-
Notifications
You must be signed in to change notification settings - Fork 40.9k
fix: fix slice init length #127785
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
base: master
Are you sure you want to change the base?
fix: fix slice init length #127785
Conversation
|
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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. |
Welcome @huochexizhan! |
Hi @huochexizhan. Thanks for your PR. I'm waiting for a kubernetes 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-sigs/prow repository. |
Hi @huochexizhan , |
@@ -274,7 +274,7 @@ func validateAllowedTopologies(topologies []api.TopologySelectorTerm, fldPath *f | |||
return allErrs | |||
} | |||
|
|||
rawTopologies := make([]map[string]sets.Set[string], len(topologies)) | |||
rawTopologies := make([]map[string]sets.Set[string], 0, len(topologies)) |
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.
If we use the modified method, the list will be considered empty but the capacity will be len(topologies). Is this what we expect? The original initialization method should create len(topologies) objects, right?
rawTopologies := make([]map[string]sets.Set[string], 0, len(topologies))
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, see below it is appending values to the list, that it seems are the supposed to be compared against, right now the len(topologies) entries are empty https://go.dev/play/p/eXaQdxsH5GP
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.
thanks for answering this! :)
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.
upps #127785 (comment) , it seems the logic depended on the empty values
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.
Thanks.
/ok-to-test |
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.
Thanks!
/lgtm
/approve
LGTM label has been added. Git tree hash: f28eec9155b7faebb954e2c9aea94a4ad271d129
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: huochexizhan, thockin 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 |
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
2 similar comments
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
interesting side effect @liggitt @thockin , since the slice was created with empty values, and the code considered invaliud duplicates, the empty value was considered invalid ... and now we need to keep this behavior, so we should keep injecting one empty case 🤕
|
Thank! If there's anything I need to do, please feel free to let me know |
I think the empty value SHOULD be allowed - it has a well defined meaning:
|
I think the correct thing to do here is fix the code and also: diff --git a/pkg/apis/storage/validation/validation_test.go b/pkg/apis/storage/validation/validation_test.go
index 9f8c5bd0f72..16bd94ff364 100644
--- a/pkg/apis/storage/validation/validation_test.go
+++ b/pkg/apis/storage/validation/validation_test.go
@@ -837,7 +837,7 @@ func TestValidateAllowedTopologies(t *testing.T) {
},
"empty MatchLabelExpressions": {
class: makeClass(&waitingMode, topologyEmptyMatchLabelExpressions),
- shouldSucceed: false,
+ shouldSucceed: true,
},
"duplicate MatchLabelExpression keys": {
class: makeClass(&waitingMode, topologyDupKeys), |
Signed-off-by: huochexizhan <[email protected]>
Sorry to deal with it so late. Has been modified, please review again. |
Looking at this again, the effect of this is that we are loosening validation. It used to behave like:
Note the "duplicate value" error. If we change this, then my YAML above will be accepted and stored. If a user subsequently rolls back to the previosu k8s release, this will fail to validate any update operations. Worse, docs are somewhat conflicting: staging/src/k8s.io/api/storage/v1/types.go:
vs: staging/src/k8s.io/api/core/v1/types.go:
@msau42 @jsafrane - can you spend a moment thinking about this? I see two paths:
|
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
Thanks. Anything need I to do? |
Thanks! |
@msau42 @jsafrane - can you spend a moment thinking about this? Thanks. |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
What type of PR is this?
/kind bug
What this PR does / why we need it:
The intention here should be to initialize a slice with a capacity of len(topologies) rather than initializing the length of this slice.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: