Skip to content

Enable OpenAPI formats immediately at release version #132531

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpbetz
Copy link
Contributor

@jpbetz jpbetz commented Jun 25, 2025

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

The JSON Schema specification states that unrecognized formats should be allowed, but ignored, by implementations. Kubernetes honors this and allows
unrecognized formats in CRD OpenAPI schemas. The implication here is that formats like the newly introduced k8s-long-name can be put in CRD schemas, even in very old Kubernetes releases. The apiserver will allow the unrecognized formats to be written into the CRD and will ignore them (we don't publish them into discovery OpenAPI endpoint, however).

Because of this, it is possible for us to enable newly supported formats in the same release the formats are introduced, eliminating a 1-release delay. This PR proposes making this change. That is, instead using introducedVersion>=minCompatibilityVersion, we can use introducedVersion>=emulationVersion.

AFAIK, this change has no impact on downgrade. No matter what version we start enforcing a format, a downgrade to the previous version will cause the format to be ignored. Ratcheting ensures that unchanged fields will be treated as valid in the case of a downgrade/modify-field-to-invalid-value-according-to-format/upgrade.

There is also one reason this change might actually be SAFER: Once we document the existence of a format, it is likely to be put to use. With this change, we shorten the time window where the format is known the community but not enforced.

Does this PR introduce a user-facing change?

Changed CustomResourceDefinitions to immediately enforce new OpenAPI formats on the same release the new formats are introduced.

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. area/apiserver area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jun 25, 2025
@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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 25, 2025
effectiveVer = DefaultBuildEffectiveVersion()
}
return effectiveVer
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@siyuanfoundation @Jefftree Are you okay with introducing this function? We do this lookup quite a few places..

Copy link
Member

Choose a reason for hiding this comment

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

yep, sgtm.

Copy link
Contributor Author

@jpbetz jpbetz Jun 25, 2025

Choose a reason for hiding this comment

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

An alternative I considered was to make this a receiver function of the registry, but we only have the build tag fallback for the kube component, so it didn't seem to add any value.

@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 25, 2025

@liggitt @thockin This is a fast follow on #132504 that I kept separate because it might be more contentious. The format release policy change proposed in the description is the critical bit.

@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 25, 2025

I've also opened #132532 to try to reduce the problems that can be caused by introducing new formats.

@lmktfy
Copy link

lmktfy commented Jun 26, 2025

I'd give this PR its own changelog entry.

@yongruilin
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed 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. labels Jun 26, 2025
@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 26, 2025

I'd give this PR its own changelog entry.

Added.

@@ -94,22 +94,23 @@ func (s basicSchemaValidator) ValidateUpdate(new, old interface{}, options ...Va

// NewSchemaValidator creates an openapi schema validator for the given CRD validation using environment.DefaultCompatibilityVersion().
func NewSchemaValidator(customResourceValidation *apiextensions.JSONSchemaProps) (SchemaValidator, *spec.Schema, error) {
return NewSchemaValidatorForVersion(customResourceValidation, environment.DefaultCompatibilityVersion())
return NewSchemaValidatorForVersion(customResourceValidation, compatibility.KubeComponentEffectiveVersion().EmulationVersion())
Copy link
Member

Choose a reason for hiding this comment

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

Need to change the godoc, at least

What are the implications of changing the version this uses by default? It looks like this is used when writing CRDs to decide if all the validation stuff in the CRD spec is valid to persist. Don't we have to construct that with our compatibility version to make sure we don't persist a CRD a skewed older API server would choke on?

// If the kube component is registered in the DefaultComponentGlobalsRegistry, the
// effective version from the registry is returned. Otherwise, the DefaultBuildEffectiveVersion
// is returned.
func KubeComponentEffectiveVersion() basecompatibility.EffectiveVersion {
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a global, it is possible to call this before the parsing / initialization of the effective version has been done, right?

We tried to add tests into the cel initialization paths to detect when things initialized based on versions or gates prematurely, but moving this into a global used by things other than cel worries me a bit. How can we protect against accidentally using this in an initialization path too early?

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. area/apiserver area/test 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants