-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add changes to validate name and generateName for revision template #5110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
37806f3
7f83cf8
ae41cc7
c4d7ccd
2b4c297
8ccdcae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,12 @@ package serving | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "k8s.io/apimachinery/pkg/api/equality" | ||
| "k8s.io/apimachinery/pkg/api/validation" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "knative.dev/pkg/apis" | ||
| "knative.dev/serving/pkg/apis/autoscaling" | ||
|
|
@@ -132,3 +134,38 @@ func SetUserInfo(ctx context.Context, oldSpec, newSpec, resource interface{}) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| // ValidateRevisionName validates name and generateName for the revisionTemplate | ||
| func ValidateRevisionName(ctx context.Context, name, generateName string) *apis.FieldError { | ||
| if generateName != "" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we allow to use generateName before?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we provide valid or invalid But if at all user give invalid user will not be notified and service will be created successfully by overriding
To just to make sure i have added condition check. |
||
| 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 != "" { | ||
| 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 + "-" | ||
| if om.Name != "" { | ||
| // Even if there is GenerateName, allow the use | ||
| // of Name post-creation. | ||
| } else if om.GenerateName != "" { | ||
| // We disallow bringing your own name when the parent | ||
| // resource uses generateName (at creation). | ||
| return apis.ErrDisallowedFields("metadata.name") | ||
| } | ||
|
|
||
| if !strings.HasPrefix(name, prefix) { | ||
| return apis.ErrInvalidValue( | ||
| fmt.Sprintf("%q must have prefix %q", name, prefix), | ||
| "metadata.name") | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.