Skip to content
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

Merged
merged 6 commits into from
Nov 11, 2019

Conversation

savitaashture
Copy link
Contributor

Fixes #5094

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 9, 2019
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 9, 2019
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a 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.

pkg/apis/serving/metadata_validation.go Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 9, 2019
@knative-prow-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@knative-prow-robot knative-prow-robot added the area/API API objects and controllers label Aug 9, 2019
@savitaashture savitaashture force-pushed the issue-5094 branch 2 times, most recently from 4a94098 to 3bd86ee Compare August 9, 2019 06:35
Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay in general, though I'm not the right person to review API nuances. The additional generateName stuff makes me wonder though if we even accept that today?

/assign @mattmoor @dgerd


// ValidateRevisionName validates name and generateName for the revisionTemplate
func ValidateRevisionName(ctx context.Context, name, generateName string) *apis.FieldError {
if generateName != "" {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@markusthoemmes
Copy link
Contributor

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 9, 2019
// 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if msg :=. ...; msg != "" {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. type of msgs is []string so we cannot do msgs != ""
  2. Added if condition as per suggestion

if generateName != "" {
msgs := validation.NameIsDNS1035Label(generateName, true)
if len(msgs) > 0 {
return &apis.FieldError{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errinvalidvalue?

@mattmoor mattmoor added area/API API objects and controllers and removed area/API API objects and controllers labels Aug 9, 2019
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",
Copy link
Contributor

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?

Copy link
Contributor Author

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",
Copy link
Contributor

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?

Copy link
Contributor Author

@savitaashture savitaashture Aug 21, 2019

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

@mattmoor mattmoor removed their assignment Aug 13, 2019
@savitaashture savitaashture force-pushed the issue-5094 branch 2 times, most recently from 49d6dd7 to 6c7a439 Compare August 26, 2019 07:58
@savitaashture
Copy link
Contributor Author

savitaashture commented Sep 6, 2019

@dgerd this PR is ready for another review. Would you please take a look?

@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 18, 2019
@knative-test-reporter-robot

The following jobs failed due to test flakiness:

Test name Triggers Retries
pull-knative-serving-unit-tests 0/3

Failed non-flaky tests preventing automatic retry of pull-knative-serving-unit-tests:

pkg/apis/serving/v1.TestConfigurationValidation
pkg/apis/serving/v1.TestConfigurationValidation/valid_BYO_name_(with_generateName)

@dgerd
Copy link

dgerd commented Oct 23, 2019

@savitaashture Can you rebase this and I will take a look? This would be good to land in 0.10.x

@savitaashture
Copy link
Contributor Author

@dgerd Rebased
Please have a look :)

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/serving/metadata_validation.go 97.6% 98.2% 0.6
pkg/apis/serving/v1/revision_validation.go 95.2% 94.4% -0.8
pkg/apis/serving/v1alpha1/revision_validation.go 91.4% 96.1% 4.7

@dgerd
Copy link

dgerd commented Oct 28, 2019

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 28, 2019
@knative-prow-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 28, 2019
@markusthoemmes
Copy link
Contributor

/test pull-knative-serving-build-tests

1 similar comment
@markusthoemmes
Copy link
Contributor

/test pull-knative-serving-build-tests

@savitaashture
Copy link
Contributor Author

/retest

@knative-prow-robot knative-prow-robot merged commit 2a1f3b9 into knative:master Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid revision names are accepted in the revision template
10 participants