feat: add NodeInclusionPolicy to TopologySpreadConstraint in PodSpec
Signed-off-by: kerthcet <kerthcet@gmail.com>
This commit is contained in:
@@ -580,6 +580,7 @@ func dropDisabledFields(
|
||||
}
|
||||
|
||||
dropDisabledTopologySpreadConstraintsFields(podSpec, oldPodSpec)
|
||||
dropDisabledNodeInclusionPolicyFields(podSpec, oldPodSpec)
|
||||
}
|
||||
|
||||
// dropDisabledTopologySpreadConstraintsFields removes disabled fields from PodSpec related
|
||||
@@ -647,6 +648,51 @@ func dropDisabledCSIVolumeSourceAlphaFields(podSpec, oldPodSpec *api.PodSpec) {
|
||||
}
|
||||
}
|
||||
|
||||
// dropDisabledNodeInclusionPolicyFields removes disabled fields from PodSpec related
|
||||
// to NodeInclusionPolicy only if it is not used by the old spec.
|
||||
func dropDisabledNodeInclusionPolicyFields(podSpec, oldPodSpec *api.PodSpec) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.NodeInclusionPolicyInPodTopologySpread) && podSpec != nil {
|
||||
if !nodeTaintsPolicyInUse(oldPodSpec) {
|
||||
for i := range podSpec.TopologySpreadConstraints {
|
||||
podSpec.TopologySpreadConstraints[i].NodeTaintsPolicy = nil
|
||||
}
|
||||
}
|
||||
if !nodeAffinityPolicyInUse(oldPodSpec) {
|
||||
for i := range podSpec.TopologySpreadConstraints {
|
||||
podSpec.TopologySpreadConstraints[i].NodeAffinityPolicy = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nodeAffinityPolicyInUse returns true if the pod spec is non-nil and has NodeAffinityPolicy field set
|
||||
// in TopologySpreadConstraints
|
||||
func nodeAffinityPolicyInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
return false
|
||||
}
|
||||
for _, c := range podSpec.TopologySpreadConstraints {
|
||||
if c.NodeAffinityPolicy != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// nodeTaintsPolicyInUse returns true if the pod spec is non-nil and has NodeTaintsPolicy field set
|
||||
// in TopologySpreadConstraints
|
||||
func nodeTaintsPolicyInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
return false
|
||||
}
|
||||
for _, c := range podSpec.TopologySpreadConstraints {
|
||||
if c.NodeTaintsPolicy != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ephemeralContainersInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
return false
|
||||
|
Reference in New Issue
Block a user