-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
67 lines (57 loc) · 1.77 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package template
import (
"context"
"fmt"
"log"
"github.com/argoproj/pkg/errors"
"github.com/spf13/cobra"
"github.com/argoproj/argo/cmd/argo/commands/client"
workflowtemplatepkg "github.com/argoproj/argo/pkg/apiclient/workflowtemplate"
)
// 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 workflow template",
Run: func(cmd *cobra.Command, args []string) {
apiServerDeleteWorkflowTemplates(all, args)
},
}
command.Flags().BoolVar(&all, "all", false, "Delete all workflow templates")
return command
}
func apiServerDeleteWorkflowTemplates(allWFs bool, wfTmplNames []string) {
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewWorkflowTemplateServiceClient()
namespace := client.Namespace()
var delWFTmplNames []string
if allWFs {
wftmplList, err := serviceClient.ListWorkflowTemplates(ctx, &workflowtemplatepkg.WorkflowTemplateListRequest{
Namespace: namespace,
})
if err != nil {
log.Fatal(err)
}
for _, wfTmpl := range wftmplList.Items {
delWFTmplNames = append(delWFTmplNames, wfTmpl.Name)
}
} else {
delWFTmplNames = wfTmplNames
}
for _, wfTmplNames := range delWFTmplNames {
apiServerDeleteWorkflowTemplate(serviceClient, ctx, namespace, wfTmplNames)
}
}
func apiServerDeleteWorkflowTemplate(client workflowtemplatepkg.WorkflowTemplateServiceClient, ctx context.Context, namespace, wftmplName string) {
_, err := client.DeleteWorkflowTemplate(ctx, &workflowtemplatepkg.WorkflowTemplateDeleteRequest{
Name: wftmplName,
Namespace: namespace,
})
if err != nil {
errors.CheckError(err)
}
fmt.Printf("WorkflowTemplate '%s' deleted\n", wftmplName)
}