-
Notifications
You must be signed in to change notification settings - Fork 20
/
sks_upgrade.go
65 lines (49 loc) · 1.5 KB
/
sks_upgrade.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
package cmd
import (
"fmt"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type sksUpgradeCmd struct {
_ bool `cli-cmd:"upgrade"`
Cluster string `cli-arg:"#" cli-usage:"NAME|ID"`
Version string `cli-arg:"#"`
Force bool `cli-short:"f" cli-usage:"don't prompt for confirmation"`
Zone string `cli-short:"z" cli-usage:"SKS cluster zone"`
}
func (c *sksUpgradeCmd) cmdAliases() []string { return nil }
func (c *sksUpgradeCmd) cmdShort() string { return "Upgrade an SKS cluster Kubernetes version" }
func (c *sksUpgradeCmd) cmdLong() string { return "" }
func (c *sksUpgradeCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *sksUpgradeCmd) cmdRun(_ *cobra.Command, _ []string) error {
if !c.Force {
if !askQuestion(fmt.Sprintf(
"Are you sure you want to upgrade the cluster %q to version %s?",
c.Cluster,
c.Version,
)) {
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...", c.Cluster), func() {
err = cs.UpgradeSKSCluster(ctx, c.Zone, cluster, c.Version)
})
if err != nil {
return err
}
if !gQuiet {
return output(showSKSCluster(c.Zone, *cluster.ID))
}
return nil
}
func init() {
cobra.CheckErr(registerCLICommand(sksCmd, &sksUpgradeCmd{}))
}