Skip to content

Commit

Permalink
pkg/test/context.go: create an id that is a valid namespace name.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dustinspecker committed Dec 13, 2019
1 parent 8adf8db commit dd1cdd8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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))


## v0.13.0
Expand Down
22 changes: 3 additions & 19 deletions pkg/test/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
package test

import (
"strconv"
"strings"
"testing"
"time"

"github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/restmapper"
Expand Down Expand Up @@ -48,23 +47,8 @@ type CleanupOptions struct {
type cleanupFn func() error

func (f *Framework) newTestCtx(t *testing.T) *TestCtx {
var prefix string
if t != nil {
// TestCtx is used among others for namespace names where '/' is forbidden
prefix = strings.TrimPrefix(
strings.Replace(
strings.ToLower(t.Name()),
"/",
"-",
-1,
),
"test",
)
} else {
prefix = "main"
}

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()

var namespace string
if f.singleNamespaceMode {
Expand Down
2 changes: 2 additions & 0 deletions test/test-framework/deploy/namespace-init.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ roleRef:
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
name: memcached-operator
spec:
replicas: 1
Expand All @@ -74,6 +75,7 @@ spec:
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
name: memcached-operator
spec:
Expand Down
1 change: 1 addition & 0 deletions test/test-framework/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJ
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776/go.mod h1:3HNVkVOU7vZeFXocWuvtcS0XSFLcf2XUSDHkq9t1jU4=
github.com/otiai10/mint v1.2.3/go.mod h1:YnfyPNhBvnY8bW4SGQHCs/aAFhkgySlMZbrF5U0bOVw=
github.com/otiai10/mint v1.2.4/go.mod h1:d+b7n/0R3tdyUYYylALXpWQ/kTN+QobSq/4SRGBkR3M=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
4 changes: 2 additions & 2 deletions test/test-framework/test/e2e/memcached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
t.Run("AVeryLongClusterNameThatIsSoLong2", MemcachedCluster)
})
}

Expand Down

0 comments on commit dd1cdd8

Please sign in to comment.