-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add changes to validate name and generateName for revision template #5110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@savitaashture: 1 warning.
In response to this:
Fixes #5094
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Hi @savitaashture. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
4a94098
to
3bd86ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
// ValidateRevisionName validates name and generateName for the revisionTemplate | ||
func ValidateRevisionName(ctx context.Context, name, generateName string) *apis.FieldError { | ||
if generateName != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we allow to use generateName before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we provide valid or invalid generateName
in service spec it will override in the generateName
when it creates revision
But if at all user give invalid generateName
something like below
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: "hello"
spec:
template:
metadata:
generateName: hi@
spec:
containers:
- image: savita3020/helloworld
user will not be notified and service will be created successfully by overriding generateName
in revision as shown below
kubectl get rev -n test hello-kphn8 -o yaml
apiVersion: serving.knative.dev/v1alpha1
kind: Revision
metadata:
annotations:
serving.knative.dev/creator: kube:admin
serving.knative.dev/lastPinned: "1565333856"
creationTimestamp: "2019-08-09T06:57:24Z"
generateName: hello-
generation: 1
labels:
serving.knative.dev/configuration: hello
serving.knative.dev/configurationGeneration: "1"
serving.knative.dev/route: hello
serving.knative.dev/service: hello
name: hello-kphn8
To just to make sure i have added condition check.
/ok-to-test |
// 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if msg :=. ...; msg != "" {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- type of
msgs
is[]string
so we cannot domsgs != ""
- Added if condition as per suggestion
if generateName != "" { | ||
msgs := validation.NameIsDNS1035Label(generateName, true) | ||
if len(msgs) > 0 { | ||
return &apis.FieldError{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errinvalidvalue?
3bd86ee
to
99a478f
Compare
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a valid generate name test case here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Can we add a valid generate name test case here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taragu In revision even if user provide generate name in spec it will be overriden so just added testcase for invalid generate name
99a478f
to
f708b21
Compare
49d6dd7
to
6c7a439
Compare
6c7a439
to
c868670
Compare
@dgerd this PR is ready for another review. Would you please take a look? |
76386a2
to
e8dbbfb
Compare
The following jobs failed due to test flakiness:
Failed non-flaky tests preventing automatic retry of pull-knative-serving-unit-tests:
|
e8dbbfb
to
e5aa699
Compare
@savitaashture Can you rebase this and I will take a look? This would be good to land in 0.10.x |
e5aa699
to
8ccdcae
Compare
@dgerd Rebased |
The following is the coverage report on the affected files.
|
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dgerd, savitaashture The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test pull-knative-serving-build-tests |
1 similar comment
/test pull-knative-serving-build-tests |
/retest |
Fixes #5094