-
Notifications
You must be signed in to change notification settings - Fork 850
/
pause.go
45 lines (40 loc) · 1.14 KB
/
pause.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
package pause
import (
"context"
"fmt"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/options"
)
const (
pauseExample = `
# Pause a rollout
%[1]s pause guestbook`
)
// NewCmdPause returns a new instance of an `rollouts pause` command
func NewCmdPause(o *options.ArgoRolloutsOptions) *cobra.Command {
var cmd = &cobra.Command{
Use: "pause ROLLOUT_NAME",
Short: "Pause a rollout",
Long: "Set the rollout paused state to 'true'",
Example: o.Example(pauseExample),
SilenceUsage: true,
RunE: func(c *cobra.Command, args []string) error {
if len(args) == 0 {
return o.UsageErr(c)
}
ns := o.Namespace()
rolloutIf := o.RolloutsClientset().ArgoprojV1alpha1().Rollouts(ns)
for _, name := range args {
ro, err := rolloutIf.Patch(context.TODO(), name, types.MergePatchType, []byte(`{"spec":{"paused":true}}`), metav1.PatchOptions{})
if err != nil {
return err
}
fmt.Fprintf(o.Out, "rollout '%s' paused\n", ro.Name)
}
return nil
},
}
return cmd
}