forked from argoproj/argo-workflows
/
delete.go
53 lines (44 loc) · 1.59 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package clustertemplate
import (
"context"
"fmt"
"github.com/argoproj/pkg/errors"
"github.com/spf13/cobra"
"github.com/svnshing/argo-workflows/v3/cmd/argo/commands/client"
"github.com/svnshing/argo-workflows/v3/pkg/apiclient/clusterworkflowtemplate"
)
// NewDeleteCommand returns a new instance of an `argo delete` command
func NewDeleteCommand() *cobra.Command {
var all bool
command := &cobra.Command{
Use: "delete WORKFLOW_TEMPLATE",
Short: "delete a cluster workflow template",
Run: func(cmd *cobra.Command, args []string) {
apiServerDeleteClusterWorkflowTemplates(cmd.Context(), all, args)
},
}
command.Flags().BoolVar(&all, "all", false, "Delete all cluster workflow templates")
return command
}
func apiServerDeleteClusterWorkflowTemplates(ctx context.Context, allWFs bool, wfTmplNames []string) {
ctx, apiClient := client.NewAPIClient(ctx)
serviceClient, err := apiClient.NewClusterWorkflowTemplateServiceClient()
errors.CheckError(err)
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)
}
}