From 1750e50063e839a562aa697a96fa94ff8d68e42f Mon Sep 17 00:00:00 2001 From: "yangxue.chen" Date: Wed, 16 Jun 2021 11:17:03 +0800 Subject: [PATCH] [aidi][feat] support resource create or get --- workflow/executor/resource.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/workflow/executor/resource.go b/workflow/executor/resource.go index 536b9465fa8b..65fee9361005 100644 --- a/workflow/executor/resource.go +++ b/workflow/executor/resource.go @@ -24,7 +24,7 @@ import ( "github.com/argoproj/argo-workflows/v3/util" envutil "github.com/argoproj/argo-workflows/v3/util/env" argoerr "github.com/argoproj/argo-workflows/v3/util/errors" - os_specific "github.com/argoproj/argo-workflows/v3/workflow/executor/os-specific" + "github.com/argoproj/argo-workflows/v3/workflow/executor/os-specific" ) // ExecResource will run kubectl action against a manifest @@ -38,6 +38,18 @@ func (we *WorkflowExecutor) ExecResource(action string, manifestPath string, fla log.Info(strings.Join(cmd.Args, " ")) out, err := cmd.Output() + if err != nil && action == "create" { + // create支持restart,如果create err(already exists), try get + args, err = we.getKubectlArguments("get", manifestPath, flags) + if err != nil { + return "", "", "", err + } + + cmd = exec.Command("kubectl", args...) + log.Info(strings.Join(cmd.Args, " ")) + + out, err = cmd.Output() + } if err != nil { if exErr, ok := err.(*exec.ExitError); ok { errMsg := strings.TrimSpace(string(exErr.Stderr))