mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #123181 from tenzen-y/job-avoid-casts-due-to-old-sets
Job: Use generic sets to avoid unnecessary string casts in valiations
This commit is contained in:
commit
9fa043e769
@ -28,6 +28,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
apimachineryvalidation "k8s.io/apimachinery/pkg/util/validation"
|
apimachineryvalidation "k8s.io/apimachinery/pkg/util/validation"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
@ -402,25 +403,25 @@ func validateJobStatus(status *batch.JobStatus, fldPath *field.Path) field.Error
|
|||||||
}
|
}
|
||||||
if status.UncountedTerminatedPods != nil {
|
if status.UncountedTerminatedPods != nil {
|
||||||
path := fldPath.Child("uncountedTerminatedPods")
|
path := fldPath.Child("uncountedTerminatedPods")
|
||||||
seen := sets.NewString()
|
seen := sets.New[types.UID]()
|
||||||
for i, k := range status.UncountedTerminatedPods.Succeeded {
|
for i, k := range status.UncountedTerminatedPods.Succeeded {
|
||||||
p := path.Child("succeeded").Index(i)
|
p := path.Child("succeeded").Index(i)
|
||||||
if k == "" {
|
if k == "" {
|
||||||
allErrs = append(allErrs, field.Invalid(p, k, "must not be empty"))
|
allErrs = append(allErrs, field.Invalid(p, k, "must not be empty"))
|
||||||
} else if seen.Has(string(k)) {
|
} else if seen.Has(k) {
|
||||||
allErrs = append(allErrs, field.Duplicate(p, k))
|
allErrs = append(allErrs, field.Duplicate(p, k))
|
||||||
} else {
|
} else {
|
||||||
seen.Insert(string(k))
|
seen.Insert(k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, k := range status.UncountedTerminatedPods.Failed {
|
for i, k := range status.UncountedTerminatedPods.Failed {
|
||||||
p := path.Child("failed").Index(i)
|
p := path.Child("failed").Index(i)
|
||||||
if k == "" {
|
if k == "" {
|
||||||
allErrs = append(allErrs, field.Invalid(p, k, "must not be empty"))
|
allErrs = append(allErrs, field.Invalid(p, k, "must not be empty"))
|
||||||
} else if seen.Has(string(k)) {
|
} else if seen.Has(k) {
|
||||||
allErrs = append(allErrs, field.Duplicate(p, k))
|
allErrs = append(allErrs, field.Duplicate(p, k))
|
||||||
} else {
|
} else {
|
||||||
seen.Insert(string(k))
|
seen.Insert(k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user