Skip to content

Commit

Permalink
Fix review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
savitaashture committed Aug 13, 2019
1 parent 3ce9563 commit 72eb1c3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 52 deletions.
20 changes: 8 additions & 12 deletions pkg/apis/serving/metadata_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,17 @@ func ValidateTimeoutSeconds(ctx context.Context, timeoutSeconds int64) *apis.Fie
// ValidateRevisionName validates name and generateName for the revisionTemplate
func ValidateRevisionName(ctx context.Context, name, generateName string) *apis.FieldError {
if generateName != "" {
msgs := validation.NameIsDNS1035Label(generateName, true)
if len(msgs) > 0 {
return &apis.FieldError{
Message: fmt.Sprintf("not a DNS 1035 label prefix: %v", msgs),
Paths: []string{"metadata.generateName"},
}
if msgs := validation.NameIsDNS1035Label(generateName, true); len(msgs) > 0 {
return apis.ErrInvalidValue(
fmt.Sprintf("not a DNS 1035 label prefix: %v", msgs),
"metadata.generateName")
}
}
if name != "" {
msgs := validation.NameIsDNS1035Label(name, false)
if len(msgs) > 0 {
return &apis.FieldError{
Message: fmt.Sprintf("not a DNS 1035 label: %v", msgs),
Paths: []string{"metadata.name"},
}
if msgs := validation.NameIsDNS1035Label(name, false); len(msgs) > 0 {
return apis.ErrInvalidValue(
fmt.Sprintf("not a DNS 1035 label: %v", msgs),
"metadata.name")
}
om := apis.ParentMeta(ctx)
prefix := om.Name + "-"
Expand Down
12 changes: 4 additions & 8 deletions pkg/apis/serving/metadata_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,13 @@ func TestValidateRevisionName(t *testing.T) {
}{{
name: "invalid revision generateName - dots",
revGenerateName: "foo.bar",
expectErr: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"metadata.generateName"},
},
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])?')]",
"metadata.generateName"),
}, {
name: "invalid revision name - dots",
revName: "foo.bar",
expectErr: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"metadata.name"},
},
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])?')]",
"metadata.name"),
}, {
name: "invalid name (not prefixed)",
objectMeta: metav1.ObjectMeta{
Expand Down
12 changes: 4 additions & 8 deletions pkg/apis/serving/v1alpha1/configuration_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,8 @@ func TestConfigurationValidation(t *testing.T) {
},
},
},
want: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"spec.revisionTemplate.metadata.name"},
},
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])?')]",
"spec.revisionTemplate.metadata.name"),
}, {
name: "invalid generate name for configuration spec",
c: &Configuration{
Expand All @@ -371,10 +369,8 @@ func TestConfigurationValidation(t *testing.T) {
},
},
},
want: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"spec.revisionTemplate.metadata.generateName"},
},
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])?')]",
"spec.revisionTemplate.metadata.generateName"),
}}

for _, test := range tests {
Expand Down
12 changes: 4 additions & 8 deletions pkg/apis/serving/v1alpha1/revision_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,8 @@ func TestRevisionTemplateSpecValidation(t *testing.T) {
},
},
},
want: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"metadata.name"},
},
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])?')]",
"metadata.name"),
}, {
name: "invalid generate name for revision template",
rts: &RevisionTemplateSpec{
Expand All @@ -370,10 +368,8 @@ func TestRevisionTemplateSpecValidation(t *testing.T) {
},
},
},
want: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"metadata.generateName"},
},
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])?')]",
"metadata.generateName"),
}, {
name: "Queue sidecar resource percentage annotation more than 100",
rts: &RevisionTemplateSpec{
Expand Down
12 changes: 4 additions & 8 deletions pkg/apis/serving/v1beta1/configuration_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ func TestConfigurationValidation(t *testing.T) {
},
},
},
want: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"spec.template.metadata.name"},
},
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])?')]",
"spec.template.metadata.name"),
}, {
name: "invalid generate name for configuration spec",
c: &Configuration{
Expand All @@ -213,10 +211,8 @@ func TestConfigurationValidation(t *testing.T) {
},
},
},
want: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"spec.template.metadata.generateName"},
},
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])?')]",
"spec.template.metadata.generateName"),
}}

// TODO(dangerd): PodSpec validation failures.
Expand Down
12 changes: 4 additions & 8 deletions pkg/apis/serving/v1beta1/revision_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,8 @@ func TestRevisionTemplateSpecValidation(t *testing.T) {
},
},
},
want: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"metadata.name"},
},
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])?')]",
"metadata.name"),
}, {
name: "invalid generate name for revision template",
rts: &RevisionTemplateSpec{
Expand All @@ -829,10 +827,8 @@ func TestRevisionTemplateSpecValidation(t *testing.T) {
},
},
},
want: &apis.FieldError{
Message: "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])?')]",
Paths: []string{"metadata.generateName"},
},
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])?')]",
"metadata.generateName"),
}, {
name: "invalid metadata.annotations for scale",
rts: &RevisionTemplateSpec{
Expand Down

0 comments on commit 72eb1c3

Please sign in to comment.