mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Validating the scheduling gate naming format
This commit is contained in:
parent
a25834cb5a
commit
f09eeaf104
@ -3365,9 +3365,7 @@ func validateSchedulingGates(schedulingGates []core.PodSchedulingGate, fldPath *
|
|||||||
// There should be no duplicates in the list of scheduling gates.
|
// There should be no duplicates in the list of scheduling gates.
|
||||||
seen := sets.String{}
|
seen := sets.String{}
|
||||||
for i, schedulingGate := range schedulingGates {
|
for i, schedulingGate := range schedulingGates {
|
||||||
if schedulingGate.Name == "" {
|
allErrs = append(allErrs, ValidateQualifiedName(schedulingGate.Name, fldPath.Index(i))...)
|
||||||
allErrs = append(allErrs, field.Required(fldPath.Index(i), "must not be empty"))
|
|
||||||
}
|
|
||||||
if seen.Has(schedulingGate.Name) {
|
if seen.Has(schedulingGate.Name) {
|
||||||
allErrs = append(allErrs, field.Duplicate(fldPath.Index(i), schedulingGate.Name))
|
allErrs = append(allErrs, field.Duplicate(fldPath.Index(i), schedulingGate.Name))
|
||||||
}
|
}
|
||||||
|
@ -18696,7 +18696,10 @@ func TestValidateSchedulingGates(t *testing.T) {
|
|||||||
{Name: "foo"},
|
{Name: "foo"},
|
||||||
{Name: ""},
|
{Name: ""},
|
||||||
},
|
},
|
||||||
wantFieldErrors: []*field.Error{field.Required(fieldPath.Index(1), "must not be empty")},
|
wantFieldErrors: field.ErrorList{
|
||||||
|
field.Invalid(fieldPath.Index(1), "", "name part must be non-empty"),
|
||||||
|
field.Invalid(fieldPath.Index(1), "", "name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "legal gates",
|
name: "legal gates",
|
||||||
@ -18706,6 +18709,14 @@ func TestValidateSchedulingGates(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantFieldErrors: field.ErrorList{},
|
wantFieldErrors: field.ErrorList{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "illegal gates",
|
||||||
|
schedulingGates: []core.PodSchedulingGate{
|
||||||
|
{Name: "foo"},
|
||||||
|
{Name: "\nbar"},
|
||||||
|
},
|
||||||
|
wantFieldErrors: []*field.Error{field.Invalid(fieldPath.Index(1), "\nbar", "name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')")},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "duplicated gates (single duplication)",
|
name: "duplicated gates (single duplication)",
|
||||||
schedulingGates: []core.PodSchedulingGate{
|
schedulingGates: []core.PodSchedulingGate{
|
||||||
|
Loading…
Reference in New Issue
Block a user