From d81235b5c01c87516ebc5e1a510f897cbc2e567d Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Thu, 17 May 2018 15:26:23 -0400 Subject: [PATCH] cmd/up/local: add flag operator-flags extra-flags gives the ability to pass flags to the local operator. Fixes #255 --- commands/operator-sdk/cmd/up/local.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/commands/operator-sdk/cmd/up/local.go b/commands/operator-sdk/cmd/up/local.go index 64fac65ab8..0763373008 100644 --- a/commands/operator-sdk/cmd/up/local.go +++ b/commands/operator-sdk/cmd/up/local.go @@ -6,6 +6,7 @@ import ( "os/exec" "os/user" "path/filepath" + "strings" "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil" cmdError "github.com/operator-framework/operator-sdk/commands/operator-sdk/error" @@ -18,20 +19,22 @@ func NewLocalCmd() *cobra.Command { upLocalCmd := &cobra.Command{ Use: "local", Short: "Launches the operator locally", - Long: `The operator-sdk up local command launches the operator on the local machine -by building the operator binary with the ability to access a + Long: `The operator-sdk up local command launches the operator on the local machine +by building the operator binary with the ability to access a kubernetes cluster using a kubeconfig file. `, Run: upLocalFunc, } upLocalCmd.Flags().StringVar(&kubeConfig, "kubeconfig", "", "The file path to kubernetes configuration file; defaults to $HOME/.kube/config") + upLocalCmd.Flags().StringVar(&operatorFlags, "operator-flags", "", "The flags that the operator needs. Example: \"--flag1 value1 --flag2=value2\"") return upLocalCmd } var ( - kubeConfig string + kubeConfig string + operatorFlags string ) const ( @@ -67,7 +70,12 @@ func mustKubeConfig() { } func upLocal(projectName string) { - dc := exec.Command(gocmd, run, filepath.Join(cmd, projectName, main)) + args := []string{run, filepath.Join(cmd, projectName, main)} + if operatorFlags != "" { + extraArgs := strings.Split(operatorFlags, " ") + args = append(args, extraArgs...) + } + dc := exec.Command(gocmd, args...) dc.Stdout = os.Stdout dc.Stderr = os.Stderr dc.Env = append(os.Environ(), fmt.Sprintf("%v=%v", k8sutil.KubeConfigEnvVar, kubeConfig))