Skip to content

Commit

Permalink
Correct the namespace creation for e2e tests (#1806)
Browse files Browse the repository at this point in the history
  • Loading branch information
johscheuer authored Sep 19, 2023
1 parent 7adaed8 commit 783e8ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion e2e/fixtures/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func (config *ClusterConfig) SetDefaults(factory *Factory) {
config.Name = factory.getClusterPrefix()
}

if config.Namespace == "" {
// Only create the namespace for non HA clusters, otherwise the namespaces will be created in a different way.
if config.Namespace == "" && config.HaMode == HaModeNone {
config.Namespace = factory.SingleNamespace()
}

Expand Down
12 changes: 10 additions & 2 deletions e2e/fixtures/kubernetes_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ const (
namespaceRegEx = `^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
)

// factory.getRandomizedNamespaceName() checks if the username is valid to be used in the namespace name. If so this
// method will return the namespace name as the username a hyphen and 8 random chars.
func (factory *Factory) getRandomizedNamespaceName() string {
gomega.Expect(factory.singleton.userName).To(gomega.MatchRegexp(namespaceRegEx), "user name contains invalid characters")
return factory.singleton.userName + "-" + RandStringRunes(8)
}

// MultipleNamespaces creates multiple namespaces for HA testing.
func (factory *Factory) MultipleNamespaces(dcIDs []string) []string {
factory.options.namespace = factory.getRandomizedNamespaceName()

res := make([]string, len(dcIDs))
for idx, dcID := range dcIDs {
namespace := factory.createNamespace(dcID)
Expand Down Expand Up @@ -71,8 +80,7 @@ func (factory *Factory) createNamespace(suffix string) string {
namespace := factory.options.namespace

if namespace == "" {
gomega.Expect(factory.singleton.userName).To(gomega.MatchRegexp(namespaceRegEx), "user name contains invalid characters")
namespace = factory.singleton.userName + "-" + RandStringRunes(8)
namespace = factory.getRandomizedNamespaceName()
}

if suffix != "" {
Expand Down

0 comments on commit 783e8ad

Please sign in to comment.