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

pkg/test/context.go: create an id that is a valid namespace name #2335

Merged

Conversation

dustinspecker
Copy link
Contributor

@dustinspecker dustinspecker commented Dec 13, 2019

Before this change it was possible for TestCtx.GetNamespace() to create a
namespace with too long of a name, thus getting an error from Kubernetes
saying the namespace name exceeded 63 characters.

Now set the id to "osdk-e2e-UUID", so that TestCtx.GetNamespace() is
guaranteed to have a namespace name be 63 characters or less, which is a
valid namespace name.

Fixes #2101

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 13, 2019
@@ -34,7 +35,7 @@ func (ctx *TestCtx) GetNamespace() (string, error) {
return ctx.namespace, nil
}
// create namespace
ctx.namespace = ctx.GetID()
ctx.namespace = fmt.Sprintf("osdk-e2e-%s", uuid.New())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to investigate adding unit tests around GetNamespace this weekend. Need to figure how to handle testing code using UUID. Attach a UUID on TestCtx? Maybe change GetID() to return this UUID on TestCtx instead of creating the UUID 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.

Taking a second look at this: I think assigning ctx.id in newTestCtx to the above string would make this all easier. So instead of changing resource_creator modify pkg/test/context.go's newTestCtx.

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 13, 2019
@dustinspecker dustinspecker changed the title pkg/test/resource_creator: prevent creating too long of namespace name pkg/test/context.go: create an id that is a valid namespace name. Dec 13, 2019

id := prefix + "-" + strconv.FormatInt(time.Now().Unix(), 10)
// TestCtx is used among others for namespace names where '/' is forbidden and must be 63 characters or less
id := "osdk-e2e-" + uuid.New()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this approach much better than my previous code change. This weekend I'd still like to add unit tests around NewTestCtx, but please let me know thoughts on this approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is ok for me. @joelanford have you any objection?

@dustinspecker dustinspecker changed the title pkg/test/context.go: create an id that is a valid namespace name. pkg/test/context.go: create an id that is a valid namespace name Dec 13, 2019
@dustinspecker dustinspecker force-pushed the fix-namespace-creation branch 3 times, most recently from ed51bc6 to 6938a11 Compare December 19, 2019 12:03
}

id := prefix + "-" + strconv.FormatInt(time.Now().Unix(), 10)
// TestCtx is used among others for namespace names where '/' is forbidden and must be 63 characters or less
Copy link
Contributor

Choose a reason for hiding this comment

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

@joelanford wdyt? Are you ok with?
For me, it shows fine.

CHANGELOG.md Outdated
@@ -25,6 +25,7 @@

### Bug Fixes
- Fix `operator-sdk build`'s `--image-build-args` to support spaces within quotes like `--label some.name="First Last"`. ([#2312](https://github.com/operator-framework/operator-sdk/pull/2312))
- Fix `pkg/test/NewTestCtx()` to always create an id that is a valid namespace name. This prevents `TestCtx.GetNamespace()` from attempting to sometimes erroneously creating a namespace with a name exceeding 63 characters. ([#2335](https://github.com/operator-framework/operator-sdk/pull/2335))
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT?

Suggested change
- Fix `pkg/test/NewTestCtx()` to always create an id that is a valid namespace name. This prevents `TestCtx.GetNamespace()` from attempting to sometimes erroneously creating a namespace with a name exceeding 63 characters. ([#2335](https://github.com/operator-framework/operator-sdk/pull/2335))
- Fix issue to use from test-framework which is faced when the created namespace is exceeding 63 characters. The `TestCtx.GetNamespace()` was changed to always create a unique ID instead of using the operator name in order to avoid this scenario. ([#2335](https://github.com/operator-framework/operator-sdk/pull/2335))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion! I made a couple additional modifications to the proposed change. Please let me know what you think.

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Hi @dustinspecker,

Really tks for your contribution. It shows OK for me. Just a nit in the CHANGELOG.
Also, please could you rebase it with the master branch?

@camilamacedo86 camilamacedo86 added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 8, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 9, 2020
@@ -45,8 +45,8 @@ func TestMemcached(t *testing.T) {
}
// run subtests
t.Run("memcached-group", func(t *testing.T) {
t.Run("Cluster", MemcachedCluster)
t.Run("Cluster2", MemcachedCluster)
t.Run("AVeryLongClusterNameThatIsSoLong", MemcachedCluster)
Copy link
Member

Choose a reason for hiding this comment

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

Why are these names changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think he tried to demonstrate that the issue was solved.
However, I agree with @estroz. I would stick with the previous names either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's why I did it. Before this change that test would fail. I'll change it back.

Before this change it was possible for `TestCtx.GetNamespace()` to create a
namespace with too long of a name, thus getting an error from Kubernetes
saying the namespace name exceeded 63 characters.

Now set the id to "osdk-e2e-UUID", so that `TestCtx.GetNamespace()` is
guaranteed to have a namespace name be 63 characters or less, which is a
valid namespace name.

Fixes operator-framework#2101
Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

It shows ok for me
/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 16, 2020
Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@estroz estroz merged commit ab62973 into operator-framework:master Jan 17, 2020
@dustinspecker dustinspecker deleted the fix-namespace-creation branch January 17, 2020 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Operator-sdk's test-framework fails to initialize cluster resource: Namespace
4 participants