-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic instance update func #117
Generic instance update func #117
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instance
is a pretty generic name for the package. I would call this reconciler
instead. That also helps showing the intention that PatchInstance should be use in a Reconciler.
feb92dd
to
4c89371
Compare
ok, @abays just told me that there is some import cycle then because of the util.log... we could update util/log.go to pass in the logger from the caller ... but that requires changes all over the place where we use the logger funcs. use basic logging in patching could be an alternative. seems we need to put some more thinking in our logging. I wanted to get back to that and make that better to have e.g. some log level ... but other prios ... if we agree that this patching func is better located in the helper as it is tightly coupled, we might want to go with basic logging and update that when we got back to logging in general, instead of relocate the patchInstance later ... |
What if we introduce a new I also see a generic pattern here.
|
Its a good idea to add a new variant for LogForObject by doing a log package and have all the future logging stuff there. Re the other split, probably best to discuss that again after the break. GetFinalizer() is not meant to get the finalizers of |
Then it even better to rename it as well when we separate it out. The implementation is actually simple based on GetFinalizerName(obj client.Object, client client.Client) (string, error) {
gvk, err := apiutil.GVKForObject(obj, client.Scheme())
return gvk.Kind()
} Looking more at the implementation I think this can be simplified further to: func GetFinalizerName(obj client.Object) string {
return obj.GetObjectKind().GroupVersionKind().Kind
} But I agree we need to table this for next year as this is my last day before my PTO. (I will be back around 5th of Jan) |
Let's do that as a separate PR first. Who wants to do it? :) |
I will make a quick stab of it. |
#125 I try to take an approach which is more aligned with the existing logr and context interfaces. But I provided some compatibility methods so we can discuss our options. I will push a nova change to show the real usage of it. |
And here is the nova example openstack-k8s-operators/nova-operator#206 |
Testing of #125 (#125 (comment)) shows that we don't need any fancy logging interface massaging as the logger from the ctx already has all the information we want in the log. |
modules/common/instance/instance.go
Outdated
if changes["metadata"] { | ||
err = h.GetClient().Patch(ctx, instance, patch) | ||
if k8s_errors.IsConflict(err) { | ||
util.LogForObject(h, "Metadata update conflict", instance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets change this to
l := log.FromContext(ctx)
l.Info(...)
The instance related information is already stored in and emitted by that logger
modules/common/instance/instance.go
Outdated
util.LogForObject(h, "Metadata update conflict", instance) | ||
return err | ||
} else if err != nil && !k8s_errors.IsNotFound(err) { | ||
util.LogErrorForObject(h, err, "Metadate update failed", instance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l.Error()
modules/common/instance/instance.go
Outdated
if changes["status"] { | ||
err = h.GetClient().Status().Patch(ctx, instance, patch) | ||
if k8s_errors.IsConflict(err) { | ||
util.LogForObject(h, "Status update conflict", instance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l.Info()
modules/common/instance/instance.go
Outdated
return err | ||
|
||
} else if err != nil && !k8s_errors.IsNotFound(err) { | ||
util.LogErrorForObject(h, err, "Status update failed", instance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l.Error()
@gibizer With the new logging approach, which would remove the import cycle loop and thus allow this code to exist in the |
Lets move it to the |
4c89371
to
d193dd3
Compare
d193dd3
to
26befd7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks @abays!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/lgtm |
Intended to be used with our deferred-instance-patch-at-end-of-reconcile pattern