-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
CRD Validation Rule: skip individual cost limit check for expressions of untouched versions. #121460
Conversation
/sig api-machinery |
/lgtm |
LGTM label has been added. Git tree hash: 1aa38537f4174e0ae77379a746faf78d7839822c
|
Hello! As the PR is tagged for 1.29, is it still planned for that release? |
Yes it is planned for 1.29 and waiting for the final API approval. Thanks |
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go
Outdated
Show resolved
Hide resolved
1ce45d6
to
209241b
Compare
@liggitt The PR has been updated to skip estimated cost check based on if the version schema changed and leave the overall estimated cost check as what it is. Does that align with what's in your mind? Thank you! |
// findMutatedVersions finds each version that is in the new CRD object and differs from that of the old CRD object. | ||
// It returns a set of the names of mutated versions. | ||
// This function does not check for duplicated versions, as further validations check their uniqueness. | ||
// This function does not care about the root version. |
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.
why doesn't this function care about the root version? if there's only a single version, or the schema for all versions is identical, that's where it lives in the internal CRD type:
kubernetes/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1/conversion.go
Lines 128 to 169 in ebf46ce
// If versions[*].{subresources,schema,additionalPrinterColumns} are identical, move to spec | |
subresources := out.Versions[0].Subresources | |
subresourcesIdentical := true | |
validation := out.Versions[0].Schema | |
validationIdentical := true | |
additionalPrinterColumns := out.Versions[0].AdditionalPrinterColumns | |
additionalPrinterColumnsIdentical := true | |
// Detect if per-version fields are identical | |
for _, v := range out.Versions { | |
if subresourcesIdentical && !apiequality.Semantic.DeepEqual(v.Subresources, subresources) { | |
subresourcesIdentical = false | |
} | |
if validationIdentical && !apiequality.Semantic.DeepEqual(v.Schema, validation) { | |
validationIdentical = false | |
} | |
if additionalPrinterColumnsIdentical && !apiequality.Semantic.DeepEqual(v.AdditionalPrinterColumns, additionalPrinterColumns) { | |
additionalPrinterColumnsIdentical = false | |
} | |
} | |
// If they are, set the top-level fields and clear the per-version fields | |
if subresourcesIdentical { | |
out.Subresources = subresources | |
} | |
if validationIdentical { | |
out.Validation = validation | |
} | |
if additionalPrinterColumnsIdentical { | |
out.AdditionalPrinterColumns = additionalPrinterColumns | |
} | |
for i := range out.Versions { | |
if subresourcesIdentical { | |
out.Versions[i].Subresources = nil | |
} | |
if validationIdentical { | |
out.Versions[i].Schema = nil | |
} | |
if additionalPrinterColumnsIdentical { | |
out.Versions[i].AdditionalPrinterColumns = nil | |
} | |
} |
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.
use the GetSchemaForVersion helper method to get the schema for the each version
something like this:
versionsWithUnchangedSchemas := sets.New[string]()
for _, version := range obj.Spec.Versions {
newSchema, err := apiextensions.GetSchemaForVersion(obj, version.Name)
if err != nil {
continue
}
oldSchema, err := apiextensions.GetSchemaForVersion(oldObject, version.Name)
if err != nil {
continue
}
if reflect.DeepEqual(newSchema, oldSchema) {
versionsWithUnchangedSchemas.Insert(version.Name)
}
}
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.
Thank you for the hint! main reason for not wanting to use GetSchemaForVersion
is that it scans through versions, makes this function O(N^2) for N versions. However, because the number of versions are small, it is better to reuse existing helper function.
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation/validation.go
Outdated
Show resolved
Hide resolved
86dea64
to
4030667
Compare
4030667
to
c1fd3f5
Compare
@liggitt Thank you SO much for reviewing! Now that all comments are addressed, could you take another look? |
/lgtm |
LGTM label has been added. Git tree hash: 023e4aa0f005510b8d0172181320feeb129d721e
|
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jiahuif, liggitt 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR skips expressions and messageExpressions of versions that are not mutated during update for the check of per-expression cost limit.
Which issue(s) this PR fixes:
Fixes #120821
Special notes for your reviewer:
Total cost calculation still includes these expressions.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: