diff --git a/pkg/codegen/main.go b/pkg/codegen/main.go index 9c6b8a3edf..883f50d76a 100644 --- a/pkg/codegen/main.go +++ b/pkg/codegen/main.go @@ -94,5 +94,6 @@ func main() { GenerateTypes: true, }, }, + GenMocks: false, }) } diff --git a/pkg/generated/controllers/k3s.cattle.io/factory.go b/pkg/generated/controllers/k3s.cattle.io/factory.go index 7b96258fb0..c5e423ad62 100644 --- a/pkg/generated/controllers/k3s.cattle.io/factory.go +++ b/pkg/generated/controllers/k3s.cattle.io/factory.go @@ -23,12 +23,18 @@ import ( "time" clientset "github.com/rancher/k3s/pkg/generated/clientset/versioned" + scheme "github.com/rancher/k3s/pkg/generated/clientset/versioned/scheme" informers "github.com/rancher/k3s/pkg/generated/informers/externalversions" "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/pkg/schemes" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/rest" ) +func init() { + scheme.AddToScheme(schemes.All) +} + type Factory struct { synced bool informerFactory informers.SharedInformerFactory diff --git a/trash.lock b/trash.lock index 5316383d5d..56d35e3c87 100755 --- a/trash.lock +++ b/trash.lock @@ -232,7 +232,7 @@ import: - package: github.com/rancher/remotedialer version: 20ec38853712bb6d348f0db9ac47d34c954c6b00 - package: github.com/rancher/wrangler - version: 4202dbfa88013c19238bb004d82e013f0593493d + version: d53925110e19e055d1c21df3b49021833e883f33 - package: github.com/rancher/wrangler-api version: efe26ac6a9d720e1bfa5a8cc5f8dce5ad598ce26 - package: github.com/robfig/cron @@ -275,6 +275,8 @@ import: version: 1d523034197ff1f222f6429836dd36a2457a1874 - package: go.etcd.io/bbolt version: v1.3.1-etcd.8 +- package: go.etcd.io/etcd + version: v3.3.11 - package: golang.org/x/crypto version: a49355c7e3f8fe157a85be2f77e6e269a0f89602 - package: golang.org/x/net diff --git a/vendor.conf b/vendor.conf index da15795ecf..847b56436e 100644 --- a/vendor.conf +++ b/vendor.conf @@ -12,7 +12,7 @@ package=github.com/opencontainers/runc/contrib/cmd/recvtty k8s.io/kubernetes v1.14.3-k3s.2 https://github.com/rancher/k3s.git transitive=true,staging=true github.com/rancher/dynamiclistener 03208cf106d553d58d3a73267aa473a45af63120 https://github.com/erikwilson/rancher-dynamiclistener.git -github.com/rancher/wrangler 4202dbfa88013c19238bb004d82e013f0593493d +github.com/rancher/wrangler d53925110e19e055d1c21df3b49021833e883f33 github.com/rancher/wrangler-api efe26ac6a9d720e1bfa5a8cc5f8dce5ad598ce26 github.com/rancher/dynamiclistener 077eb13a904f2c62496f31b158135d9743526f82 github.com/rancher/remotedialer 20ec38853712bb6d348f0db9ac47d34c954c6b00 diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go index c211bc65b7..f56a300584 100644 --- a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go +++ b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go @@ -6,6 +6,8 @@ import ( "fmt" "sync" + gvk2 "github.com/rancher/wrangler/pkg/gvk" + "github.com/pkg/errors" "github.com/rancher/wrangler/pkg/apply/injectors" "github.com/rancher/wrangler/pkg/objectset" @@ -165,10 +167,14 @@ func (o *desiredSet) getLabelsAndAnnotations() (map[string]string, map[string]st } if o.owner != nil { - annotations[LabelGVK] = o.owner.GetObjectKind().GroupVersionKind().String() + gvk, err := gvk2.Get(o.owner) + if err != nil { + return nil, nil, err + } + annotations[LabelGVK] = gvk.String() metadata, err := meta.Accessor(o.owner) if err != nil { - return nil, nil, fmt.Errorf("failed to get metadata for %s", o.owner.GetObjectKind().GroupVersionKind()) + return nil, nil, fmt.Errorf("failed to get metadata for %s", gvk) } annotations[LabelName] = metadata.GetName() annotations[LabelNamespace] = metadata.GetNamespace() diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go index 0dca721fcc..13149d13b9 100644 --- a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go +++ b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go @@ -208,15 +208,19 @@ func getOriginal(obj v1.Object) ([]byte, error) { return []byte("{}"), nil } - mapObj := &unstructured.Unstructured{} - err := json.Unmarshal(original, mapObj) + mapObj := map[string]interface{}{} + err := json.Unmarshal(original, &mapObj) if err != nil { return nil, err } - removeCreationTimestamp(mapObj.Object) + removeCreationTimestamp(mapObj) - objCopy, err := prepareObjectForCreate(mapObj) + u := &unstructured.Unstructured{ + Object: mapObj, + } + + objCopy, err := prepareObjectForCreate(u) if err != nil { return nil, err } diff --git a/vendor/github.com/rancher/wrangler/pkg/controller-gen/args/args.go b/vendor/github.com/rancher/wrangler/pkg/controller-gen/args/args.go index 1fe796a871..fd71abe360 100644 --- a/vendor/github.com/rancher/wrangler/pkg/controller-gen/args/args.go +++ b/vendor/github.com/rancher/wrangler/pkg/controller-gen/args/args.go @@ -16,6 +16,7 @@ type Options struct { OutputPackage string Groups map[string]Group Boilerplate string + GenMocks bool } type Group struct { diff --git a/vendor/github.com/rancher/wrangler/pkg/controller-gen/generators/factory_go.go b/vendor/github.com/rancher/wrangler/pkg/controller-gen/generators/factory_go.go index 22a2c664c8..aec5180bf3 100644 --- a/vendor/github.com/rancher/wrangler/pkg/controller-gen/generators/factory_go.go +++ b/vendor/github.com/rancher/wrangler/pkg/controller-gen/generators/factory_go.go @@ -3,6 +3,7 @@ package generators import ( "fmt" "io" + "path/filepath" args2 "github.com/rancher/wrangler/pkg/controller-gen/args" "k8s.io/gengo/args" @@ -38,7 +39,9 @@ func (f *factory) Imports(*generator.Context) []string { "k8s.io/apimachinery/pkg/runtime/schema", "k8s.io/client-go/rest", GenericPackage, + AllSchemes, fmt.Sprintf("clientset \"%s\"", group.ClientSetPackage), + fmt.Sprintf("scheme \"%s\"", filepath.Join(group.ClientSetPackage, "scheme")), fmt.Sprintf("informers \"%s\"", group.InformersPackage), } } @@ -61,6 +64,10 @@ func (f *factory) Init(c *generator.Context, w io.Writer) error { } var factoryBody = ` +func init() { + scheme.AddToScheme(schemes.All) +} + type Factory struct { synced bool informerFactory informers.SharedInformerFactory diff --git a/vendor/github.com/rancher/wrangler/pkg/controller-gen/generators/util.go b/vendor/github.com/rancher/wrangler/pkg/controller-gen/generators/util.go index 939414e505..a3ca741cbe 100644 --- a/vendor/github.com/rancher/wrangler/pkg/controller-gen/generators/util.go +++ b/vendor/github.com/rancher/wrangler/pkg/controller-gen/generators/util.go @@ -8,6 +8,7 @@ import ( const ( GenericPackage = "github.com/rancher/wrangler/pkg/generic" + AllSchemes = "github.com/rancher/wrangler/pkg/schemes" ) func groupPath(group string) string { diff --git a/vendor/github.com/rancher/wrangler/pkg/controller-gen/main.go b/vendor/github.com/rancher/wrangler/pkg/controller-gen/main.go index 3b96553a95..ed82da826b 100644 --- a/vendor/github.com/rancher/wrangler/pkg/controller-gen/main.go +++ b/vendor/github.com/rancher/wrangler/pkg/controller-gen/main.go @@ -104,9 +104,11 @@ func Run(opts cgargs.Options) { logrus.Fatalf("go modules copy failed: %v", err) } - if err := clientGen.GenerateMocks(); err != nil { - logrus.Errorf("mocks failed: %v", err) - return + if opts.GenMocks { + if err := clientGen.GenerateMocks(); err != nil { + logrus.Errorf("mocks failed: %v", err) + return + } } } diff --git a/vendor/github.com/rancher/wrangler/pkg/generic/controller.go b/vendor/github.com/rancher/wrangler/pkg/generic/controller.go index 565c31370b..56bf13dfdf 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generic/controller.go +++ b/vendor/github.com/rancher/wrangler/pkg/generic/controller.go @@ -56,7 +56,6 @@ func NewController(name string, informer cache.SharedIndexInformer, workqueue wo workqueue: workqueue, } - logrus.Info("Setting up event handlers") informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: controller.handleObject, UpdateFunc: func(old, new interface{}) { diff --git a/vendor/github.com/rancher/wrangler/pkg/gvk/get.go b/vendor/github.com/rancher/wrangler/pkg/gvk/get.go new file mode 100644 index 0000000000..75146e7d53 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/pkg/gvk/get.go @@ -0,0 +1,27 @@ +package gvk + +import ( + "fmt" + + "github.com/rancher/wrangler/pkg/schemes" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +func Get(obj runtime.Object) (schema.GroupVersionKind, error) { + gvk := obj.GetObjectKind().GroupVersionKind() + if gvk.Kind != "" { + return gvk, nil + } + + gvks, _, err := schemes.All.ObjectKinds(obj) + if err != nil { + return schema.GroupVersionKind{}, err + } + + if len(gvks) == 0 { + return schema.GroupVersionKind{}, fmt.Errorf("failed to find gvk for %v", obj.GetObjectKind()) + } + + return gvks[0], nil +} diff --git a/vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go b/vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go index 7e3c9b0031..c4896938aa 100644 --- a/vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go +++ b/vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go @@ -5,6 +5,8 @@ import ( "reflect" "sort" + "github.com/rancher/wrangler/pkg/gvk" + "github.com/rancher/wrangler/pkg/merr" "k8s.io/apimachinery/pkg/api/meta" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -33,16 +35,21 @@ func (o ObjectKey) String() string { type ObjectByGVK map[schema.GroupVersionKind]map[ObjectKey]runtime.Object -func (o ObjectByGVK) Add(obj runtime.Object) error { +func (o ObjectByGVK) Add(obj runtime.Object) (schema.GroupVersionKind, error) { metadata, err := meta.Accessor(obj) if err != nil { - return err + return schema.GroupVersionKind{}, err } - objs := o[obj.GetObjectKind().GroupVersionKind()] + gvk, err := gvk.Get(obj) + if err != nil { + return schema.GroupVersionKind{}, err + } + + objs := o[gvk] if objs == nil { objs = map[ObjectKey]runtime.Object{} - o[obj.GetObjectKind().GroupVersionKind()] = objs + o[gvk] = objs } objs[ObjectKey{ @@ -50,42 +57,28 @@ func (o ObjectByGVK) Add(obj runtime.Object) error { Name: metadata.GetName(), }] = obj - return nil + return gvk, nil } type ObjectSet struct { - errs []error - objects ObjectByGVK - nsed map[schema.GroupVersionKind]bool - inputs []runtime.Object - order []runtime.Object + errs []error + objects ObjectByGVK + order []runtime.Object + gvkOrder []schema.GroupVersionKind + gvkSeen map[schema.GroupVersionKind]bool } func NewObjectSet() *ObjectSet { return &ObjectSet{ - nsed: map[schema.GroupVersionKind]bool{}, objects: ObjectByGVK{}, + gvkSeen: map[schema.GroupVersionKind]bool{}, } } -func (o *ObjectSet) Inputs() []runtime.Object { - return o.inputs -} - func (o *ObjectSet) ObjectsByGVK() ObjectByGVK { return o.objects } -func (o *ObjectSet) AddInput(objs ...runtime.Object) *ObjectSet { - for _, obj := range objs { - if obj == nil || reflect.ValueOf(obj).IsNil() { - continue - } - o.inputs = append(o.inputs, obj) - } - return o -} - func (o *ObjectSet) Add(objs ...runtime.Object) *ObjectSet { for _, obj := range objs { o.add(obj) @@ -98,34 +91,17 @@ func (o *ObjectSet) add(obj runtime.Object) { return } - gvk := obj.GetObjectKind().GroupVersionKind() - - metadata, err := meta.Accessor(obj) + gvk, err := o.objects.Add(obj) if err != nil { - o.err(fmt.Errorf("failed to get metadata for %s", gvk)) - return - } - - name := metadata.GetName() - if name == "" { - o.err(fmt.Errorf("%s is missing name", gvk)) - return - } - - namespace := metadata.GetNamespace() - nsed, ok := o.nsed[gvk] - if ok && nsed != (namespace != "") { - o.err(fmt.Errorf("got %s objects that are both namespaced and not namespaced", gvk)) - return - } - o.nsed[gvk] = namespace != "" - - if err := o.objects.Add(obj); err != nil { - o.err(fmt.Errorf("failed to get metadata for %s", gvk)) + o.err(fmt.Errorf("failed to add %v", obj)) return } o.order = append(o.order, obj) + if !o.gvkSeen[gvk] { + o.gvkSeen[gvk] = true + o.gvkOrder = append(o.gvkOrder, gvk) + } } func (o *ObjectSet) err(err error) error { @@ -146,25 +122,12 @@ func (o *ObjectSet) Len() int { } func (o *ObjectSet) GVKOrder(known ...schema.GroupVersionKind) []schema.GroupVersionKind { - seen := map[schema.GroupVersionKind]bool{} - var gvkOrder []schema.GroupVersionKind - - for _, obj := range o.order { - if seen[obj.GetObjectKind().GroupVersionKind()] { - continue - } - seen[obj.GetObjectKind().GroupVersionKind()] = true - gvkOrder = append(gvkOrder, obj.GetObjectKind().GroupVersionKind()) - } - var rest []schema.GroupVersionKind for _, gvk := range known { - if seen[gvk] { + if o.gvkSeen[gvk] { continue } - - seen[gvk] = true rest = append(rest, gvk) } @@ -172,5 +135,5 @@ func (o *ObjectSet) GVKOrder(known ...schema.GroupVersionKind) []schema.GroupVer return rest[i].String() < rest[j].String() }) - return append(gvkOrder, rest...) + return append(o.gvkOrder, rest...) } diff --git a/vendor/github.com/rancher/wrangler/pkg/schemes/all.go b/vendor/github.com/rancher/wrangler/pkg/schemes/all.go new file mode 100644 index 0000000000..8e64b5ca9f --- /dev/null +++ b/vendor/github.com/rancher/wrangler/pkg/schemes/all.go @@ -0,0 +1,7 @@ +package schemes + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +var All = runtime.NewScheme()