diff --git a/cmd/operator-sdk/test/local.go b/cmd/operator-sdk/test/local.go index fd1bd48130d..6b247b18df6 100644 --- a/cmd/operator-sdk/test/local.go +++ b/cmd/operator-sdk/test/local.go @@ -50,6 +50,7 @@ type testLocalConfig struct { noSetup bool debug bool image string + operatorFlags 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.operatorFlags, "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.operatorFlags != "" { + testArgs = append(testArgs, "-"+test.OperatorFlags, tlConfig.operatorFlags) + } } opts := projutil.GoTestOptions{ GoCmdOptions: projutil.GoCmdOptions{ diff --git a/pkg/test/main_entry.go b/pkg/test/main_entry.go index dfe49a440f5..fbb57a259ce 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" + OperatorFlags = "operatorFlags" ) 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)") + operatorFlags := flag.String(OperatorFlags, "", "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 *operatorFlags != "" { + args = append(args, strings.Split(*operatorFlags, " ")...) + } + localCmd = exec.Command(outputBinName, args...) localCmd.Stdout = &localCmdOutBuf localCmd.Stderr = &localCmdErrBuf c := make(chan os.Signal)