From 428fcb7235fddd59aad9744968d58ade52f787b4 Mon Sep 17 00:00:00 2001 From: norbjd Date: Mon, 11 Aug 2025 17:01:17 +0200 Subject: [PATCH 1/2] Add a failing test (revision name starting with a digit doesn't work) --- pkg/apis/serving/v1/revision_validation_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/apis/serving/v1/revision_validation_test.go b/pkg/apis/serving/v1/revision_validation_test.go index 9373923ad229..90f72a432ec9 100644 --- a/pkg/apis/serving/v1/revision_validation_test.go +++ b/pkg/apis/serving/v1/revision_validation_test.go @@ -1253,6 +1253,12 @@ func TestValidateRevisionName(t *testing.T) { Name: "valid", }, revName: "valid-name", + }, { + name: "valid name - starts with a digit", + objectMeta: metav1.ObjectMeta{ + Name: "1valid", + }, + revName: "1valid-name", }} for _, c := range cases { From 62f519e7311a2080533883c236a8117fbf570b9e Mon Sep 17 00:00:00 2001 From: norbjd Date: Mon, 11 Aug 2025 17:06:22 +0200 Subject: [PATCH 2/2] Use NameIsDNSLabel for validation (RFC 1123) instead of NameIsDNS1035Label --- pkg/apis/serving/v1/configuration_validation_test.go | 4 ++-- pkg/apis/serving/v1/revision_validation.go | 8 ++++---- pkg/apis/serving/v1/revision_validation_test.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/apis/serving/v1/configuration_validation_test.go b/pkg/apis/serving/v1/configuration_validation_test.go index e4f4f0c767cb..28e46e61bab1 100644 --- a/pkg/apis/serving/v1/configuration_validation_test.go +++ b/pkg/apis/serving/v1/configuration_validation_test.go @@ -186,7 +186,7 @@ func TestConfigurationValidation(t *testing.T) { }, }, }, - want: apis.ErrInvalidValue("not a DNS 1035 label: [a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')]", + want: apis.ErrInvalidValue("not a DNS label: [must not contain dots]", "spec.template.metadata.name"), }, { name: "invalid generate name for configuration spec", @@ -209,7 +209,7 @@ func TestConfigurationValidation(t *testing.T) { }, }, }, - want: apis.ErrInvalidValue("not a DNS 1035 label prefix: [a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')]", + want: apis.ErrInvalidValue("not a DNS label prefix: [must not contain dots]", "spec.template.metadata.generateName"), }, { name: "valid generate name for configuration spec", diff --git a/pkg/apis/serving/v1/revision_validation.go b/pkg/apis/serving/v1/revision_validation.go index def2570fef70..08cee14ef34a 100644 --- a/pkg/apis/serving/v1/revision_validation.go +++ b/pkg/apis/serving/v1/revision_validation.go @@ -136,16 +136,16 @@ func (r *Revision) ValidateLabels() (errs *apis.FieldError) { // validateRevisionName validates name and generateName for the revisionTemplate func validateRevisionName(ctx context.Context, name, generateName string) *apis.FieldError { if generateName != "" { - if msgs := validation.NameIsDNS1035Label(generateName, true); len(msgs) > 0 { + if msgs := validation.NameIsDNSLabel(generateName, true); len(msgs) > 0 { return apis.ErrInvalidValue( - fmt.Sprint("not a DNS 1035 label prefix: ", msgs), + fmt.Sprint("not a DNS label prefix: ", msgs), "metadata.generateName") } } if name != "" { - if msgs := validation.NameIsDNS1035Label(name, false); len(msgs) > 0 { + if msgs := validation.NameIsDNSLabel(name, false); len(msgs) > 0 { return apis.ErrInvalidValue( - fmt.Sprint("not a DNS 1035 label: ", msgs), + fmt.Sprint("not a DNS label: ", msgs), "metadata.name") } om := apis.ParentMeta(ctx) diff --git a/pkg/apis/serving/v1/revision_validation_test.go b/pkg/apis/serving/v1/revision_validation_test.go index 90f72a432ec9..ae00941e0952 100644 --- a/pkg/apis/serving/v1/revision_validation_test.go +++ b/pkg/apis/serving/v1/revision_validation_test.go @@ -866,7 +866,7 @@ func TestRevisionTemplateSpecValidation(t *testing.T) { }, }, }, - want: apis.ErrInvalidValue("not a DNS 1035 label: [a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')]", + want: apis.ErrInvalidValue("not a DNS label: [a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')]", "metadata.name"), }, { name: "invalid generate name for revision template", @@ -883,7 +883,7 @@ func TestRevisionTemplateSpecValidation(t *testing.T) { }, }, }, - want: apis.ErrInvalidValue("not a DNS 1035 label prefix: [a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')]", + want: apis.ErrInvalidValue("not a DNS label prefix: [a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')]", "metadata.generateName"), }, { name: "invalid metadata.annotations for scale", @@ -1225,12 +1225,12 @@ func TestValidateRevisionName(t *testing.T) { }{{ name: "invalid revision generateName - dots", revGenerateName: "foo.bar", - expectErr: apis.ErrInvalidValue("not a DNS 1035 label prefix: [a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')]", + expectErr: apis.ErrInvalidValue("not a DNS label prefix: [must not contain dots]", "metadata.generateName"), }, { name: "invalid revision name - dots", revName: "foo.bar", - expectErr: apis.ErrInvalidValue("not a DNS 1035 label: [a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')]", + expectErr: apis.ErrInvalidValue("not a DNS label: [must not contain dots]", "metadata.name"), }, { name: "invalid name (not prefixed)",