Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Cluster scoped workflow template #2451

Merged
merged 144 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 128 commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
44d15f1
feat: Add ability to submit CronWorkflow and WorflowTemplate from CLI…
simster7 Jan 16, 2020
9325f16
goimports
simster7 Jan 16, 2020
502b1f4
Merge
simster7 Jan 27, 2020
1112e2c
Comments
simster7 Jan 27, 2020
0256c4f
Merge branch 'master' into submit-cron
simster7 Jan 27, 2020
d28b316
Lint:
simster7 Jan 27, 2020
8865b9d
Merge branch 'master' into submit-cron
simster7 Feb 3, 2020
a8ee360
Remove submitting from Workflow Template
simster7 Feb 3, 2020
87a2184
Convert.go and lint
simster7 Feb 3, 2020
002582a
Merge branch 'master' into submit-cron
simster7 Feb 6, 2020
64f6403
Update cli_with_server_test.go
sarabala1979 Feb 7, 2020
86158b5
feat!: Submittable workflow templates. Closes #2007
alexec Feb 7, 2020
d897d44
metav1
alexec Feb 7, 2020
cfd7609
Merge branch 'master' into submit-cron
alexec Feb 7, 2020
56b5aeb
merge
alexec Feb 7, 2020
76e6a13
goimports
alexec Feb 7, 2020
8689ca7
private
alexec Feb 7, 2020
af3bb73
remove nil check
alexec Feb 7, 2020
5afea26
code review changes
alexec Feb 7, 2020
ebeeac6
goimports
alexec Feb 7, 2020
9cd6b1f
Merge branch 'master' into submit-cron
alexec Feb 7, 2020
2783c94
Merge branch 'submit-cron' into submit-tmpl
alexec Feb 7, 2020
b482906
bits
alexec Feb 7, 2020
f183ffa
Merge branch 'master' into submit-tmpl
alexec Feb 7, 2020
260d3ea
Merge branch 'master' into submitable-tmpl
sarabala1979 Feb 12, 2020
9845c02
First Draft implementation of Submittable WorkflowTemplate
sarabala1979 Feb 12, 2020
fadae0e
Merge branch 'master' into submitable-tmpl
sarabala1979 Feb 12, 2020
b47eb26
Merge branch 'master' into submitable-tmpl
sarabala1979 Feb 12, 2020
5a34bcb
Merge branch 'master' into submitable-tmpl
alexec Feb 12, 2020
feace7d
Update pkg/apis/workflow/v1alpha1/workflow_types.go
sarabala1979 Feb 13, 2020
0e5f58e
Update test/e2e/smoke/workflow-template-whalesay-template.yaml
sarabala1979 Feb 13, 2020
1954f3c
Update pkg/apis/workflow/v1alpha1/generated.proto
sarabala1979 Feb 13, 2020
5b005ed
Merge branch 'master' into submitable-tmpl
sarabala1979 Feb 13, 2020
a007220
Fixed review comments
sarabala1979 Feb 13, 2020
4a67b77
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 13, 2020
143a0fc
Merge branch 'master' into submitable-tmpl
sarabala1979 Feb 13, 2020
31c63f5
Merge branch 'submitable-tmpl' of https://github.com/sarabala1979/arg…
sarabala1979 Feb 13, 2020
c6468ee
Update validate.go
sarabala1979 Feb 13, 2020
4409691
Update convert.go
sarabala1979 Feb 13, 2020
9417147
Update convert.go
sarabala1979 Feb 14, 2020
886ca9d
Update workflow/common/convert.go
sarabala1979 Feb 14, 2020
22e465d
Added unit test
sarabala1979 Feb 14, 2020
cbbf4c9
Update convert.go
sarabala1979 Feb 14, 2020
506be87
Update submit.go
sarabala1979 Feb 14, 2020
69e8af6
Update workflow/common/convert_test.go
sarabala1979 Feb 14, 2020
8b6ee83
Update convert_test.go
sarabala1979 Feb 14, 2020
b318144
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 14, 2020
f12fde2
Update workflow/common/convert_test.go
sarabala1979 Feb 14, 2020
f93335f
Update convert_test.go
sarabala1979 Feb 14, 2020
ccc86c7
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 18, 2020
4702130
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 21, 2020
3a11f82
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 21, 2020
44d8b51
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 21, 2020
07a41f9
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 24, 2020
3ac482d
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 25, 2020
0934b2a
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 26, 2020
5b4c201
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 27, 2020
0875e7b
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Feb 28, 2020
9da394b
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 6, 2020
7bc2e6f
Merge branch 'master' into submitable-tmpl
sarabala1979 Mar 6, 2020
14874c5
codegen
sarabala1979 Mar 6, 2020
d917625
merge conflicts
sarabala1979 Mar 6, 2020
dff0204
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 12, 2020
3e2d0cd
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 12, 2020
1873bc1
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 12, 2020
3c0830a
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 12, 2020
eb32345
draftversion
sarabala1979 Mar 15, 2020
b45c85d
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 15, 2020
286d03f
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 15, 2020
b3fe528
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 15, 2020
fe4d42a
Second draft
sarabala1979 Mar 15, 2020
dc2fa0b
workingversion
sarabala1979 Mar 16, 2020
7ec94c8
CLI changes
sarabala1979 Mar 16, 2020
ae62719
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 16, 2020
e381f7a
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 16, 2020
4e7f9da
Added Cluster workflowtemplate submittable
sarabala1979 Mar 16, 2020
3566592
Fixed RBAC
sarabala1979 Mar 16, 2020
a49bebe
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 17, 2020
00bbb02
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 17, 2020
1bd5a7e
updated RBAC
sarabala1979 Mar 17, 2020
8f4dc10
udpated RBAC
sarabala1979 Mar 17, 2020
8bb2c52
fixed namespace
sarabala1979 Mar 17, 2020
bd52860
updated cli
sarabala1979 Mar 17, 2020
b2fdb52
Added examble
sarabala1979 Mar 17, 2020
4232560
cleanupcode
sarabala1979 Mar 18, 2020
68097c1
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 18, 2020
ce1e74e
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 18, 2020
f602b15
fix master merge code gen
sarabala1979 Mar 18, 2020
48ece72
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 18, 2020
841e495
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 18, 2020
a57a7bc
removed unused import
sarabala1979 Mar 18, 2020
003dc4e
fixed test failure
sarabala1979 Mar 18, 2020
d151e8f
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 18, 2020
c4ebd48
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 19, 2020
75e70a1
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 19, 2020
b6653f6
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 19, 2020
d7b1503
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 19, 2020
9ae53ef
Register the GRPC and HTTP server
sarabala1979 Mar 19, 2020
d1e72e8
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 20, 2020
caf42aa
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 23, 2020
af996cd
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 23, 2020
f2e2f43
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 24, 2020
b1ea0a9
updated review comments
sarabala1979 Mar 25, 2020
c5d49e4
updated
sarabala1979 Mar 25, 2020
a71f32d
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 25, 2020
6a0588a
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 25, 2020
46a86a1
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 25, 2020
5bd7042
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 25, 2020
561483c
merged master
sarabala1979 Mar 25, 2020
3d4fe96
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 25, 2020
b2a85ff
Update validate_test.go
sarabala1979 Mar 25, 2020
2d1f207
Update operator_template_scope_test.go
sarabala1979 Mar 25, 2020
aea4401
update go mod
sarabala1979 Mar 25, 2020
0ba75d7
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 25, 2020
a2a3762
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 25, 2020
b1b5baf
fixed testcase
sarabala1979 Mar 25, 2020
cd24fff
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 26, 2020
20fb9f4
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 26, 2020
28813d2
Update operator_template_scope_test.go
sarabala1979 Mar 26, 2020
c07e43d
Update controller_test.go
sarabala1979 Mar 26, 2020
8986f15
trying informer sync in test
sarabala1979 Mar 26, 2020
76c6b98
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 26, 2020
10f9648
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 26, 2020
12b5863
Update operator_template_scope_test.go
sarabala1979 Mar 26, 2020
8c52620
fixed golangci issue
sarabala1979 Mar 26, 2020
80429a7
similified implementation
sarabala1979 Mar 27, 2020
7c1454b
go mod update
sarabala1979 Mar 27, 2020
5696c9f
update go mod
sarabala1979 Mar 27, 2020
4aadd7a
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 30, 2020
484ff30
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 30, 2020
0616213
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 30, 2020
d293044
addressed Alex Comments
sarabala1979 Mar 30, 2020
40d3e4b
Update create_test.go
sarabala1979 Mar 30, 2020
5622854
Update server/cronworkflow/cron_workflow_server.go
sarabala1979 Mar 30, 2020
f7c3004
Merge branch 'clusterwftemplate' of https://github.com/sarabala1979/a…
sarabala1979 Mar 30, 2020
b123157
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 30, 2020
ddcc7e0
updated review comments
sarabala1979 Mar 31, 2020
5120f52
Update clustertemplates.yaml
sarabala1979 Mar 31, 2020
8c62154
Merge branch 'master' of https://github.com/argoproj/argo
sarabala1979 Mar 31, 2020
1883344
Merge branch 'master' into clusterwftemplate
sarabala1979 Mar 31, 2020
846e7e6
updated codegen
sarabala1979 Mar 31, 2020
09ea599
fixed Merge issue
sarabala1979 Mar 31, 2020
827aa93
move the interfaces to common.go
sarabala1979 Apr 2, 2020
70e9aff
Fixed testcase
sarabala1979 Apr 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
338 changes: 312 additions & 26 deletions api/openapi-spec/swagger.json

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions cmd/argo/commands/clustertemplate/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package clustertemplate

import (
"log"
"os"

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

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/pkg/apiclient/clusterworkflowtemplate"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/workflow/common"
"github.com/argoproj/argo/workflow/util"
)

type cliCreateOpts struct {
output string // --output
strict bool // --strict
}

func NewCreateCommand() *cobra.Command {
var (
cliCreateOpts cliCreateOpts
)
var command = &cobra.Command{
Use: "create FILE1 FILE2...",
Short: "create a cluster workflow template",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}

createClusterWorkflowTemplates(args, &cliCreateOpts)
},
}
command.Flags().StringVarP(&cliCreateOpts.output, "output", "o", "", "Output format. One of: name|json|yaml|wide")
command.Flags().BoolVar(&cliCreateOpts.strict, "strict", true, "perform strict workflow validation")
return command
}

func createClusterWorkflowTemplates(filePaths []string, cliOpts *cliCreateOpts) {
if cliOpts == nil {
cliOpts = &cliCreateOpts{}
}
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewClusterWorkflowTemplateServiceClient()

fileContents, err := util.ReadManifest(filePaths...)
if err != nil {
log.Fatal(err)
}

var clusterWorkflowTemplates []wfv1.ClusterWorkflowTemplate
for _, body := range fileContents {
cwftmpls := unmarshalClusterWorkflowTemplates(body, cliOpts.strict)
clusterWorkflowTemplates = append(clusterWorkflowTemplates, cwftmpls...)
}

if len(clusterWorkflowTemplates) == 0 {
log.Println("No cluster workflow template found in given files")
os.Exit(1)
}

for _, wftmpl := range clusterWorkflowTemplates {
created, err := serviceClient.CreateClusterWorkflowTemplate(ctx, &clusterworkflowtemplate.ClusterWorkflowTemplateCreateRequest{
Template: &wftmpl,
})
if err != nil {
log.Fatalf("Failed to create cluster workflow template: %v", err)
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
}
printClusterWorkflowTemplate(created, cliOpts.output)
}
}

// unmarshalClusterWorkflowTemplates unmarshals the input bytes as either json or yaml
func unmarshalClusterWorkflowTemplates(wfBytes []byte, strict bool) []wfv1.ClusterWorkflowTemplate {
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
var cwft wfv1.ClusterWorkflowTemplate
var jsonOpts []json.JSONOpt
if strict {
jsonOpts = append(jsonOpts, json.DisallowUnknownFields)
}
err := json.Unmarshal(wfBytes, &cwft, jsonOpts...)
if err == nil {
return []wfv1.ClusterWorkflowTemplate{cwft}
}
yamlWfs, err := common.SplitClusterWorkflowTemplateYAMLFile(wfBytes, strict)
if err == nil {
return yamlWfs
}
log.Fatalf("Failed to parse cluster workflow template: %v", err)
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
53 changes: 53 additions & 0 deletions cmd/argo/commands/clustertemplate/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package clustertemplate

import (
"fmt"

"github.com/spf13/cobra"

"github.com/argoproj/pkg/errors"

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/pkg/apiclient/clusterworkflowtemplate"
)

// NewDeleteCommand returns a new instance of an `argo delete` command
func NewDeleteCommand() *cobra.Command {
var (
all bool
)

var command = &cobra.Command{
Use: "delete WORKFLOW_TEMPLATE",
Short: "delete a cluster workflow template",
Run: func(cmd *cobra.Command, args []string) {
apiServerDeleteClusterWorkflowTemplates(all, args)
},
}

command.Flags().BoolVar(&all, "all", false, "Delete all cluster workflow templates")
return command
}

func apiServerDeleteClusterWorkflowTemplates(allWFs bool, wfTmplNames []string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should inline this func

ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewClusterWorkflowTemplateServiceClient()
var delWFTmplNames []string
if allWFs {
cwftmplList, err := serviceClient.ListClusterWorkflowTemplates(ctx, &clusterworkflowtemplate.ClusterWorkflowTemplateListRequest{})
errors.CheckError(err)
for _, cwfTmpl := range cwftmplList.Items {
delWFTmplNames = append(delWFTmplNames, cwfTmpl.Name)
}

} else {
delWFTmplNames = wfTmplNames
}
for _, cwfTmplName := range delWFTmplNames {
_, err := serviceClient.DeleteClusterWorkflowTemplate(ctx, &clusterworkflowtemplate.ClusterWorkflowTemplateDeleteRequest{
Name: cwfTmplName,
})
errors.CheckError(err)
fmt.Printf("ClusterWorkflowTemplate '%s' deleted\n", cwfTmplName)
}
}
66 changes: 66 additions & 0 deletions cmd/argo/commands/clustertemplate/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package clustertemplate

import (
"encoding/json"
"fmt"
"log"

"github.com/spf13/cobra"
"sigs.k8s.io/yaml"

"github.com/argoproj/pkg/humanize"

"github.com/argoproj/argo/cmd/argo/commands/client"
clusterworkflowtmplpkg "github.com/argoproj/argo/pkg/apiclient/clusterworkflowtemplate"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)

func NewGetCommand() *cobra.Command {
var (
output string
)

var command = &cobra.Command{
Use: "get CLUSTER WORKFLOW_TEMPLATE...",
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
Short: "display details about a cluster workflow template",
Run: func(cmd *cobra.Command, args []string) {
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewClusterWorkflowTemplateServiceClient()
for _, name := range args {
wftmpl, err := serviceClient.GetClusterWorkflowTemplate(ctx, &clusterworkflowtmplpkg.ClusterWorkflowTemplateGetRequest{
Name: name,
})
if err != nil {
log.Fatal(err)
}
printClusterWorkflowTemplate(wftmpl, output)
}
},
}

command.Flags().StringVarP(&output, "output", "o", "", "Output format. One of: json|yaml|wide")
return command
}

func printClusterWorkflowTemplate(wf *wfv1.ClusterWorkflowTemplate, outFmt string) {
switch outFmt {
case "name":
fmt.Println(wf.ObjectMeta.Name)
case "json":
outBytes, _ := json.MarshalIndent(wf, "", " ")
fmt.Println(string(outBytes))
case "yaml":
outBytes, _ := yaml.Marshal(wf)
fmt.Print(string(outBytes))
case "wide", "":
printClusterWorkflowTemplateHelper(wf)
default:
log.Fatalf("Unknown output format: %s", outFmt)
}
}

func printClusterWorkflowTemplateHelper(wf *wfv1.ClusterWorkflowTemplate) {
const fmtStr = "%-20s %v\n"
fmt.Printf(fmtStr, "Name:", wf.ObjectMeta.Name)
fmt.Printf(fmtStr, "Created:", humanize.Timestamp(wf.ObjectMeta.CreationTimestamp.Time))
}
67 changes: 67 additions & 0 deletions cmd/argo/commands/clustertemplate/lint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package clustertemplate

import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"

"github.com/argoproj/pkg/errors"

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/pkg/apiclient/clusterworkflowtemplate"
"github.com/argoproj/argo/workflow/validate"
)

