@@ -1777,6 +1777,8 @@ var allowedTemplateObjectMetaFields = map[string]bool{
1777
1777
type PersistentVolumeSpecValidationOptions struct {
1778
1778
// Allow users to modify the class of volume attributes
1779
1779
EnableVolumeAttributesClass bool
1780
+ // Allow invalid label-value in RequiredNodeSelector
1781
+ AllowInvalidLabelValueInRequiredNodeAffinity bool
1780
1782
}
1781
1783
1782
1784
// ValidatePersistentVolumeName checks that a name is appropriate for a
@@ -1798,11 +1800,17 @@ var supportedVolumeModes = sets.New(core.PersistentVolumeBlock, core.PersistentV
1798
1800
1799
1801
func ValidationOptionsForPersistentVolume (pv , oldPv * core.PersistentVolume ) PersistentVolumeSpecValidationOptions {
1800
1802
opts := PersistentVolumeSpecValidationOptions {
1801
- EnableVolumeAttributesClass : utilfeature .DefaultMutableFeatureGate .Enabled (features .VolumeAttributesClass ),
1803
+ EnableVolumeAttributesClass : utilfeature .DefaultMutableFeatureGate .Enabled (features .VolumeAttributesClass ),
1804
+ AllowInvalidLabelValueInRequiredNodeAffinity : false ,
1802
1805
}
1803
1806
if oldPv != nil && oldPv .Spec .VolumeAttributesClassName != nil {
1804
1807
opts .EnableVolumeAttributesClass = true
1805
1808
}
1809
+ if oldPv != nil && oldPv .Spec .NodeAffinity != nil &&
1810
+ oldPv .Spec .NodeAffinity .Required != nil {
1811
+ terms := oldPv .Spec .NodeAffinity .Required .NodeSelectorTerms
1812
+ opts .AllowInvalidLabelValueInRequiredNodeAffinity = helper .HasInvalidLabelValueInNodeSelectorTerms (terms )
1813
+ }
1806
1814
return opts
1807
1815
}
1808
1816
@@ -1874,7 +1882,7 @@ func ValidatePersistentVolumeSpec(pvSpec *core.PersistentVolumeSpec, pvName stri
1874
1882
if validateInlinePersistentVolumeSpec {
1875
1883
allErrs = append (allErrs , field .Forbidden (fldPath .Child ("nodeAffinity" ), "may not be specified in the context of inline volumes" ))
1876
1884
} else {
1877
- nodeAffinitySpecified , errs = validateVolumeNodeAffinity (pvSpec .NodeAffinity , fldPath .Child ("nodeAffinity" ))
1885
+ nodeAffinitySpecified , errs = validateVolumeNodeAffinity (pvSpec .NodeAffinity , opts , fldPath .Child ("nodeAffinity" ))
1878
1886
allErrs = append (allErrs , errs ... )
1879
1887
}
1880
1888
}
@@ -3865,7 +3873,7 @@ func validateAffinity(affinity *core.Affinity, opts PodValidationOptions, fldPat
3865
3873
3866
3874
if affinity != nil {
3867
3875
if affinity .NodeAffinity != nil {
3868
- allErrs = append (allErrs , validateNodeAffinity (affinity .NodeAffinity , fldPath .Child ("nodeAffinity" ))... )
3876
+ allErrs = append (allErrs , validateNodeAffinity (affinity .NodeAffinity , opts , fldPath .Child ("nodeAffinity" ))... )
3869
3877
}
3870
3878
if affinity .PodAffinity != nil {
3871
3879
allErrs = append (allErrs , validatePodAffinity (affinity .PodAffinity , opts .AllowInvalidLabelValueInSelector , fldPath .Child ("podAffinity" ))... )
@@ -4053,6 +4061,8 @@ type PodValidationOptions struct {
4053
4061
PodLevelResourcesEnabled bool
4054
4062
// Allow sidecar containers resize policy for backward compatibility
4055
4063
AllowSidecarResizePolicy bool
4064
+ // Allow invalid label-value in RequiredNodeSelector
4065
+ AllowInvalidLabelValueInRequiredNodeAffinity bool
4056
4066
}
4057
4067
4058
4068
// validatePodMetadataAndSpec tests if required fields in the pod.metadata and pod.spec are set,
@@ -4730,14 +4740,14 @@ func validatePodAntiAffinity(podAntiAffinity *core.PodAntiAffinity, allowInvalid
4730
4740
}
4731
4741
4732
4742
// validateNodeAffinity tests that the specified nodeAffinity fields have valid data
4733
- func validateNodeAffinity (na * core.NodeAffinity , fldPath * field.Path ) field.ErrorList {
4743
+ func validateNodeAffinity (na * core.NodeAffinity , opts PodValidationOptions , fldPath * field.Path ) field.ErrorList {
4734
4744
allErrs := field.ErrorList {}
4735
4745
// TODO: Uncomment the next three lines once RequiredDuringSchedulingRequiredDuringExecution is implemented.
4736
4746
// if na.RequiredDuringSchedulingRequiredDuringExecution != nil {
4737
4747
// allErrs = append(allErrs, ValidateNodeSelector(na.RequiredDuringSchedulingRequiredDuringExecution, fldPath.Child("requiredDuringSchedulingRequiredDuringExecution"))...)
4738
4748
// }
4739
4749
if na .RequiredDuringSchedulingIgnoredDuringExecution != nil {
4740
- allErrs = append (allErrs , ValidateNodeSelector (na .RequiredDuringSchedulingIgnoredDuringExecution , true /* TODO: opts.AllowInvalidLabelValueInRequiredNodeAffinity */ , fldPath .Child ("requiredDuringSchedulingIgnoredDuringExecution" ))... )
4750
+ allErrs = append (allErrs , ValidateNodeSelector (na .RequiredDuringSchedulingIgnoredDuringExecution , opts .AllowInvalidLabelValueInRequiredNodeAffinity , fldPath .Child ("requiredDuringSchedulingIgnoredDuringExecution" ))... )
4741
4751
}
4742
4752
if len (na .PreferredDuringSchedulingIgnoredDuringExecution ) > 0 {
4743
4753
allErrs = append (allErrs , ValidatePreferredSchedulingTerms (na .PreferredDuringSchedulingIgnoredDuringExecution , fldPath .Child ("preferredDuringSchedulingIgnoredDuringExecution" ))... )
@@ -7783,15 +7793,15 @@ func ValidateLoadBalancerStatus(status *core.LoadBalancerStatus, fldPath *field.
7783
7793
// returns:
7784
7794
// - true if volumeNodeAffinity is set
7785
7795
// - errorList if there are validation errors
7786
- func validateVolumeNodeAffinity (nodeAffinity * core.VolumeNodeAffinity , fldPath * field.Path ) (bool , field.ErrorList ) {
7796
+ func validateVolumeNodeAffinity (nodeAffinity * core.VolumeNodeAffinity , opts PersistentVolumeSpecValidationOptions , fldPath * field.Path ) (bool , field.ErrorList ) {
7787
7797
allErrs := field.ErrorList {}
7788
7798
7789
7799
if nodeAffinity == nil {
7790
7800
return false , allErrs
7791
7801
}
7792
7802
7793
7803
if nodeAffinity .Required != nil {
7794
- allErrs = append (allErrs , ValidateNodeSelector (nodeAffinity .Required , true /* TODO: opts.AllowInvalidLabelValueInRequiredNodeAffinity */ , fldPath .Child ("required" ))... )
7804
+ allErrs = append (allErrs , ValidateNodeSelector (nodeAffinity .Required , opts .AllowInvalidLabelValueInRequiredNodeAffinity , fldPath .Child ("required" ))... )
7795
7805
} else {
7796
7806
allErrs = append (allErrs , field .Required (fldPath .Child ("required" ), "must specify required node constraints" ))
7797
7807
}
0 commit comments