Skip to content

Commit 85ba911

Browse files
author
Moritz Clasmeier
committed
Introduce --skip-user-config flag, allowing e2e tests to ignore the current user's config
1 parent db537a7 commit 85ba911

8 files changed

Lines changed: 30 additions & 14 deletions

File tree

cmd/deploy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,10 @@ func runDeploy(cmd *cobra.Command, args []string) error {
267267
deploySettings := deployer.DefaultConfig()
268268

269269
// Apply user config on top (overriding defaults).
270-
if err := tryApplyUserDefaults(globalLogger, &deploySettings); err != nil {
271-
return fmt.Errorf("applying user config: %w", err)
270+
if !skipUserConfig {
271+
if err := tryApplyUserDefaults(globalLogger, &deploySettings); err != nil {
272+
return fmt.Errorf("applying user config: %w", err)
273+
}
272274
}
273275

274276
// Apply changes from arg parsing.

cmd/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ var (
2020
envrc string
2121
dryRun bool
2222

23+
skipUserConfig bool
24+
2325
globalLogger = logger.New()
2426

2527
// We need this set up before command line flags are parsed.
@@ -75,6 +77,8 @@ Red Hat Advanced Cluster Security (ACS) on any Kubernetes/OpenShift cluster.`,
7577
func init() {
7678
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output (show CRs)")
7779
rootCmd.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "Do not actually modify cluster")
80+
rootCmd.PersistentFlags().BoolVar(&skipUserConfig, "skip-user-config", false,
81+
fmt.Sprintf("Skips reading of user's configuration (%s)", paths.UserConfigPathString()))
7882
rootCmd.AddCommand(newDeployCmd(&deploySettingsFromArgs))
7983
rootCmd.AddCommand(newTeardownCmd(&deploySettingsFromArgs))
8084
rootCmd.AddCommand(newShellCmd())

cmd/teardown.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ func runTeardown(cmd *cobra.Command, args []string) error {
6060
deploySettings := deployer.DefaultConfig()
6161

6262
// Apply user config on top (overriding defaults).
63-
if err := tryApplyUserDefaults(globalLogger, &deploySettings); err != nil {
64-
return fmt.Errorf("applying user config: %w", err)
63+
if !skipUserConfig {
64+
if err := tryApplyUserDefaults(globalLogger, &deploySettings); err != nil {
65+
return fmt.Errorf("applying user config: %w", err)
66+
}
6567
}
6668

6769
// Apply changes from arg parsing.

internal/paths/paths.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ func UserConfigPath() (string, error) {
1616
return filepath.Join(dir, "config.yaml"), nil
1717
}
1818

19+
func UserConfigPathString() string {
20+
path, err := UserConfigPath()
21+
if err != nil {
22+
return "(UNAVAILABLE)"
23+
}
24+
return path
25+
}
26+
1927
func configDir() (string, error) {
2028
dir, err := os.UserConfigDir()
2129
if err != nil {

tests/e2e/basic_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestDeployBothSimple(t *testing.T) {
4646

4747
// Cleanup
4848
t.Log("=== Cleaning up ===")
49-
teardownArgs := []string{roxieBinary, "teardown", "both"}
49+
teardownArgs := []string{roxieBinary, "teardown", "--skip-user-config", "both"}
5050
runCommand(t, teardownTimeout, nil, teardownArgs...)
5151

5252
t.Log("Verifying components are removed")
@@ -90,7 +90,7 @@ func TestDetachedPortForwarding(t *testing.T) {
9090
testCentralAPI(t, endpoint, caCertFile)
9191

9292
t.Log("=== Cleaning up ===")
93-
teardownArgs := []string{roxieBinary, "teardown", "central"}
93+
teardownArgs := []string{roxieBinary, "teardown", "--skip-user-config", "central"}
9494
runCommand(t, teardownTimeout, env, teardownArgs...)
9595

9696
// Verify port-forward cleanup by checking the port is free. We can't use

tests/e2e/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestDeployBothComponentsTogetherInSingleNamespace(t *testing.T) {
5757
verifySecuredClusterInstalled(t, "stackrox")
5858

5959
t.Log("=== Tearing down both components in single namespace ===")
60-
args = []string{roxieBinary, "teardown", "--single-namespace"}
60+
args = []string{roxieBinary, "teardown", "--skip-user-config", "--single-namespace"}
6161
runCommand(t, teardownTimeout, nil, args...)
6262

6363
verifyCentralNotInstalled(t, "stackrox")

tests/e2e/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
)
3030

3131
var (
32-
commonDeployArgs = []string{"--resources=small"}
32+
commonDeployArgs = []string{"--resources=small", "--skip-user-config"}
3333

3434
roxieBinary = "roxie"
3535
)
@@ -41,7 +41,7 @@ func teardownAllDeployments() error {
4141
defer cancel()
4242

4343
// Teardown standard deployments
44-
cmd := exec.CommandContext(ctx, roxieBinary, "teardown")
44+
cmd := exec.CommandContext(ctx, roxieBinary, "teardown", "--skip-user-config")
4545
cmd.Stdout = os.Stdout
4646
cmd.Stderr = os.Stderr
4747
if err := cmd.Run(); err != nil {
@@ -51,7 +51,7 @@ func teardownAllDeployments() error {
5151
// Teardown single-namespace deployments
5252
ctx, cancel = context.WithTimeout(context.Background(), teardownTimeout)
5353
defer cancel()
54-
cmd = exec.CommandContext(ctx, roxieBinary, "teardown", "--single-namespace")
54+
cmd = exec.CommandContext(ctx, roxieBinary, "teardown", "--skip-user-config", "--single-namespace")
5555
cmd.Stdout = os.Stdout
5656
cmd.Stderr = os.Stderr
5757
if err := cmd.Run(); err != nil {

tests/e2e/olm_switch_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestOLMToNonOLMSwitch(t *testing.T) {
107107

108108
// Cleanup
109109
t.Log("=== Cleaning up ===")
110-
teardownArgs := []string{roxieBinary, "teardown", "central"}
110+
teardownArgs := []string{roxieBinary, "teardown", "--skip-user-config", "central"}
111111
runCommand(t, teardownTimeout, nil, teardownArgs...)
112112

113113
verifyCentralNotInstalled(t, "acs-central")
@@ -157,7 +157,7 @@ func TestNonOLMToOLMSwitch(t *testing.T) {
157157

158158
// Cleanup
159159
t.Log("=== Cleaning up ===")
160-
teardownArgs := []string{roxieBinary, "teardown", "central"}
160+
teardownArgs := []string{roxieBinary, "teardown", "--skip-user-config", "central"}
161161
runCommand(t, teardownTimeout, nil, teardownArgs...)
162162

163163
verifyCentralNotInstalled(t, "acs-central")
@@ -221,7 +221,7 @@ func TestOLMOperatorVersionUpgrade(t *testing.T) {
221221

222222
// Cleanup
223223
t.Log("=== Cleaning up ===")
224-
teardownArgs := []string{roxieBinary, "teardown", "central"}
224+
teardownArgs := []string{roxieBinary, "teardown", "--skip-user-config", "central"}
225225
runCommand(t, teardownTimeout, nil, teardownArgs...)
226226

227227
verifyCentralNotInstalled(t, "acs-central")
@@ -277,7 +277,7 @@ func TestSecuredClusterWithOLMSwitch(t *testing.T) {
277277

278278
// Cleanup
279279
t.Log("=== Cleaning up ===")
280-
teardownArgs := []string{roxieBinary, "teardown", "both"}
280+
teardownArgs := []string{roxieBinary, "teardown", "--skip-user-config", "both"}
281281
runCommand(t, teardownTimeout, nil, teardownArgs...)
282282

283283
verifyCentralNotInstalled(t, "acs-central")

0 commit comments

Comments
 (0)