Skip to content

Commit b9566b4

Browse files
authored
Allow to specify a cluster name in test suite (#1946)
* Allow to specify a cluster name in test suite * Add docs for reusing a test cluster
1 parent 0eb4361 commit b9566b4

File tree

7 files changed

+37
-24
lines changed

7 files changed

+37
-24
lines changed

e2e/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ compile:
77
# INPUT ENVIRONMENT VARIABLES
88
TIMEOUT?=168h
99

10+
CLUSTER_NAME?=
1011
NAMESPACE?=
11-
PREFIX?=
1212
CONTEXT?=
1313
FDB_VERSION?=7.1.53
1414
# This will be the version used for upgrade tests.
@@ -111,7 +111,6 @@ nightly-tests: run
111111
--ginkgo.timeout=$(TIMEOUT) \
112112
--timeout=$(TIMEOUT) \
113113
--namespace="$(NAMESPACE)" \
114-
--prefix="$(PREFIX)" \
115114
--context="$(CONTEXT)" \
116115
--fdb-image="$(FDB_IMAGE)" \
117116
--sidecar-image="$(SIDECAR_IMAGE)" \
@@ -129,4 +128,5 @@ nightly-tests: run
129128
--feature-dns=$(FEATURE_DNS) \
130129
--cloud-provider=$(CLOUD_PROVIDER) \
131130
--dump-operator-state=$(DUMP_OPERATOR_STATE) \
131+
--cluster-name=$(CLUSTER_NAME) \
132132
| grep -v 'constructing many client instances from the same exec auth config can cause performance problems during cert rotation' &> $(BASE_DIR)/../logs/$<.log

e2e/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ make -C e2e test_operator.run
1919

2020
Every test suite will create at least one namespace, HA cluster tests will create all the required namespaces.
2121

22+
### Reusing an existing test cluster
23+
24+
A test cluster can be reused if wanted, e.g. for test cases that load a large amount of data into the cluster.
25+
This requires to specify the `CLUSTER_NAME` and the `NAMESPACE`, if those values are not specified the test suite will use randomized values.
26+
** NOTE ** The limitation of this approach is that the test suite will not update the existing `FoundationDBCluster` in the creation step.
27+
So if you're modifying the `FoundationDBCluster` spec, you have to recreate the cluster.
28+
29+
```bash
30+
CLEANUP=false CLUSTER_NAME=dev-cluster-1 NAMESPACE=dev make -kj -C e2e run
31+
```
32+
2233
### StorageClass selection
2334

2435
The e2e tests assume that at least one `StorageClass` is present in the target Kubernetes cluster.

e2e/fixtures/cluster_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func DefaultClusterConfig(debugSymbols bool) *ClusterConfig {
125125
// SetDefaults will set all unset fields to the default values.
126126
func (config *ClusterConfig) SetDefaults(factory *Factory) {
127127
if config.Name == "" {
128-
config.Name = factory.getClusterPrefix()
128+
config.Name = factory.getClusterName()
129129
}
130130

131131
// Only create the namespace for non HA clusters, otherwise the namespaces will be created in a different way.

e2e/fixtures/factory.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ func (factory *Factory) getContainerOverrides(
254254
return mainOverrides, sidecarOverrides
255255
}
256256

257-
func (factory *Factory) getClusterPrefix() string {
258-
prefix := factory.options.prefix
259-
if prefix == "" {
257+
func (factory *Factory) getClusterName() string {
258+
if factory.options.clusterName == "" {
260259
return fmt.Sprintf("fdb-cluster-%s", RandStringRunes(8))
261260
}
262-
return prefix
261+
262+
return factory.options.clusterName
263263
}
264264

265265
// GetDefaultStorageClass returns either the StorageClass provided by the command line or fetches the StorageClass passed on

e2e/fixtures/fdb_operator_fixtures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (factory *Factory) ensureHAFdbClusterExists(
151151
options []ClusterOption,
152152
) (*HaFdbCluster, error) {
153153
fdb := &HaFdbCluster{}
154-
clusterPrefix := factory.getClusterPrefix()
154+
clusterPrefix := factory.getClusterName()
155155

156156
databaseConfiguration := config.CreateDatabaseConfiguration()
157157
dcIDs := GetDcIDsFromConfig(databaseConfiguration)

e2e/fixtures/options.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
type FactoryOptions struct {
3434
namespace string
3535
chaosNamespace string
36-
prefix string
3736
context string
3837
fdbImage string // TODO (johscheuer): Make this optional if we use the default
3938
sidecarImage string // TODO (johscheuer): Make this optional if we use the default
@@ -45,6 +44,7 @@ type FactoryOptions struct {
4544
storageClass string
4645
upgradeString string
4746
cloudProvider string
47+
clusterName string
4848
enableChaosTests bool
4949
enableDataLoading bool
5050
cleanup bool
@@ -69,12 +69,6 @@ func (options *FactoryOptions) BindFlags(fs *flag.FlagSet) {
6969
"",
7070
"defines the chaos namespace to run experiments (will be created if missing)",
7171
)
72-
fs.StringVar(
73-
&options.prefix,
74-
"prefix",
75-
"",
76-
"defines the prefix of fdb cluster to run the test (will be created if missing)",
77-
)
7872
fs.StringVar(
7973
&options.context,
8074
"context",
@@ -183,6 +177,11 @@ func (options *FactoryOptions) BindFlags(fs *flag.FlagSet) {
183177
true,
184178
"defines if the operator tests should print the state of the cluster and the according Pods for better debugging.",
185179
)
180+
fs.StringVar(&options.clusterName,
181+
"cluster-name",
182+
"",
183+
"if defined, the test suite will create a cluster with the specified name or update the setting of an existing cluster."+
184+
"For multi-region clusters, this will define the prefix for all clusters.")
186185
}
187186

188187
func (options *FactoryOptions) validateFlags() error {

e2e/fixtures/status.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,19 @@ func (fdbCluster *FdbCluster) RunFdbCliCommandInOperatorWithoutRetry(
152152
break
153153
}
154154

155-
var parsedStatus *fdbv1beta2.FoundationDBStatus
156-
parsedStatus, err = parseStatusOutput(stdout)
157-
// If we cannot parse the status we probably have an error or timeout
158-
if err != nil {
159-
continue
160-
}
155+
// Only try to parse the content to json if the command was "status json".
156+
if strings.Contains(command, "status json") {
157+
var parsedStatus *fdbv1beta2.FoundationDBStatus
158+
parsedStatus, err = parseStatusOutput(stdout)
159+
// If we cannot parse the status we probably have an error or timeout
160+
if err != nil {
161+
continue
162+
}
161163

162-
// Quorum of coordinators are available, so we probably use the correct version
163-
if parsedStatus.Client.Coordinators.QuorumReachable {
164-
break
164+
// Quorum of coordinators are available, so we probably use the correct version
165+
if parsedStatus.Client.Coordinators.QuorumReachable {
166+
break
167+
}
165168
}
166169
}
167170

0 commit comments

Comments
 (0)