Skip to content
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

Merged
merged 3 commits into from
Aug 10, 2020

Conversation

somtochiama
Copy link
Member

No description provided.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Jul 3, 2020
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 3, 2020
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 3, 2020
@somtochiama somtochiama changed the title Update event status Adds Preflight Check Jul 3, 2020
@somtochiama
Copy link
Member Author

/assign @justinsb

@somtochiama somtochiama changed the title Adds Preflight Check Adds Version Check Jul 7, 2020
Copy link
Contributor

@justinsb justinsb left a 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

pkg/patterns/addon/pkg/status/basic.go Outdated Show resolved Hide resolved
pkg/patterns/addon/pkg/status/version.go Outdated Show resolved Hide resolved
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/pkg/manifest"
)

// NewVersionCheck provides an implementation of declarative.Reconciled that
Copy link
Contributor

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")
Copy link
Contributor

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?
Copy link
Contributor

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.

Copy link
Member Author

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")
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 17, 2020
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")
Copy link
Contributor

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)
Copy link
Contributor

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!)

@justinsb
Copy link
Contributor

One problem with variable shadowing (and a nit), but otherwise lgtm

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 30, 2020
@justinsb
Copy link
Contributor

Thanks @somtochiama ... this looks great

/approve
/lgtm
/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 10, 2020
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 10, 2020
@k8s-ci-robot k8s-ci-robot merged commit a6536ef into kubernetes-sigs:master Aug 10, 2020
@somtochiama somtochiama deleted the update-event-status branch August 20, 2020 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants