Skip to content

Conversation

aaron-prindle
Copy link
Contributor

@aaron-prindle aaron-prindle commented Oct 4, 2025

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 calls ValidateResourceClaim 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:

		"drop-fields-prioritized-list": {
			oldObj:                obj,
			newObj:                objWithPrioritizedList,
			prioritizedList:       false,
			expectValidationError: deviceRequestError,
			verify: func(t *testing.T, as []testclient.Action) {
				if len(as) != 0 {
					t.Errorf("expected no action to be taken")
				}
			},
		},

triggered the fieldImmutableError error (changing spec and namespace) AND triggered the deviceRequestError - see debug logs here from the original test case before this PR:

    strategy_test.go:775: Error found: spec.devices.requests[0]: Required value: exactly one of `exactly` or `firstAvailable` is required
    strategy_test.go:775: Error found: metadata.namespace: Invalid value: "default": field is immutable
    strategy_test.go:775: Error found: spec: Invalid value: ...: field is immutable
    strategy_test.go:782: CONFIRMED: Namespace immutability error was present.

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 the ValidateResourceClaimUpdate occur first and short-circuit.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 4, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 4, 2025
@k8s-ci-robot k8s-ci-robot requested review from bart0sh and pohly October 4, 2025 01:00
@k8s-ci-robot k8s-ci-robot added the wg/device-management Categorizes an issue or PR as relevant to WG Device Management. label Oct 4, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Oct 4, 2025
@aaron-prindle
Copy link
Contributor Author

/cc @pohly

@aaron-prindle aaron-prindle force-pushed the resourceclaim-strategy-cleanup branch from 93883e9 to 89259eb Compare October 4, 2025 22:04
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 4, 2025
@aaron-prindle
Copy link
Contributor Author

/retest

Copy link
Contributor

@pohly pohly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 6, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 1efb5179719d1d821f5dd6fb9a3d9f23b4b0b560

@pohly pohly moved this from 🆕 New to 👀 In review in Dynamic Resource Allocation Oct 6, 2025
@aaron-prindle
Copy link
Contributor Author

/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)
Copy link
Contributor

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...

Copy link
Contributor Author

@aaron-prindle aaron-prindle Oct 6, 2025

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

Copy link
Contributor Author

@aaron-prindle aaron-prindle Oct 6, 2025

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.

Copy link
Member

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

Copy link
Contributor Author

@aaron-prindle aaron-prindle Oct 6, 2025

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)...)

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 6, 2025
@k8s-ci-robot k8s-ci-robot requested a review from liggitt October 6, 2025 20:25
@k8s-ci-robot k8s-ci-robot requested a review from pohly October 6, 2025 20:25
@aaron-prindle aaron-prindle force-pushed the resourceclaim-strategy-cleanup branch from 842c613 to b4d1d9b Compare October 6, 2025 20:26
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 6, 2025
@aaron-prindle
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 6, 2025
@aaron-prindle
Copy link
Contributor Author

/retest

@aaron-prindle aaron-prindle force-pushed the resourceclaim-strategy-cleanup branch from b4d1d9b to e62523e Compare October 6, 2025 22:11
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 6, 2025
@aaron-prindle
Copy link
Contributor Author

/retest

@aaron-prindle
Copy link
Contributor Author

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Oct 7, 2025
@liggitt
Copy link
Member

liggitt commented Oct 7, 2025

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 7, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 7c1466e12a45c590645caaae2909aec0ec383f74

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 7, 2025
@k8s-ci-robot k8s-ci-robot merged commit 62e9524 into kubernetes:master Oct 7, 2025
21 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.35 milestone Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. wg/device-management Categorizes an issue or PR as relevant to WG Device Management.
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

5 participants