Skip to content

Commit

Permalink
Support submission of manifests via URL
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesuen committed Nov 16, 2017
1 parent cc1f0ca commit 1069af4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/argo/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func getWorkflow(cmd *cobra.Command, args []string) {
func printWorkflow(wf *wfv1.Workflow) {
const fmtStr = "%-17s %v\n"
fmt.Printf(fmtStr, "Name:", wf.ObjectMeta.Name)
fmt.Printf(fmtStr, "Namespace:", wf.ObjectMeta.Namespace)
fmt.Printf(fmtStr, "Status:", worklowStatus(wf))
fmt.Printf(fmtStr, "Created:", humanizeTimestamp(wf.ObjectMeta.CreationTimestamp.Unix()))

Expand Down
24 changes: 20 additions & 4 deletions cmd/argo/commands/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package commands
import (
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"strings"

wfv1 "github.com/argoproj/argo/api/workflow/v1"
cmdutil "github.com/argoproj/argo/util/cmd"
"github.com/argoproj/argo/workflow/common"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
Expand All @@ -34,17 +36,31 @@ func submitWorkflows(cmd *cobra.Command, args []string) {
}
initWorkflowClient()
for _, filePath := range args {
body, err := ioutil.ReadFile(filePath)
if err != nil {
log.Fatal(err)
var body []byte
var err error
if cmdutil.IsURL(filePath) {
response, err := http.Get(filePath)
if err != nil {
log.Fatal(err)
}
body, err = ioutil.ReadAll(response.Body)
response.Body.Close()
if err != nil {
log.Fatal(err)
}
} else {
body, err = ioutil.ReadFile(filePath)
if err != nil {
log.Fatal(err)
}
}
manifests := yamlSeparator.Split(string(body), -1)
for _, manifestStr := range manifests {
if strings.TrimSpace(manifestStr) == "" {
continue
}
var wf wfv1.Workflow
err = yaml.Unmarshal([]byte(manifestStr), &wf)
err := yaml.Unmarshal([]byte(manifestStr), &wf)
if err != nil {
log.Fatalf("Workflow manifest %s failed to parse: %v\n%s", filePath, err, manifestStr)
}
Expand Down
6 changes: 3 additions & 3 deletions deploy/demo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ $ argo install --service-account argo


2) Submit some examples
$ argo submit examples/hello-world.yaml
$ argo submit examples/coinflip.yaml
$ argo submit examples/loops-maps.yaml
$ argo submit https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml
$ argo submit https://raw.githubusercontent.com/argoproj/argo/master/examples/coinflip.yaml
$ argo submit https://raw.githubusercontent.com/argoproj/argo/master/examples/loops-maps.yaml


3) Install an artifact repository
Expand Down
7 changes: 7 additions & 0 deletions util/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd
import (
"fmt"
"log"
"net/url"
"os"
"os/user"

Expand Down Expand Up @@ -40,3 +41,9 @@ func MustHomeDir() string {
}
return usr.HomeDir
}

// IsURL returns whether or not a string is a URL
func IsURL(u string) bool {
_, err := url.ParseRequestURI(u)
return err == nil
}

0 comments on commit 1069af4

Please sign in to comment.