From f8d2df0f74b8a40430eafe43f0968b1a3522e83c Mon Sep 17 00:00:00 2001 From: yongruilin Date: Tue, 16 Sep 2025 17:33:44 +0000 Subject: [PATCH] refactor: skip re-validating for unchanged resource claim specs --- pkg/apis/resource/validation/validation.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/apis/resource/validation/validation.go b/pkg/apis/resource/validation/validation.go index b06472a4537..a911b1139e5 100644 --- a/pkg/apis/resource/validation/validation.go +++ b/pkg/apis/resource/validation/validation.go @@ -95,11 +95,10 @@ func ValidateResourceClaim(resourceClaim *resource.ResourceClaim) field.ErrorLis // ValidateResourceClaimUpdate tests if an update to ResourceClaim is valid. func ValidateResourceClaimUpdate(resourceClaim, oldClaim *resource.ResourceClaim) field.ErrorList { 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"))...) - // Because the spec is immutable, all CEL expressions in it must have been stored. - // If the user tries an update, this is not true and checking is less strict, but - // as there are errors, it doesn't matter. - allErrs = append(allErrs, validateResourceClaimSpec(&resourceClaim.Spec, field.NewPath("spec"), true)...) return allErrs } @@ -580,11 +579,10 @@ func validateResourceClaimTemplateSpec(spec *resource.ResourceClaimTemplateSpec, // ValidateResourceClaimTemplateUpdate tests if an update to template is valid. func ValidateResourceClaimTemplateUpdate(template, oldTemplate *resource.ResourceClaimTemplate) field.ErrorList { allErrs := corevalidation.ValidateObjectMetaUpdate(&template.ObjectMeta, &oldTemplate.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(template.Spec, oldTemplate.Spec, field.NewPath("spec"))...) - // Because the spec is immutable, all CEL expressions in it must have been stored. - // If the user tries an update, this is not true and checking is less strict, but - // as there are errors, it doesn't matter. - allErrs = append(allErrs, validateResourceClaimTemplateSpec(&template.Spec, field.NewPath("spec"), true)...) return allErrs }