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

⚠️ MachineHealthCheck Spec.Selector field cannot be empty #3032

Merged
merged 1 commit into from
May 13, 2020

Conversation

vincepri
Copy link
Member

@vincepri vincepri commented May 8, 2020

Signed-off-by: Vince Prignano [email protected]

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #3006

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 8, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

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 requested review from detiber and justinsb May 8, 2020 14:42
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 8, 2020
@vincepri
Copy link
Member Author

vincepri commented May 8, 2020

/milestone v0.3.6
/assign @ncdc @JoelSpeed

@k8s-ci-robot k8s-ci-robot added this to the v0.3.6 milestone May 8, 2020
@vincepri
Copy link
Member Author

vincepri commented May 8, 2020

cc @sedefsavas for the e2e tests

@vincepri
Copy link
Member Author

vincepri commented May 8, 2020

Marked as a ⚠️, but this should have been like this from the very beginning

@fabriziopandini
Copy link
Member

/lgtm
/hold for other reviewers to chime in

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 8, 2020
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 8, 2020
@JoelSpeed
Copy link
Contributor

LGTM too, one suggestion might be to add a test case with an empty selector so that we can see an empty selector makes the validation fail? Should be pretty simple to add to TestMachineHealthCheckLabelSelectorAsSelectorValidation

if err != nil {
allErrs = append(
allErrs,
field.Invalid(field.NewPath("spec", "selector"), m.Spec.Selector, err.Error()),
)
}

// Validate that the selector isn't empty.
Copy link
Member

@enxebre enxebre May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since empty label selector is actually a valid semantic https://github.com/kubernetes/kubernetes/blob/665e76d97623447d13bb3b33b68591a985b49c9d/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L1041
It'd be helpful to add the reasoning behind this in the commit description (git commit -m"" -m"This is to prevent users from accidentally...").

@vincepri vincepri force-pushed the no-empty-selectors branch from 1eec34c to 721bda3 Compare May 11, 2020 15:11
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 11, 2020
@vincepri
Copy link
Member Author

/hold cancel

Added the test case, for the text of the error if you have any suggestion that'd be great — otherwise I'd leave it like this for now and improve it later

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 11, 2020
@JoelSpeed
Copy link
Contributor

I think the error is fine for now. There's still an outstanding comment from @enxebre that should be fixed before merge

@vincepri
Copy link
Member Author

@JoelSpeed that's what I meant by error :) — I'm not sure what to write in there without going into much details and while trying to be consistent with the other errors

@sedefsavas
Copy link

These changes LGTM.

@JoelSpeed
Copy link
Contributor

@JoelSpeed that's what I meant by error :) — I'm not sure what to write in there without going into much details and while trying to be consistent with the other errors

I think @enxebre just wanted to see some motivation in the commit message itself rather than in the code. The error message itself that is shown to users is separate as far as I can tell?

It's not immediately obvious looking at the commit history why this change was made I think is the point

An empty selector is usually a valid selector that matches all objects;
in Cluster API usually we disallow its use given the scope of our
project is to manage the lifecycle of Kubernetes clusters and
having an "everything" selector could lead users into errors.

For MachineHealthCheck in particular, an empty selector would match
all the machines in a given cluster; given that we don't want to have
overlapping health checks, it makes sense to disable it and make it
opt-in.

Signed-off-by: Vince Prignano <[email protected]>
@vincepri vincepri force-pushed the no-empty-selectors branch from 721bda3 to 7ad907d Compare May 13, 2020 14:31
@vincepri
Copy link
Member Author

@JoelSpeed fixed, ptal

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Thanks for updating @vincepri , description is ++

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 13, 2020
@vincepri
Copy link
Member Author

/test pull-cluster-api-make

@k8s-ci-robot k8s-ci-robot merged commit 5a53d56 into kubernetes-sigs:master May 13, 2020
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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remote nodes do not trigger reconcile for MHC when MHC selector is empty
7 participants