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

🌱 Improve Cluster variable defaulting/validation errors #9452

Merged

Conversation

sbueringer
Copy link
Member

Signed-off-by: Stefan Büringer [email protected]

What this PR does / why we need it:

Before

The Cluster "my-cluster-2" is invalid: spec.topology.variables: Invalid value: []v1beta1.ClusterVariable{v1beta1.ClusterVariable{Name:"imageRepository", DefinitionFrom:"", Value:v1.JSON{Raw:[]uint8{0x22, 0x6b, 0x38, 0x73, 0x2e, 0x67, 0x63, 0x72, 0x2e, 0x69, 0x6f, 0x22}}}, v1beta1.ClusterVariable{Name:"imageRepository", DefinitionFrom:"", Value:v1.JSON{Raw:[]uint8{0x22, 0x6b, 0x38, 0x73, 0x2e, 0x67, 0x63, 0x72, 0x2e, 0x69, 0x6f, 0x22}}}, v1beta1.ClusterVariable{Name:"lbImage", DefinitionFrom:"", Value:v1.JSON{Raw:[]uint8{0x7b, 0x22, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x22, 0x6b, 0x69, 0x6e, 0x64, 0x65, 0x73, 0x74, 0x22, 0x2c, 0x22, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x54, 0x61, 0x67, 0x22, 0x3a, 0x22, 0x76, 0x32, 0x30, 0x32, 0x31, 0x30, 0x37, 0x31, 0x35, 0x2d, 0x61, 0x36, 0x64, 0x61, 0x33, 0x34, 0x36, 0x33, 0x22, 0x7d}}}, v1beta1.ClusterVariable{Name:"controlPlaneTaint", DefinitionFrom:"", Value:v1.JSON{Raw:[]uint8{0x66, 0x61, 0x6c, 0x73, 0x65}}}}: cluster variables not valid: variable "imageRepository" from "" is defined more than once

After

The Cluster "my-cluster-2" is invalid: spec.topology.variables: Invalid value: "[Name: imageRepository DefinitionFrom: ,Name: imageRepository DefinitionFrom: ,Name: lbImage DefinitionFrom: ,Name: controlPlaneTaint DefinitionFrom: ]": cluster variables not valid: variable "imageRepository" from "" is defined more than once

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 #

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label labels Sep 18, 2023
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 18, 2023
@@ -49,8 +50,11 @@ func defaultClusterVariables(values []clusterv1.ClusterVariable, definitions []c
// - variables with the same name do not have a mix of empty and non-empty DefinitionFrom.
valuesIndex, err := newValuesIndex(values)
if err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

TIL: Technically we produce this error during defaulting and validation, so we have two of them. But this gets deduplicated during error aggregation in apierrors.NewInvalid

@chrischdi
Copy link
Member

The Cluster "my-cluster-2" is invalid: spec.topology.variables: Invalid value: "[Name: imageRepository DefinitionFrom: ,Name: imageRepository DefinitionFrom: ,Name: lbImage DefinitionFrom: ,Name: controlPlaneTaint DefinitionFrom: ]": cluster variables not valid: variable "imageRepository" from "" is defined more than once

Is DefinitionFrom always empty?

If yes I think we should not add all this and the error may be sufficient?

otherwise lgtm

@sbueringer
Copy link
Member Author

sbueringer commented Sep 19, 2023

The Cluster "my-cluster-2" is invalid: spec.topology.variables: Invalid value: "[Name: imageRepository DefinitionFrom: ,Name: imageRepository DefinitionFrom: ,Name: lbImage DefinitionFrom: ,Name: controlPlaneTaint DefinitionFrom: ]": cluster variables not valid: variable "imageRepository" from "" is defined more than once

Is DefinitionFrom always empty?

If yes I think we should not add all this and the error may be sufficient?

otherwise lgtm

No it is not always empty. It can also vary between variables (we also have it in other errors and it can be crucial to understand what is wrong). But I agree it is confusing in the cases where it is empty. Maybe we should do a follow-up to audit all our variable errors to try to simplify in cases where it is empty and we can.

I could also implement basically an "omitempty" in this error.

@sbueringer
Copy link
Member Author

@killianmuldoon WDYT?

@sbueringer
Copy link
Member Author

@killianmuldoon ^^

Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

/area clusterclass

@k8s-ci-robot k8s-ci-robot added area/clusterclass Issues or PRs related to clusterclass and removed do-not-merge/needs-area PR is missing an area label labels Sep 21, 2023
@killianmuldoon
Copy link
Contributor

IMO this is a really big improvement as-is, and I don't think we need to complicate it.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 21, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 511bb48957a192cc440e5e2c3f7e63c8ed925d3e

@sbueringer
Copy link
Member Author

Alrighty. Let's go with that one as is then

/approve

@sbueringer
Copy link
Member Author

I would cherry-pick into release-1.5 as it's a significant improvement to our error messages and it falls under the "experimental feature" clause of our backport policy

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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

@sbueringer
Copy link
Member Author

/cherry-pick release-1.5

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 21, 2023
@k8s-infra-cherrypick-robot

@sbueringer: once the present PR merges, I will cherry-pick it on top of release-1.5 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.5

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 merged commit 753fa61 into kubernetes-sigs:main Sep 21, 2023
16 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.6 milestone Sep 21, 2023
@sbueringer sbueringer deleted the pr-improve-webhook-err branch September 21, 2023 11:04
@k8s-infra-cherrypick-robot

@sbueringer: new pull request created: #9479

In response to this:

/cherry-pick release-1.5

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.

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. area/clusterclass Issues or PRs related to clusterclass 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/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants