Skip to content
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

KEP-5051: Add opt-in support for unset markers #280

Closed
wants to merge 3 commits into from

Conversation

jpbetz
Copy link
Contributor

@jpbetz jpbetz commented Jan 23, 2025

This implements the SMD bits of kubernetes/enhancements#5052.

All the new functionality is opt-in. No default behavior is changed. This is extensively tested.

Benchmark data suggests negligible performance impact: https://gist.github.com/jpbetz/df3806a5605a174597a3d0d6459125c5

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 23, 2025
@k8s-ci-robot k8s-ci-robot requested a review from cici37 January 23, 2025 19:55
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jpbetz

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 requested a review from Jefftree January 23, 2025 19:55
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 23, 2025

const (
// markerKey is the key used to store marker values in the object.
markerKey = "k8s_io__value"
Copy link
Contributor Author

@jpbetz jpbetz Jan 23, 2025

Choose a reason for hiding this comment

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

@deads2k @sttts Suggestions welcome on how to name the key/value of the markers used in the proposal. BTH, I'm actively looking for something more pleasing to the eye. Having a key that is also a valid CEL identifier is important for MutatingAdmissionPolicy, so [a-z][A-Z][0-9]_ (non-number first char) is strongly preferred. And picking something that "no one could reasonably already be using for something else" is also desirable.

@jpbetz jpbetz force-pushed the unsetting-fields branch 2 times, most recently from 224104f to e6a5a35 Compare January 23, 2025 21:35
@jpbetz jpbetz changed the title KEP-5052: Add opt-in support for unset markers KEP-5051: Add opt-in support for unset markers Jan 23, 2025
@jpbetz
Copy link
Contributor Author

jpbetz commented Jan 24, 2025

/retest
Now that apidiff PR has merged.

@k8s-ci-robot
Copy link
Contributor

@jpbetz: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-structured-merge-diff-apidiff 38f711b link false /test pull-structured-merge-diff-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@@ -128,6 +137,42 @@ func (tv TypedValue) ToFieldSet() (*fieldpath.Set, error) {
return w.set, nil
}

// ExtractMarkers finds and all marker values in TypedValue.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ExtractMarkers finds and all marker values in TypedValue.
// ExtractMarkers finds all marker values in TypedValue.

}

// validateMarkerLocation returns true if the current value is a marker and false otherwise.
// It the value is a marker, it returns a list of errors if the marker is not in a valid location.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// It the value is a marker, it returns a list of errors if the marker is not in a valid location.
// If the value is a marker, it returns a list of errors if the marker is not in a valid location.

return false, nil
}
if marker != unsetMarkerValue {
// Should never happen since validation already checks for allowed marker values.
Copy link
Contributor

Choose a reason for hiding this comment

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

So how about just getting rid of this function and just use isUnsetMarker(v)?

func (v *markerExtractorWalker) validateMarkerLocation(t interface{}) (bool, ValidationErrors) {
	if !isUnsetMarker(v.value) {
		return false, nil
	}
        ...
        ...

}
return true
})
return errs
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we descend further if this map is atomic?

Comment on lines +124 to +128
for i := len(v.parentElementRelationship) - 1; i >= 0; i-- {
if v.parentElementRelationship[i] != nil {
return v.parentElementRelationship[i]
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We're only looking for the nearestElementRelationship, what if it is nested? e.g. an atomic List which contains maps(not atomic),

              types:
              - name: TestType
                map:
                  fields:
                  - name: items
                    type:
                      list:
                        elementType:
                          map:
                            fields:
                            - name: key
                              type:
                                scalar: string
                            - name: value
                              type:
                                scalar: string
                        elementRelationship: atomic

and applyconfig is {"items": [{"key": "k1", "value": {"k8s_io__value": "unset"}}]}, should we throw an error for it? The parentElementRelationship would be ["", "atomic", ""] when validating the marker location.

Or, it should be if v.parentElementRelationship[i] != nil && *v.parentElementRelationship[i] != "" && *v.parentElementRelationship[i] != "separable { to looking for the nearest "atomic" or 'associative"?

@jpbetz
Copy link
Contributor Author

jpbetz commented Mar 29, 2025

/close
The KEP for this did not get approved.

@k8s-ci-robot
Copy link
Contributor

@jpbetz: Closed this PR.

In response to this:

/close
The KEP for this did not get approved.

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.

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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants