PodPriority validation and tests

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
This commit is contained in:
Serguei Bezverkhi
2018-12-19 14:55:34 -05:00
parent 190f6d870e
commit 587c5d7263
3 changed files with 132 additions and 9 deletions

View File

@@ -235,13 +235,11 @@ func UpdatePodCondition(status *api.PodStatus, condition *api.PodCondition) bool
// DropDisabledFields removes disabled fields from the pod spec.
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pod spec.
func DropDisabledFields(podSpec, oldPodSpec *api.PodSpec) {
if !utilfeature.DefaultFeatureGate.Enabled(features.PodPriority) {
if !utilfeature.DefaultFeatureGate.Enabled(features.PodPriority) && !podPriorityInUse(oldPodSpec) {
// Set to nil pod's priority fields if the feature is disabled and the old pod
// does not specify any values for these fields.
podSpec.Priority = nil
podSpec.PriorityClassName = ""
if oldPodSpec != nil {
oldPodSpec.Priority = nil
oldPodSpec.PriorityClassName = ""
}
}
if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) {
@@ -419,3 +417,14 @@ func procMountInUse(podSpec *api.PodSpec) bool {
}
return false
}
// podPriorityInUse returns true if the pod spec is non-nil and has Priority or PriorityClassName set.
func podPriorityInUse(podSpec *api.PodSpec) bool {
if podSpec == nil {
return false
}
if podSpec.Priority != nil || podSpec.PriorityClassName != "" {
return true
}
return false
}