-
Notifications
You must be signed in to change notification settings - Fork 41.5k
fix: remove unnecessary ValidateResourceClaim call from resourclaim ValidateUpdate #134412
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
fix: remove unnecessary ValidateResourceClaim call from resourclaim ValidateUpdate #134412
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. |
/cc @pohly |
93883e9
to
89259eb
Compare
/retest |
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.
/lgtm
LGTM label has been added. Git tree hash: 1efb5179719d1d821f5dd6fb9a3d9f23b4b0b560
|
/assign @liggitt |
// AuthorizedForAdmin isn't needed here because the spec is immutable. | ||
errorList := validation.ValidateResourceClaim(newClaim) | ||
errorList = append(errorList, validation.ValidateResourceClaimUpdate(newClaim, oldClaim)...) | ||
errorList := validation.ValidateResourceClaimUpdate(newClaim, oldClaim) |
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 this drop the call to ValidateObjectMeta
?
If so the fact that this passed CI is deeply concerning...
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.
validation.ValidateResourceClaimUpdate
calls
- corevalidation.ValidateObjectMetaUpdate
- apimachineryvalidation.ValidateImmutableField
corevalidation.ValidateObjectMetaUpdate
calls
- apimachineryvalidation.ValidateObjectMetaUpdate
- (and validateKubeFinalizerName over finalizers)
===
You are correct that this would make it so that Update no longer calls ValidateObjectMeta
but it still calls ValidateObjectMetaUpdate
, is ValidateObjectMeta
necessary on non-CREATE calls?
ValidateObjectMeta
comment states -
// ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already
// been performed.
(link to ValidateObjectMeta
and ValidateObjectMetaUpdate
source)
https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/validation/validation.go#L399-L420
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 can add this validation back directly as part of strategy.go, it is only the dupe ResourceClaim validations that are an issue. ObjectMeta is orthogonal to Spec so to make sure validation is still 1:1 we should likely still do this check. The only thing I was uncertain of is if ValidateObjectMeta
was desired on non-CREATE operations.
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.
but it still calls ValidateObjectMetaUpdate
That's what makes it ok
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 reduce the risk here, I've added the ValidateObjectMeta
call back:
// ValidateResourceClaimUpdate tests if an update to ResourceClaim is valid.
func ValidateResourceClaimUpdate(resourceClaim, oldClaim *resource.ResourceClaim) field.ErrorList {
allErrs := corevalidation.ValidateObjectMeta(&resourceClaim.ObjectMeta, true, corevalidation.ValidateResourceClaimName, field.NewPath("metadata"))
allErrs = append(allErrs, corevalidation.ValidateObjectMetaUpdate(&resourceClaim.ObjectMeta, &oldClaim.ObjectMeta, field.NewPath("metadata"))...)
// The spec is immutable. On update, we only check for immutability.
// Re-validating other fields is skipped because the user cannot change them;
// the only actionable error is for the immutability violation.
allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(resourceClaim.Spec, oldClaim.Spec, field.NewPath("spec"))...)
return allErrs
}
now the only effective delta from this change is no longer calling:
allErrs = append(allErrs, validateResourceClaimSpec(&resourceClaim.Spec, field.NewPath("spec"), false)...)
842c613
to
b4d1d9b
Compare
/retest |
/retest |
b4d1d9b
to
e62523e
Compare
/retest |
/sig api-machinery |
/lgtm |
LGTM label has been added. Git tree hash: 7c1466e12a45c590645caaae2909aec0ec383f74
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aaron-prindle, liggitt, pohly 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 cleanup
What this PR does / why we need it:
This PR modifies -
pkg/registry/resource/resourceclaim/strategy.go
so that ValidateUpdate no longer callsValidateResourceClaim
which is unnecessary as this is called on CREATE and then on UPDATE we do an immutability check where no field in the Spec can change. If no fields can change and we validated on CREATE then we shouldn't need to re-validate on update. Status fields are wiped for the root resource UPDATE call so this is correct logic for the root endpoint by just having spec be immutable.A test change is needed here as previously this test:
triggered the
fieldImmutableError
error (changing spec and namespace) AND triggered thedeviceRequestError
- see debug logs here from the original test case before this PR:but with this change to strategy.go now only the immutability error would be present. As such the test was updated to check for
fieldImmutableError
Which issue(s) this PR is related to:
Special notes for your reviewer:
Alternatively we could keep the
ValidateResourceClaim
call but have theValidateResourceClaimUpdate
occur first and short-circuit.Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: