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 conformance tests for .metadata.generateName. #3292

Merged

Conversation

brandon-mabey
Copy link
Contributor

Fixes #3183

Proposed Changes

  • Add testing to ensure that .metadata.generateName can be used instead of .metadata.name to specify names for services, routes, and configurations.

Release Note

NONE

@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 20, 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.

@brandon-mabey: 0 warnings.

In response to this:

Fixes #3183

Proposed Changes

  • Add testing to ensure that .metadata.generateName can be used instead of .metadata.name to specify names for services, routes, and configurations.

Release Note

NONE

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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 20, 2019
test/conformance/generatename_test.go Outdated Show resolved Hide resolved
test/conformance/generatename_test.go Outdated Show resolved Hide resolved
test/conformance/generatename_test.go Outdated Show resolved Hide resolved
test/conformance/generatename_test.go Outdated Show resolved Hide resolved
test/conformance/generatename_test.go Outdated Show resolved Hide resolved
test/conformance/generatename_test.go Outdated Show resolved Hide resolved

// Ensure that the name given to the configuration is generated from the generate name field.
t.Log("When the configuration is created, the name is generated using the provided generateName")
if names.Config == generateName {
Copy link

Choose a reason for hiding this comment

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

These statements could probably be refactored out to a common function for Service, Config, and Route to reduce duplication (i.e. validateName(prefix, name string) error . A regex also might be both simpler and capture more requirements as to what we expect from generate name such as:

  1. What characters should follow the prefix?
  2. How long should the generated name be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to validateName, and changed it to a regex. It now validates that the prefix is followed by 5 lower-case characters or digits, which is what the current behaviour is.

It might be a bit overly strict since it now depends on the api-server implementation not changing. I believe Kubernetes only guarantees a unique suffix (https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#idempotency). Is this updated regex okay?

Copy link

Choose a reason for hiding this comment

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

I would loosen it up a bit to be prefix followed by one or more valid name characters ( https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, loosed up the regex and changed it. Thanks.

}

// generateNamePrefix returns the object name to be used for testing, shorted to
// 44 characters to avoid #3236, as generateNames longer than 44 characters may cause
Copy link

Choose a reason for hiding this comment

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

The issue referenced seems to indicate 49 characters. I assume the text here then is expecting 5 additional from the generateName randomness?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is exactly it. 49 characters will work with a service with .metadata.name set but not .metadata.generateName set.

@bradhoekstra
Copy link
Contributor

/ok-to-test

@knative-prow-robot knative-prow-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 27, 2019
@mattmoor mattmoor self-assigned this Mar 19, 2019
@mattmoor mattmoor added this to the Serving 0.5 milestone Mar 19, 2019
@mattmoor
Copy link
Member

@brandon-mabey Can you rebase this?

@knative-prow-robot knative-prow-robot added the area/test-and-release It flags unit/e2e/conformance/perf test issues for product features label Mar 19, 2019
@mattmoor mattmoor assigned dgerd and unassigned mattmoor Mar 19, 2019
@brandon-mabey
Copy link
Contributor Author

@mattmoor Done. Rebased merge conflict.

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

superficial

r := regexp.MustCompile("^" + regexp.QuoteMeta(generateName) + "[a-zA-Z0-9\\-.]+$")

if !r.MatchString(name) {
return fmt.Errorf("expected generated name to match \"%v\", got %s", r, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. got before want e.g "generated name = %q want to match %q".
  2. use: https://golang.org/pkg/regexp/#Regexp.String and %q as format qualifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, also edited another instance of "%s" below. Thanks.

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 19, 2019
@dgerd
Copy link

dgerd commented Mar 19, 2019

/lgtm

@mattmoor
Copy link
Member

/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brandon-mabey, mattmoor, vagababov

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 Mar 19, 2019
@knative-prow-robot knative-prow-robot merged commit c91121a into knative:master Mar 19, 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/test-and-release It flags unit/e2e/conformance/perf test issues for product features lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants