-
Notifications
You must be signed in to change notification settings - Fork 20
/
sks_update.go
94 lines (72 loc) · 2.14 KB
/
sks_update.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
package cmd
import (
"fmt"
"strings"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
var sksClusterResetFields = []string{
"description",
}
type sksUpdateCmd struct {
_ bool `cli-cmd:"update"`
Cluster string `cli-arg:"#" cli-usage:"NAME|ID"`
Description string `cli-usage:"cluster description"`
Name string `cli-usage:"cluster name"`
ResetFields []string `cli-flag:"reset" cli-usage:"properties to reset to default value"`
Zone string `cli-short:"z" cli-usage:"SKS cluster zone"`
}
func (c *sksUpdateCmd) cmdAliases() []string { return nil }
func (c *sksUpdateCmd) cmdShort() string { return "Update an SKS cluster" }
func (c *sksUpdateCmd) cmdLong() string {
return fmt.Sprintf(`This command updates an SKS cluster.
Supported output template annotations: %s
Support values for --reset flag: %s`,
strings.Join(outputterTemplateAnnotations(&sksShowOutput{}), ", "),
strings.Join(sksClusterResetFields, ", "),
)
}
func (c *sksUpdateCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *sksUpdateCmd) cmdRun(cmd *cobra.Command, _ []string) error {
var updated bool
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(gCurrentAccount.Environment, c.Zone))
cluster, err := cs.FindSKSCluster(ctx, c.Zone, c.Cluster)
if err != nil {
return err
}
if cmd.Flags().Changed(mustCLICommandFlagName(c, &c.Name)) {
cluster.Name = c.Name
updated = true
}
if cmd.Flags().Changed(mustCLICommandFlagName(c, &c.Description)) {
cluster.Description = c.Description
updated = true
}
decorateAsyncOperation(fmt.Sprintf("Updating SKS cluster %q...", c.Cluster), func() {
if updated {
err = cs.UpdateSKSCluster(ctx, c.Zone, cluster)
}
for _, f := range c.ResetFields {
switch f {
case "description":
err = cluster.ResetField(ctx, &cluster.Description)
}
if err != nil {
return
}
}
})
if err != nil {
return err
}
if !gQuiet {
return output(showSKSCluster(c.Zone, cluster.ID))
}
return nil
}
func init() {
cobra.CheckErr(registerCLICommand(sksCmd, &sksUpdateCmd{}))
}