-
Notifications
You must be signed in to change notification settings - Fork 84
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
Adds Version Check #102
Adds Version Check #102
Conversation
Hi @somtochiama. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @justinsb |
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.
A few nits but otherwise LGTM
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/pkg/manifest" | ||
) | ||
|
||
// NewVersionCheck provides an implementation of declarative.Reconciled that |
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.
Oh cool - using a signature inspired by Reconcilers is an interesting pattern to explore!
|
||
versionActual, err := semver.Make(versionNeededStr) | ||
if err != nil { | ||
log.WithValues("version", versionNeededStr).Info("Unable to convert string to version, skipping this object") |
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.
Nit: I think you should report this as a log.Error(err)
, even if we don't return an error.
} | ||
} | ||
|
||
// TODO(somtochi): Do we want to return an error when the version is invalid or just skip and use the operator? |
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.
I actually think it would be reasonable to return an error, if the annotation is specified but we can't parse it. It could be a version schema our operator is too old to understand. (More likely, it's just a typo).
But ... the user did specify the annotation in their manifest...
I think returning an error is reasonable, it will help users create valid manifests. A message in the logs is going to get overlooked and users will be surprised when it doesn't work.
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.
There are also two versions, what happens if we cannot parse the operator's version?
// TODO(somtochi): Do we want to return an error when the version is invalid or just skip and use the operator? | ||
operatorVersion, err := semver.Make(p.version) | ||
if err != nil { | ||
log.WithValues("version", p.version).Info("Unable to convert string to version, skipping check") |
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.
You could move this to NewVersionCheck
; I think it's very natural to return an error there if passed a bad version :-)
Related question is: should we refuse to apply manifests that specify invalid minimum versions (i.e. ignore vs error). I would vote "error" I think, based on my chain of thoughts in this review!
@@ -122,6 +122,22 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN | |||
} | |||
log.WithValues("objects", fmt.Sprintf("%d", len(objects.Items))).Info("built deployment objects") | |||
|
|||
if r.options.status != nil { | |||
bool, err := r.options.status.VersionCheck(ctx, instance, objects) |
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.
Nit: Don't name it bool
- it's confusing. e.g. maybe something like validVersion, err := r.options.status.VersionCheck(...)
if err != nil { | ||
if !bool { | ||
// r.client isn't exported so can't be updated in version check function | ||
r.client.Status().Update(ctx, 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.
Nit: I think this can return an error; we need to bubble it up if so.
for _, obj := range objs.Items { | ||
annotations := obj.UnstructuredObject().GetAnnotations() | ||
if versionNeededStr, ok := annotations["addons.k8s.io/min-operator-version"]; ok { | ||
log.WithValues("version", versionNeededStr).Info("Got version requirement addons.k8s.io/operator-version=%v") |
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.
Nit: this should say min-operator-version
to match the annotation value
if err != nil { | ||
if !isValidVersion { | ||
// r.client isn't exported so can't be updated in version check function | ||
err := r.client.Status().Update(ctx, 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.
So this actually "shadows" the err value we care about. So on line 142 err will be nil.
Sometimes people use a different name e.g. updateErr :=...
But I think a better pattern - when you can use it - is to so if err := r.client.Status()...; err != nil
as then the scope of the shadowing err should just be the if
statement (I think!)
One problem with variable shadowing (and a nit), but otherwise lgtm |
49bb60f
to
9e17933
Compare
Thanks @somtochiama ... this looks great /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: justinsb, SomtochiAma The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
No description provided.