What did you do?
Tried to run e2e tests on memcached sample operator.
project/namespace character limit which is 63 charactersoperator-sdk test local ./test/e2e --image quay.io/pratikjagrut/memcached-operator:v0.0.2 --verboseWhat did you expect to see?
SDK to handle exceeded namespace character limit and tests to pass.
What did you see instead? Under which circumstances?
Fails with the following error.
DEBU[0000] Debug logging is set
INFO[0000] Testing operator locally.
DEBU[0000] Running []string{"go", "test", "./test/e2e/...", "-namespacedMan", "/tmp/namespaced-manifest.yaml605350766", "-globalMan", "/tmp/global-manifest.yaml069236213", "-root", "/home/pjagrut/go/src/github.com/operator-framework/operator-sdk-samples/memcached-operator"}
=== RUN TestMemcached
=== RUN TestMemcached/memcached-group
=== RUN TestMemcached/memcached-group/Cluster-memcached-memcached-group-cluster
=== PAUSE TestMemcached/memcached-group/Cluster-memcached-memcached-group-cluster
=== CONT TestMemcached/memcached-group/Cluster-memcached-memcached-group-cluster
--- FAIL: TestMemcached (27.18s)
--- FAIL: TestMemcached/memcached-group (0.00s)
--- FAIL: TestMemcached/memcached-group/Cluster-memcached-memcached-group-cluster (0.31s)
memcached_test.go:98: failed to initialize cluster resources: Namespace "memcached-memcached-group-cluster-memcached-memcached-group-cluster-1571914599" is invalid: metadata.name: Invalid value: "memcached-memcached-group-cluster-memcached-memcached-group-cluster-1571914599": must be no more than 63 characters
FAIL
FAIL github.com/operator-framework/operator-sdk-samples/memcached-operator/test/e2e 54.554s
Error: failed to build test binary: (failed to exec []string{"go", "test", "./test/e2e/...", "-namespacedMan", "/tmp/namespaced-manifest.yaml605350766", "-globalMan", "/tmp/global-manifest.yaml069236213", "-root", "/home/pjagrut/go/src/github.com/operator-framework/operator-sdk-samples/memcached-operator"}: exit status 1)
Usage:
operator-sdk test local <path to tests directory> [flags]
Flags:
--debug Enable debug-level logging
--global-manifest string Path to manifest for Global resources (e.g. CRD manifests)
--go-test-flags string Additional flags to pass to go test
-h, --help help for local
--image string Use a different operator image from the one specified in the namespaced manifest
--kubeconfig string Kubeconfig path
--local-operator-flags string The flags that the operator needs (while using --up-local). Example: "--flag1 value1 --flag2=value2"
--molecule-test-flags string Additional flags to pass to molecule test
--namespace string If non-empty, single namespace to run tests in
--namespaced-manifest string Path to manifest for per-test, namespaced resources (e.g. RBAC and Operator manifest)
--no-setup Disable test resource creation
--up-local Enable running operator locally with go run instead of as an image in the cluster
Global Flags:
--verbose Enable verbose logging
Environment
v0.10.0-117-gc7f429f0", commit: "c7f429f05808406068b1a67f49b0de9e6481f545go1.12.9 linux/amd64Client Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.0+d4cacc0", GitCommit:"d4cacc0", GitTreeState:"clean", BuildDate:"2018-12-06T15:15:06Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.0-beta.2+03b33d2", GitCommit:"03b33d2", GitTreeState:"clean", BuildDate:"2019-10-21T19:38:32Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
Possible Solution
Seems like SDK appends operator name, test-group name and test name to create the namespace without taking care of the length of the final string.
We should check the char length of the final string before creating the namespace.
If it exceeds then should cut it down to less than 63 chars or else it is good to go.
Hi @AlexNPavel,
I understand that the namespace is mandatory. Am I right? If yes, maybe the solution could not allow the command to go forward without it? Or should it work without that namespace flag? If yes, what about we just use the operator-name + randon numbers trunc (see the msg below)? WDYT?
@camilamacedo86 What I noticed is if we do not provide namespace SDK creates one by appending test-group name, test name, operator name and around 10 digits random number. So I don't see why --namespace should be compulsory if not using --up-local?
The reason the SDK creates namespaces with that form (group-test-timestamp) is to prevent namespace conflicts when running tests in parallel. If the namespace name is too long, I assume we could truncate the name, but then we might have namespace conflicts. The test framework errors if it tries to create a namespace that already exists, so maybe it would be fine to try and truncate the namespace's name before trying to create it and make the error message for the namespace conflicts a bit clearer.
@joelanford What are your thoughts on this?
I think the best bet would be to change the code to always use a consistent and known length for the namespace name (e.g. osdk-e2e-<54-or-less-random-alphanum-chars>)
Hi @pratikjagrut,
Now, you have your answers if you still wishing to collab with a PR with the fix I think you can do as @joelanford suggest.
HI @camilamacedo86,
Thanx, I'll raise PR ASAP.
Most helpful comment
HI @camilamacedo86,
Thanx, I'll raise PR ASAP.