diff --git a/pkg/expansion/system.go b/pkg/expansion/system.go index 5287b159726..82b59c8c187 100644 --- a/pkg/expansion/system.go +++ b/pkg/expansion/system.go @@ -85,6 +85,9 @@ func ValidateTemplate(template *expansionunversioned.ExpansionTemplate) error { if k == "" { return fmt.Errorf("ExpansionTemplate has empty name field") } + if len(k) > 64 { + return fmt.Errorf("ExpansionTemplate name must be less than 64 characters") + } if template.Spec.TemplateSource == "" { return fmt.Errorf("ExpansionTemplate %s has empty source field", k) } diff --git a/pkg/expansion/system_test.go b/pkg/expansion/system_test.go index 9eaf394b6e6..726c915e3d1 100644 --- a/pkg/expansion/system_test.go +++ b/pkg/expansion/system_test.go @@ -336,6 +336,24 @@ func TestValidateTemplate(t *testing.T) { }), errFn: matchErr("empty name"), }, + { + name: "name too long", + temp: *fixtures.NewTemplate(&fixtures.TemplateData{ + Name: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + Apply: []match.ApplyTo{{ + Groups: []string{"apps"}, + Kinds: []string{"Deployment"}, + Versions: []string{"v1"}, + }}, + Source: "spec.template", + GenGVK: expansionunversioned.GeneratedGVK{ + Group: "", + Version: "v1", + Kind: "Pod", + }, + }), + errFn: matchErr("less than 64"), + }, { name: "missing source", temp: *fixtures.NewTemplate(&fixtures.TemplateData{