Skip to content

Commit

Permalink
Add a check for the server api version when using server-dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
AnesBenmerzoug committed Jul 31, 2019
1 parent 8547209 commit 5f1680b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cmd/argo/commands/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"log"
"net/http"
"os"
"strconv"

"github.com/argoproj/pkg/json"
"github.com/spf13/cobra"

apimachineryversion "k8s.io/apimachinery/pkg/version"

wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
cmdutil "github.com/argoproj/argo/util/cmd"
"github.com/argoproj/argo/workflow/common"
Expand Down Expand Up @@ -128,6 +131,17 @@ func SubmitWorkflows(filePaths []string, submitOpts *util.SubmitOpts, cliOpts *c
if cliOpts.output == "" {
log.Fatalf("--server-dry-run should have an output option")
}
serverVersion, err := wfClientset.Discovery().ServerVersion()
if err != nil {
log.Fatalf("Unexpected error while getting the server's api version")
}
isCompatible, err := checkServerVersionForDryRun(serverVersion)
if err != nil {
log.Fatalf("Unexpected error while checking the server's api version compatibility with --server-dry-run")
}
if !isCompatible {
log.Fatalf("--server-dry-run is not available for server api versions older than v1.12")
}
}

if len(workflows) == 0 {
Expand Down Expand Up @@ -160,6 +174,24 @@ func SubmitWorkflows(filePaths []string, submitOpts *util.SubmitOpts, cliOpts *c
waitOrWatch(workflowNames, *cliOpts)
}

// Checks whether the server has support for the dry-run option
func checkServerVersionForDryRun(serverVersion *apimachineryversion.Info) (bool, error) {
majorVersion, err := strconv.Atoi(serverVersion.Major)
if err != nil {
return false, err
}
minorVersion, err := strconv.Atoi(serverVersion.Minor)
if err != nil {
return false, err
}
if majorVersion < 1 {
return false, nil
} else if majorVersion == 1 && minorVersion < 12 {
return false, nil
}
return true, nil
}

// unmarshalWorkflows unmarshals the input bytes as either json or yaml
func unmarshalWorkflows(wfBytes []byte, strict bool) []wfv1.Workflow {
var wf wfv1.Workflow
Expand Down

0 comments on commit 5f1680b

Please sign in to comment.