func NewLintCommand() *cobra.Command {
var (
strict bool
)
var command = &cobra.Command{
Use: "lint FILE...",
Short: "validate files or directories of workflow manifests",
Run: func(cmd *cobra.Command, args []string) {
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewClusterWorkflowTemplateServiceClient()

lint := func(file string) error {
cwfTmpls, err := validate.ParseCWfTmplFromFile(file, strict)
if err != nil {
return err
}
for _, cfwft := range cwfTmpls {
_, err := serviceClient.LintClusterWorkflowTemplate(ctx, &clusterworkflowtemplate.ClusterWorkflowTemplateLintRequest{Template: &cfwft})
if err != nil {
return err
}
}
fmt.Printf("%s is valid\n", file)
return nil
}

for _, file := range args {
stat, err := os.Stat(file)
errors.CheckError(err)
if stat.IsDir() {
err := filepath.Walk(file, func(path string, info os.FileInfo, err error) error {
fileExt := filepath.Ext(info.Name())
switch fileExt {
case ".yaml", ".yml", ".json":
default:
return nil
}
return lint(path)
})
errors.CheckError(err)
} else {
err := lint(file)
errors.CheckError(err)
}
}
fmt.Printf("Cluster Workflow Template manifests validated\n")
},
}
command.Flags().BoolVar(&strict, "strict", true, "perform strict workflow validation")
return command
}
61 changes: 61 additions & 0 deletions cmd/argo/commands/clustertemplate/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package clustertemplate

import (
"fmt"
"log"
"os"
"text/tabwriter"

"github.com/spf13/cobra"

"github.com/argoproj/argo/cmd/argo/commands/client"
"github.com/argoproj/argo/pkg/apiclient/clusterworkflowtemplate"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)

type listFlags struct {
output string // --output
}

func NewListCommand() *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

var (
listArgs listFlags
)
var command = &cobra.Command{
Use: "list",
Short: "list cluster workflow templates",
Run: func(cmd *cobra.Command, args []string) {
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewClusterWorkflowTemplateServiceClient()

cwftmplList, err := serviceClient.ListClusterWorkflowTemplates(ctx, &clusterworkflowtemplate.ClusterWorkflowTemplateListRequest{})
if err != nil {
log.Fatal(err)
}
switch listArgs.output {
case "", "wide":
printTable(cwftmplList.Items)
case "name":
for _, cwftmp := range cwftmplList.Items {
fmt.Println(cwftmp.ObjectMeta.Name)
}
default:
log.Fatalf("Unknown output mode: %s", listArgs.output)
}

},
}
command.Flags().StringVarP(&listArgs.output, "output", "o", "", "Output format. One of: wide|name")
return command
}

func printTable(wfList []wfv1.ClusterWorkflowTemplate) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
_, _ = fmt.Fprint(w, "NAME")
_, _ = fmt.Fprint(w, "\n")
for _, wf := range wfList {
_, _ = fmt.Fprintf(w, "%s\t", wf.ObjectMeta.Name)
_, _ = fmt.Fprintf(w, "\n")
}
_ = w.Flush()
}
24 changes: 24 additions & 0 deletions cmd/argo/commands/clustertemplate/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package clustertemplate

import (
"github.com/spf13/cobra"
)

func NewClusterTemplateCommand() *cobra.Command {
var command = &cobra.Command{
Use: "clustertemplate",
sarabala1979 marked this conversation as resolved.
Show resolved Hide resolved
Aliases: []string{"cwftmpl", "cwft"},
Short: "manipulate cluster workflow templates",
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
},
}

command.AddCommand(NewGetCommand())
command.AddCommand(NewListCommand())
command.AddCommand(NewCreateCommand())
command.AddCommand(NewDeleteCommand())
command.AddCommand(NewLintCommand())

return command
}
4 changes: 4 additions & 0 deletions cmd/argo/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/argoproj/pkg/cli"
"github.com/spf13/cobra"

"github.com/argoproj/argo/cmd/argo/commands/clustertemplate"

"github.com/argoproj/argo/cmd/argo/commands/auth"
"github.com/argoproj/argo/cmd/argo/commands/cron"
"github.com/argoproj/argo/util/help"
Expand Down Expand Up @@ -54,6 +56,8 @@ If you're using the Argo Server (e.g. because you need large workflow support or
command.AddCommand(cmd.NewVersionCmd(CLIName))
command.AddCommand(template.NewTemplateCommand())
command.AddCommand(cron.NewCronWorkflowCommand())
command.AddCommand(clustertemplate.NewClusterTemplateCommand())

client.AddKubectlFlagsToCmd(command)
client.AddArgoServerFlagsToCmd(command)

Expand Down
Loading