diff --git a/cmd/operator-sdk/test/local.go b/cmd/operator-sdk/test/local.go index fd1bd48130d..5733352d29b 100644 --- a/cmd/operator-sdk/test/local.go +++ b/cmd/operator-sdk/test/local.go @@ -40,16 +40,17 @@ import ( var deployTestDir = filepath.Join(scaffold.DeployDir, "test") type testLocalConfig struct { - kubeconfig string - globalManPath string - namespacedManPath string - goTestFlags string - moleculeTestFlags string - namespace string - upLocal bool - noSetup bool - debug bool - image string + kubeconfig string + globalManPath string + namespacedManPath string + goTestFlags string + moleculeTestFlags string + namespace string + upLocal bool + noSetup bool + debug bool + image string + localOperatorFlags string } var tlConfig testLocalConfig @@ -70,6 +71,7 @@ func newTestLocalCmd() *cobra.Command { testCmd.Flags().BoolVar(&tlConfig.noSetup, "no-setup", false, "Disable test resource creation") testCmd.Flags().BoolVar(&tlConfig.debug, "debug", false, "Enable debug-level logging") testCmd.Flags().StringVar(&tlConfig.image, "image", "", "Use a different operator image from the one specified in the namespaced manifest") + testCmd.Flags().StringVar(&tlConfig.localOperatorFlags, "local-operator-flags", "", "The flags that the operator needs (while using --up-local). Example: \"--flag1 value1 --flag2=value2\"") return testCmd } @@ -207,6 +209,9 @@ func testLocalGoFunc(cmd *cobra.Command, args []string) error { } if tlConfig.upLocal { testArgs = append(testArgs, "-"+test.LocalOperatorFlag) + if tlConfig.localOperatorFlags != "" { + testArgs = append(testArgs, "-"+test.LocalOperatorArgs, tlConfig.localOperatorFlags) + } } opts := projutil.GoTestOptions{ GoCmdOptions: projutil.GoCmdOptions{ diff --git a/doc/sdk-cli-reference.md b/doc/sdk-cli-reference.md index 019ea7c2ed2..d45c206e535 100644 --- a/doc/sdk-cli-reference.md +++ b/doc/sdk-cli-reference.md @@ -487,6 +487,7 @@ Runs the tests locally * `--go-test-flags` string - Additional flags to pass to go test * `--molecule-test-flags` string - Additional flags to pass to molecule test * `--up-local` - enable running operator locally with go run instead of as an image in the cluster +* `--local-operator-flags` string - flags that the operator needs, while using --up-local (e.g. \"--flag1 value1 --flag2=value2\") * `--no-setup` - disable test resource creation * `--image` string - use a different operator image from the one specified in the namespaced manifest * `-h, --help` - help for local diff --git a/pkg/test/main_entry.go b/pkg/test/main_entry.go index dfe49a440f5..b0501ce27bb 100644 --- a/pkg/test/main_entry.go +++ b/pkg/test/main_entry.go @@ -23,6 +23,7 @@ import ( "os/exec" "os/signal" "path/filepath" + "strings" "syscall" "testing" @@ -42,6 +43,7 @@ const ( SingleNamespaceFlag = "singleNamespace" TestNamespaceEnv = "TEST_NAMESPACE" LocalOperatorFlag = "localOperator" + LocalOperatorArgs = "localOperatorArgs" ) func MainEntry(m *testing.M) { @@ -51,6 +53,7 @@ func MainEntry(m *testing.M) { namespacedManPath := flag.String(NamespacedManPathFlag, "", "path to rbac manifest") singleNamespace = flag.Bool(SingleNamespaceFlag, false, "enable single namespace mode") localOperator := flag.Bool(LocalOperatorFlag, false, "enable if operator is running locally (not in cluster)") + localOperatorArgs := flag.String(LocalOperatorArgs, "", "flags that the operator needs (while using --up-local). example: \"--flag1 value1 --flag2=value2\"") flag.Parse() // go test always runs from the test directory; change to project root err := os.Chdir(*projRoot) @@ -74,7 +77,11 @@ func MainEntry(m *testing.M) { if err := projutil.GoBuild(opts); err != nil { log.Fatalf("Failed to build local operator binary: %s", err) } - localCmd = exec.Command(outputBinName) + args := []string{} + if *localOperatorArgs != "" { + args = append(args, strings.Split(*localOperatorArgs, " ")...) + } + localCmd = exec.Command(outputBinName, args...) localCmd.Stdout = &localCmdOutBuf localCmd.Stderr = &localCmdErrBuf c := make(chan os.Signal)