-
Notifications
You must be signed in to change notification settings - Fork 1.4k
🌱 Enable optionalfields linter and fix remaining findings #12299
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
🌱 Enable optionalfields linter and fix remaining findings #12299
Conversation
1a28f2c
to
1b12419
Compare
1b12419
to
984df7f
Compare
984df7f
to
3b1fa37
Compare
3b1fa37
to
df2839e
Compare
a067572
to
9311747
Compare
9311747
to
c3f070b
Compare
3eefea7
to
a679fc0
Compare
a679fc0
to
bbb3f2d
Compare
c486c9b
to
031531b
Compare
u := &unstructured.Unstructured{} | ||
Expect(scheme.Convert(cluster, u, nil)).To(Succeed()) | ||
modifiedClusterYAML, err := yaml.FromUnstructured([]unstructured.Unstructured{*u}) | ||
// Note: We have to set GVK here explicitly otherwise apiVersion + kind won't be set in the YAML. |
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.
UnstructuredConverter doesn't handle omitzero yet (it will with apimachinery v0.34). So switched to marshaling Cluster directly
/test pull-cluster-api-e2e-conformance-ci-latest-main |
|
text: "optionalfields: field (Bootstrap) is optional and (should be a pointer|should have the omitempty tag|has a valid zero value)" | ||
linters: | ||
- kubeapilinter | ||
# KAL incorrectly reports that the Taints field doesn't have to be a pointer (it has to be to preserve []). |
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.
We raised a bug on KAL for this? Can it be linked?
Should be able to pick this up from a minimum items marker set to 0
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.
Ah. I thought the finding was intended so I didn't think about opening a bug. So MinItems=0 implies that empty array should be preserved? (I'll then open a bug for it)
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.
Yeah, so in discussion with upstream API reviewers, I personally think that this is fine for CRDs, but we know it's not ok for built-in/server types.
So we probably want to have an option that points this out/allows it for CRDs, but then something additional that says you cannot have minItems:=0
for built-in types.
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'll open an issue in a bit
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.
To dedup from the other thread. We have the // +kubebuilder:validation:MinItems=0
marker on the field, but we still get the following finding without the exclude:
api/bootstrap/kubeadm/v1beta2/kubeadm_types.go:304:2: optionalfields: field Taints is optional but the underlying type does not need to be a pointer. The pointer should be removed. (kubeapilinter)
Taints *[]corev1.Taint `json:"taints,omitempty"`
^
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.
@@ -179,7 +179,6 @@ type ExtensionHandler struct { | |||
// failurePolicy defines how failures in calls to the ExtensionHandler should be handled by a client. | |||
// Defaults to Fail if not set. | |||
// +optional | |||
// +kubebuilder:validation:Enum=Ignore;Fail | |||
FailurePolicy *FailurePolicy `json:"failurePolicy,omitempty"` |
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.
Doesn't need to be a pointer because the zero value is not valid. I believe there was an exception for this in the config?
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 exclude is for DeletePolicy, not FailurePolicy. But I"m going to open a follow-up PR for this independently.
I think the linter does not detect this correctly, but that is also because of the known enum bug (kubernetes-sigs/kube-api-linter#113). If I add the Enum marker here back I'm getting:
api/runtime/v1beta2/extensionconfig_types.go:183:2: optionalfields: field FailurePolicy is optional and does not allow the zero value. The field does not need to be a pointer. (kubeapilinter)
FailurePolicy *FailurePolicy `json:"failurePolicy,omitempty"`
^
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'll open a PR to fix this next week
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.
PR to fix the pointer: #12453
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.
Great improvement!
failures looks like unrelated (ipv6 tests) /hold in case @JoelSpeed wants to make another pass |
LGTM label has been added. Git tree hash: da931f85fdceb93c5cbc6b57739823d2aaf99762
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fabriziopandini 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 |
@@ -1139,16 +1140,19 @@ func (c *ClusterStatus) GetTypedPhase() ClusterPhase { | |||
// ANCHOR: APIEndpoint | |||
|
|||
// APIEndpoint represents a reachable Kubernetes API endpoint. | |||
// +kubebuilder:validation:MinProperties=1 | |||
type APIEndpoint struct { |
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.
@JoelSpeed I think the changes in this PR should also address #6416
And yes we have use cases where folks set either host or port or both
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 think I agree, provided we are adding omitzero
at the places where this field is being used.
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.
Yes, we have that set and we'll update the migration doc to mention it
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.
/hold cancel
All good on my side
@@ -1139,16 +1140,19 @@ func (c *ClusterStatus) GetTypedPhase() ClusterPhase { | |||
// ANCHOR: APIEndpoint | |||
|
|||
// APIEndpoint represents a reachable Kubernetes API endpoint. | |||
// +kubebuilder:validation:MinProperties=1 | |||
type APIEndpoint struct { |
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 think I agree, provided we are adding omitzero
at the places where this field is being used.
/override pull-cluster-api-e2e-latestk8s-main See #12299 (comment) |
@sbueringer: Overrode contexts on behalf of sbueringer: pull-cluster-api-e2e-latestk8s-main, pull-cluster-api-e2e-main In response to this:
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-sigs/prow repository. |
@sbueringer: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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-sigs/prow repository. I understand the commands that are listed here. |
/override pull-cluster-api-test-main Known flake |
@sbueringer: Overrode contexts on behalf of sbueringer: pull-cluster-api-test-main In response to this:
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-sigs/prow repository. |
What this PR does / why we need it:
Fixes the remaining findings of the optionalfields linter.
We'll follow-up on docs.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Part of #10852
Fixes #6416