forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suspend.go
44 lines (39 loc) · 1.05 KB
/
suspend.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
package cron
import (
"fmt"
"log"
"os"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
)
// NewSuspendCommand returns a new instance of an `argo suspend` command
func NewSuspendCommand() *cobra.Command {
var command = &cobra.Command{
Use: "suspend CRON_WORKFLOW",
Short: "suspend a cron workflow",
Run: func(cmd *cobra.Command, args []string) {
cronWfClient := InitCronWorkflowClient()
if len(args) == 0 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
for _, wftmplName := range args {
suspendCronWorkflow(cronWfClient, wftmplName)
}
},
}
return command
}
func suspendCronWorkflow(cronWfClient v1alpha1.CronWorkflowInterface, cronWfName string) {
cronWf, err := cronWfClient.Get(cronWfName, metav1.GetOptions{})
if err != nil {
log.Fatal(err)
}
cronWf.Spec.Suspend = true
newCronWf, err := cronWfClient.Update(cronWf)
if err != nil {
log.Fatal(err)
}
fmt.Printf("CronWorkflow '%s' suspended\n", newCronWf.Name)
}