-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Validate OS not windows for PodLevelResources in API server #132627
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
base: master
Are you sure you want to change the base?
Validate OS not windows for PodLevelResources in API server #132627
Conversation
Reject Pod with PodLevelResources in spec if Pod targets Windows OS.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: annasong20 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/sig node |
/assign @ndixita |
if spec.OS != nil && spec.OS.Name == core.Windows { | ||
// Do not include more detailed errors on the resources field value | ||
// if the resources field cannot be set on the target OS. | ||
return field.ErrorList{ |
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.
LMK if I should append the error instead.
podtest.SetPodResources(&core.ResourceRequirements{Limits: getResources("100m", "200Mi", "", "")}), | ||
podtest.SetContainers(podtest.MakeContainer("container")), | ||
podtest.SetOS(core.Linux), | ||
), | ||
} | ||
for k, v := range successCases { | ||
t.Run(k, func(t *testing.T) { | ||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.StrictIPCIDRValidation, true) |
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.
FYI I found it interesting that I didn't need to enable the PodLevelResources
feature gate in this test.
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.
Indeed. That’s because only StrictIPCIDRValidation
checks the FeatureGate directly inside the validation code.
kubernetes/pkg/apis/core/validation/validation.go
Line 8863 in b3341bd
return validation.IsValidIPForLegacyField(fldPath, value, utilfeature.DefaultFeatureGate.Enabled(features.StrictIPCIDRValidation), validOldIPs) |
For other features, the FeatureGate is checked when creating PodValidationOptions
, which is then passed to the validation logic. So if we can pass PodValidationOptions
directly in unit tests, we don’t need to use featuregatetesting.SetFeatureGateDuringTest
.
kubernetes/pkg/api/pod/util.go
Line 422 in 081b345
PodLevelResourcesEnabled: utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources), |
/triage accepted |
/ok-to-test |
Reject Pod with PodLevelResources in spec if Pod targets Windows OS.
What type of PR is this?
/kind bug
What this PR does / why we need it:
Adds check to API server to reject Pod with PodLevelResources if Pod targets Windows OS.
Which issue(s) this PR is related to:
Addresses API server portion of #132582.
PodLevelResources KEP that documents this behavior: https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/2837-pod-level-resource-spec/README.md#future-kep-consideration-in-135-support-for-windows.
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: