diff --git a/vendor.conf b/vendor.conf index e68c84d7..6f22a350 100644 --- a/vendor.conf +++ b/vendor.conf @@ -2,4 +2,4 @@ github.com/rancher/types github.com/pkg/errors v0.8.0 -github.com/rancher/norman 146f45dafa623a34864cbeeb3a39d5903daa2995 transitive=true +github.com/rancher/norman 1d24e0fc0b0a92dfc48012e82219e0d584cb8b0b transitive=true diff --git a/vendor/github.com/rancher/norman/generator/controller_template.go b/vendor/github.com/rancher/norman/generator/controller_template.go index b0fd44ec..b9da6b27 100644 --- a/vendor/github.com/rancher/norman/generator/controller_template.go +++ b/vendor/github.com/rancher/norman/generator/controller_template.go @@ -349,12 +349,12 @@ func (n *{{.schema.ID}}Client2) Cache() {{.schema.CodeName}}ClientCache { func (n *{{.schema.ID}}Client2) OnCreate(ctx context.Context, name string, sync {{.schema.CodeName}}ChangeHandlerFunc) { n.loadController() - n.iface.AddLifecycle(ctx, name, &{{.schema.ID}}LifecycleDelegate{create: sync}) + n.iface.AddLifecycle(ctx, name+"-create", &{{.schema.ID}}LifecycleDelegate{create: sync}) } func (n *{{.schema.ID}}Client2) OnChange(ctx context.Context, name string, sync {{.schema.CodeName}}ChangeHandlerFunc) { n.loadController() - n.iface.AddLifecycle(ctx, name, &{{.schema.ID}}LifecycleDelegate{update: sync}) + n.iface.AddLifecycle(ctx, name+"-change", &{{.schema.ID}}LifecycleDelegate{update: sync}) } func (n *{{.schema.ID}}Client2) OnRemove(ctx context.Context, name string, sync {{.schema.CodeName}}ChangeHandlerFunc) { @@ -426,10 +426,6 @@ func (n *{{.schema.ID}}LifecycleDelegate) Remove(obj *{{.prefix}}{{.schema.CodeN return n.remove(obj) } -func (n *{{.schema.ID}}LifecycleDelegate) HasUpdated() bool { - return n.remove != nil -} - func (n *{{.schema.ID}}LifecycleDelegate) Updated(obj *{{.prefix}}{{.schema.CodeName}}) (runtime.Object, error) { if n.update == nil { return obj, nil diff --git a/vendor/github.com/rancher/norman/generator/lifecycle_template.go b/vendor/github.com/rancher/norman/generator/lifecycle_template.go index 5594e446..d0a6cf54 100644 --- a/vendor/github.com/rancher/norman/generator/lifecycle_template.go +++ b/vendor/github.com/rancher/norman/generator/lifecycle_template.go @@ -19,6 +19,16 @@ type {{.schema.ID}}LifecycleAdapter struct { lifecycle {{.schema.CodeName}}Lifecycle } +func (w *{{.schema.ID}}LifecycleAdapter) HasCreate() bool { + o, ok := w.lifecycle.(lifecycle.ObjectLifecycleCondition) + return !ok || o.HasCreate() +} + +func (w *{{.schema.ID}}LifecycleAdapter) HasFinalize() bool { + o, ok := w.lifecycle.(lifecycle.ObjectLifecycleCondition) + return !ok || o.HasFinalize() +} + func (w *{{.schema.ID}}LifecycleAdapter) Create(obj runtime.Object) (runtime.Object, error) { o, err := w.lifecycle.Create(obj.(*{{.prefix}}{{.schema.CodeName}})) if o == nil { diff --git a/vendor/github.com/rancher/norman/lifecycle/object.go b/vendor/github.com/rancher/norman/lifecycle/object.go index b0558cc9..03c99ba9 100644 --- a/vendor/github.com/rancher/norman/lifecycle/object.go +++ b/vendor/github.com/rancher/norman/lifecycle/object.go @@ -26,7 +26,6 @@ type ObjectLifecycle interface { type ObjectLifecycleCondition interface { HasCreate() bool HasFinalize() bool - HasUpdated() bool } type objectLifecycleAdapter struct { @@ -86,6 +85,10 @@ func (o *objectLifecycleAdapter) update(name string, orig, obj runtime.Object) ( } func (o *objectLifecycleAdapter) finalize(obj runtime.Object) (runtime.Object, bool, error) { + if !o.hasFinalize() { + return obj, true, nil + } + metadata, err := meta.Accessor(obj) if err != nil { return obj, false, err @@ -173,9 +176,10 @@ func (o *objectLifecycleAdapter) record(obj runtime.Object, f func(runtime.Objec return obj, err } - obj = obj.DeepCopyObject() + origObj := obj + obj = origObj.DeepCopyObject() if newObj, err := f(obj); err != nil { - newObj, _ = o.update(metadata.GetName(), obj, newObj) + newObj, _ = o.update(metadata.GetName(), origObj, newObj) return newObj, err } else if newObj != nil { newMetadata, err := meta.Accessor(newObj) @@ -184,7 +188,7 @@ func (o *objectLifecycleAdapter) record(obj runtime.Object, f func(runtime.Objec return newObj, nil } if newMetadata.GetResourceVersion() == metadata.GetResourceVersion() { - return o.update(metadata.GetName(), obj, newObj) + return o.update(metadata.GetName(), origObj, newObj) } return newObj, nil } @@ -213,6 +217,11 @@ func (o *objectLifecycleAdapter) create(obj runtime.Object) (runtime.Object, boo } obj, err = o.record(obj, o.lifecycle.Create) + if err != nil { + return obj, false, err + } + + obj, err = o.setInitialized(obj) return obj, false, err }