forked from argoproj/argo-rollouts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminate.go
97 lines (90 loc) · 2.72 KB
/
terminate.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package terminate
import (
"fmt"
"github.com/spf13/cobra"
types "k8s.io/apimachinery/pkg/types"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/options"
)
const (
terminatePatch = `{"spec":{"terminate":true}}`
)
// NewCmdTerminate returns a new instance of an `argo rollouts terminate` command
func NewCmdTerminate(o *options.ArgoRolloutsOptions) *cobra.Command {
var cmd = &cobra.Command{
Use: "terminate <analysisrun|experiment> RESOURCE",
Short: "Terminate an AalysisRun or experiment",
Example: o.Example(`
# Terminate an analysisRun
%[1]s terminate analysisrun ANALYSISRUN
# Terminate a failed experiment
%[1]s terminate experiment EXPERIMENT
`),
SilenceUsage: true,
RunE: func(c *cobra.Command, args []string) error {
return o.UsageErr(c)
},
}
cmd.AddCommand(NewCmdTerminateAnalysisRun(o))
cmd.AddCommand(NewCmdTerminateExperiment(o))
return cmd
}
// NewCmdTerminateAnalysisRun returns a new instance of an `argo rollouts terminate analysisRun` command
func NewCmdTerminateAnalysisRun(o *options.ArgoRolloutsOptions) *cobra.Command {
var cmd = &cobra.Command{
Use: "analysisrun ANALYSISRUN",
Aliases: []string{"ar", "analysisruns"},
Short: "Terminate an AnalysisRun",
Example: o.Example(`
# Terminate an AnalysisRun
%[1]s terminate ANALYSISRUN
`),
SilenceUsage: true,
RunE: func(c *cobra.Command, args []string) error {
if len(args) == 0 {
return o.UsageErr(c)
}
ns := o.Namespace()
analysisRunIf := o.RolloutsClientset().ArgoprojV1alpha1().AnalysisRuns(ns)
for _, name := range args {
ro, err := analysisRunIf.Patch(name, types.MergePatchType, []byte(terminatePatch))
if err != nil {
return err
}
fmt.Fprintf(o.Out, "analysisRun '%s' terminated\n", ro.Name)
}
return nil
},
}
o.AddKubectlFlags(cmd)
return cmd
}
// NewCmdTerminateExperiment returns a new instance of an `argo rollouts terminate experiment` command
func NewCmdTerminateExperiment(o *options.ArgoRolloutsOptions) *cobra.Command {
var cmd = &cobra.Command{
Use: "experiment EXPERIMENT",
Aliases: []string{"exp", "experiments"},
Short: "Terminate an experiment",
Example: o.Example(`
# Terminate an experiment
%[1]s terminate experiment EXPERIMENT
`),
SilenceUsage: true,
RunE: func(c *cobra.Command, args []string) error {
if len(args) == 0 {
return o.UsageErr(c)
}
ns := o.Namespace()
experimentIf := o.RolloutsClientset().ArgoprojV1alpha1().Experiments(ns)
for _, name := range args {
ro, err := experimentIf.Patch(name, types.MergePatchType, []byte(terminatePatch))
if err != nil {
return err
}
fmt.Fprintf(o.Out, "experiment '%s' retried\n", ro.Name)
}
return nil
},
}
o.AddKubectlFlags(cmd)
return cmd
}