diff --git a/cmd/argo/commands/common.go b/cmd/argo/commands/common.go index cc252fc9d039..d54ba101074f 100644 --- a/cmd/argo/commands/common.go +++ b/cmd/argo/commands/common.go @@ -24,6 +24,7 @@ var ( wfClient v1alpha1.WorkflowInterface jobStatusIconMap map[wfv1.NodePhase]string noColor bool + namespace string ) func init() { @@ -80,11 +81,10 @@ func initKubeClient() *kubernetes.Clientset { // InitWorkflowClient creates a new client for the Kubernetes Workflow CRD. func InitWorkflowClient(ns ...string) v1alpha1.WorkflowInterface { - if wfClient != nil { + if wfClient != nil && (len(ns) == 0 || ns[0] == namespace) { return wfClient } initKubeClient() - var namespace string var err error if len(ns) > 0 { namespace = ns[0] diff --git a/cmd/argo/commands/submit.go b/cmd/argo/commands/submit.go index 0337f588b84d..093ffa1f70fc 100644 --- a/cmd/argo/commands/submit.go +++ b/cmd/argo/commands/submit.go @@ -68,7 +68,7 @@ func SubmitWorkflows(filePaths []string, submitOpts *util.SubmitOpts, cliOpts *c if cliOpts == nil { cliOpts = &cliSubmitOpts{} } - InitWorkflowClient() + defaultWFClient := InitWorkflowClient() var workflows []wfv1.Workflow if len(filePaths) == 1 && filePaths[0] == "-" { reader := bufio.NewReader(os.Stdin) @@ -114,6 +114,10 @@ func SubmitWorkflows(filePaths []string, submitOpts *util.SubmitOpts, cliOpts *c var workflowNames []string for _, wf := range workflows { wf.Spec.Priority = cliOpts.priority + wfClient := defaultWFClient + if wf.Namespace != "" { + wfClient = InitWorkflowClient(wf.Namespace) + } created, err := util.SubmitWorkflow(wfClient, &wf, submitOpts) if err != nil { log.Fatalf("Failed to submit workflow: %v", err)