fix as suggested

This commit is contained in:
Kensei Nakada 2023-04-01 10:34:57 +00:00
parent ffcf3ee6f8
commit e389d140ae
2 changed files with 10 additions and 10 deletions

View File

@ -115,7 +115,7 @@ func warningsForPodSpecAndMeta(fieldPath *field.Path, podSpec *api.PodSpec, meta
// warn if labelSelector is empty which is no-match. // warn if labelSelector is empty which is no-match.
if t.LabelSelector == nil { if t.LabelSelector == nil {
warnings = append(warnings, fmt.Sprintf("%s: LabelSelector mustn't be empty; it will result in matching with no object", fieldPath.Child("spec", "topologySpreadConstraints").Index(i).Child("labelSelector"))) warnings = append(warnings, fmt.Sprintf("%s: a null labelSelector results in matching no pod", fieldPath.Child("spec", "topologySpreadConstraints").Index(i).Child("labelSelector")))
} }
} }
@ -278,7 +278,7 @@ func warningsForPodAffinityTerms(terms []api.PodAffinityTerm, fieldPath *field.P
var warnings []string var warnings []string
for i, t := range terms { for i, t := range terms {
if t.LabelSelector == nil { if t.LabelSelector == nil {
warnings = append(warnings, fmt.Sprintf("%s: LabelSelector mustn't be empty; it will result in matching with no object", fieldPath.Index(i).Child("labelSelector"))) warnings = append(warnings, fmt.Sprintf("%s: a null labelSelector results in matching no pod", fieldPath.Index(i).Child("labelSelector")))
} }
} }
return warnings return warnings
@ -289,7 +289,7 @@ func warningsForWeightedPodAffinityTerms(terms []api.WeightedPodAffinityTerm, fi
for i, t := range terms { for i, t := range terms {
// warn if labelSelector is empty which is no-match. // warn if labelSelector is empty which is no-match.
if t.PodAffinityTerm.LabelSelector == nil { if t.PodAffinityTerm.LabelSelector == nil {
warnings = append(warnings, fmt.Sprintf("%s: LabelSelector mustn't be empty; it will result in matching with no object", fieldPath.Index(i).Child("podAffinityTerm", "labelSelector"))) warnings = append(warnings, fmt.Sprintf("%s: a null labelSelector results in matching no pod", fieldPath.Index(i).Child("podAffinityTerm", "labelSelector")))
} }
} }
return warnings return warnings

View File

@ -521,7 +521,7 @@ func TestWarnings(t *testing.T) {
}, },
}, },
{ {
name: "empty LabelSelector in topologySpreadConstraints", name: "null LabelSelector in topologySpreadConstraints",
template: &api.PodTemplateSpec{ template: &api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{}, ObjectMeta: metav1.ObjectMeta{},
Spec: api.PodSpec{ Spec: api.PodSpec{
@ -536,11 +536,11 @@ func TestWarnings(t *testing.T) {
}, },
}, },
expected: []string{ expected: []string{
`spec.topologySpreadConstraints[1].labelSelector: LabelSelector mustn't be empty; it will result in matching with no object`, `spec.topologySpreadConstraints[1].labelSelector: a null labelSelector results in matching no pod`,
}, },
}, },
{ {
name: "empty LabelSelector in PodAffinity", name: "null LabelSelector in PodAffinity",
template: &api.PodTemplateSpec{ template: &api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{}, ObjectMeta: metav1.ObjectMeta{},
Spec: api.PodSpec{ Spec: api.PodSpec{
@ -593,10 +593,10 @@ func TestWarnings(t *testing.T) {
}, },
}, },
expected: []string{ expected: []string{
`spec.affinity.podAffinity.requiredDuringSchedulingIgnoredDuringExecution[1].labelSelector: LabelSelector mustn't be empty; it will result in matching with no object`, `spec.affinity.podAffinity.requiredDuringSchedulingIgnoredDuringExecution[1].labelSelector: a null labelSelector results in matching no pod`,
`spec.affinity.podAffinity.preferredDuringSchedulingIgnoredDuringExecution[1].podAffinityTerm.labelSelector: LabelSelector mustn't be empty; it will result in matching with no object`, `spec.affinity.podAffinity.preferredDuringSchedulingIgnoredDuringExecution[1].podAffinityTerm.labelSelector: a null labelSelector results in matching no pod`,
`spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[1].labelSelector: LabelSelector mustn't be empty; it will result in matching with no object`, `spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[1].labelSelector: a null labelSelector results in matching no pod`,
`spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[1].podAffinityTerm.labelSelector: LabelSelector mustn't be empty; it will result in matching with no object`, `spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[1].podAffinityTerm.labelSelector: a null labelSelector results in matching no pod`,
}, },
}, },
} }