AllowExpandedDNSConfig if haveSameExpandedDNSConfig(newPod, oldPod)

This commit is contained in:
Gunju Kim
2021-05-24 20:58:59 +09:00
parent 6317ce63c6
commit d9681d7266
2 changed files with 391 additions and 1 deletions

View File

@@ -390,6 +390,37 @@ func usesIndivisibleHugePagesValues(podSpec *api.PodSpec) bool {
return false
}
// haveSameExpandedDNSConfig returns true if the oldPodSpec already had
// ExpandedDNSConfig and podSpec has the same DNSConfig
func haveSameExpandedDNSConfig(podSpec, oldPodSpec *api.PodSpec) bool {
if oldPodSpec == nil || oldPodSpec.DNSConfig == nil {
return false
}
if podSpec == nil || podSpec.DNSConfig == nil {
return false
}
if len(oldPodSpec.DNSConfig.Searches) <= apivalidation.MaxDNSSearchPathsLegacy &&
len(strings.Join(oldPodSpec.DNSConfig.Searches, " ")) <= apivalidation.MaxDNSSearchListCharsLegacy {
// didn't have ExpandedDNSConfig
return false
}
if len(oldPodSpec.DNSConfig.Searches) != len(podSpec.DNSConfig.Searches) {
// updates DNSConfig
return false
}
for i, oldSearch := range oldPodSpec.DNSConfig.Searches {
if podSpec.DNSConfig.Searches[i] != oldSearch {
// updates DNSConfig
return false
}
}
return true
}
// GetValidationOptionsFromPodSpecAndMeta returns validation options based on pod specs and metadata
func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, podMeta, oldPodMeta *metav1.ObjectMeta) apivalidation.PodValidationOptions {
// default pod validation options based on feature gate
@@ -403,7 +434,7 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
AllowIndivisibleHugePagesValues: false,
AllowWindowsHostProcessField: utilfeature.DefaultFeatureGate.Enabled(features.WindowsHostProcessContainers),
// Allow pod spec with expanded DNS configuration
AllowExpandedDNSConfig: utilfeature.DefaultFeatureGate.Enabled(features.ExpandedDNSConfig),
AllowExpandedDNSConfig: utilfeature.DefaultFeatureGate.Enabled(features.ExpandedDNSConfig) || haveSameExpandedDNSConfig(podSpec, oldPodSpec),
}
if oldPodSpec != nil {