API changes for Pod Level Resources

1. Add Resources struct to PodSpec struct in both external and internal API packages
2. Adding feature gate and logic for dropping disabled fields for Pod Level Resources
KEP: enhancements/keps/sig-node/2837-pod-level-resource-spec
This commit is contained in:
ndixita
2024-10-16 17:01:47 +00:00
parent 210deea063
commit d7f488b5e3
6 changed files with 213 additions and 0 deletions

View File

@@ -621,6 +621,7 @@ func dropDisabledFields(
}
}
dropDisabledPodLevelResources(podSpec, oldPodSpec)
dropDisabledProcMountField(podSpec, oldPodSpec)
dropDisabledNodeInclusionPolicyFields(podSpec, oldPodSpec)
@@ -674,6 +675,14 @@ func dropDisabledFields(
dropSELinuxChangePolicy(podSpec, oldPodSpec)
}
func dropDisabledPodLevelResources(podSpec, oldPodSpec *api.PodSpec) {
// If the feature is disabled and not in use, drop Resources at the pod-level
// from PodSpec.
if !utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources) && !podLevelResourcesInUse(oldPodSpec) {
podSpec.Resources = nil
}
}
func dropPodLifecycleSleepAction(podSpec, oldPodSpec *api.PodSpec) {
if utilfeature.DefaultFeatureGate.Enabled(features.PodLifecycleSleepAction) || podLifecycleSleepActionInUse(oldPodSpec) {
return
@@ -1050,6 +1059,28 @@ func supplementalGroupsPolicyInUse(podSpec *api.PodSpec) bool {
return false
}
// podLevelResourcesInUse returns true if pod-spec is non-nil and Resources field at
// pod-level has non-empty Requests or Limits.
func podLevelResourcesInUse(podSpec *api.PodSpec) bool {
if podSpec == nil {
return false
}
if podSpec.Resources == nil {
return false
}
if len(podSpec.Resources.Requests) > 0 {
return true
}
if len(podSpec.Resources.Limits) > 0 {
return true
}
return false
}
// inPlacePodVerticalScalingInUse returns true if pod spec is non-nil and ResizePolicy is set
func inPlacePodVerticalScalingInUse(podSpec *api.PodSpec) bool {
if podSpec == nil {