-
Notifications
You must be signed in to change notification settings - Fork 19
/
sks_upgrade_service_level.go
83 lines (64 loc) · 2.07 KB
/
sks_upgrade_service_level.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
package cmd
import (
"fmt"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type sksUpgradeServiceLevelCmd struct {
cliCommandSettings `cli-cmd:"-"`
_ bool `cli-cmd:"upgrade-service-level"`
Cluster string `cli-arg:"#" cli-usage:"NAME|ID"`
Force bool `cli-short:"f" cli-usage:"don't prompt for confirmation"`
Zone string `cli-short:"z" cli-usage:"SKS cluster zone"`
}
func (c *sksUpgradeServiceLevelCmd) cmdAliases() []string { return nil }
func (c *sksUpgradeServiceLevelCmd) cmdShort() string {
return "Upgrade an SKS cluster service level"
}
func (c *sksUpgradeServiceLevelCmd) cmdLong() string {
return `This command upgrades an SKS cluster's service level to "pro".
Note: once upgraded to pro, an SKS cluster service level cannot be downgraded
to a lower level.`
}
func (c *sksUpgradeServiceLevelCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *sksUpgradeServiceLevelCmd) cmdRun(_ *cobra.Command, _ []string) error {
if !c.Force {
if !askQuestion(fmt.Sprintf(
"Are you sure you want to upgrade the cluster %q to service level pro?",
c.Cluster,
)) {
return nil
}
}
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(gCurrentAccount.Environment, c.Zone))
cluster, err := cs.FindSKSCluster(ctx, c.Zone, c.Cluster)
if err != nil {
return err
}
decorateAsyncOperation(fmt.Sprintf("Upgrading SKS cluster %q service level...", c.Cluster), func() {
err = cs.UpgradeSKSClusterServiceLevel(ctx, c.Zone, cluster)
})
if err != nil {
return err
}
if !gQuiet {
return (&sksShowCmd{
cliCommandSettings: c.cliCommandSettings,
Cluster: *cluster.ID,
Zone: c.Zone,
}).cmdRun(nil, nil)
}
return nil
}
func init() {
cobra.CheckErr(registerCLICommand(sksCmd, &sksUpgradeServiceLevelCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
// FIXME: remove this someday.
cobra.CheckErr(registerCLICommand(deprecatedSKSCmd, &sksUpgradeServiceLevelCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}