-
Notifications
You must be signed in to change notification settings - Fork 20
/
sks_upgrade.go
59 lines (46 loc) · 1.2 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
package cmd
import (
"fmt"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
var sksUpgradeCmd = &cobra.Command{
Use: "upgrade NAME|ID VERSION",
Short: "Upgrade a SKS cluster Kubernetes version",
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 2 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
cmdSetZoneFlagFromDefault(cmd)
return cmdCheckRequiredFlags(cmd, []string{"zone"})
},
RunE: func(cmd *cobra.Command, args []string) error {
var (
c = args[0]
version = args[1]
)
zone, err := cmd.Flags().GetString("zone")
if err != nil {
return err
}
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(gCurrentAccount.Environment, zone))
cluster, err := lookupSKSCluster(ctx, zone, c)
if err != nil {
return err
}
decorateAsyncOperation(fmt.Sprintf("Upgrading SKS cluster %q...", c), func() {
err = cs.UpgradeSKSCluster(ctx, zone, cluster.ID, version)
})
if err != nil {
return err
}
if !gQuiet {
return output(showSKSCluster(zone, cluster.ID))
}
return nil
},
}
func init() {
sksUpgradeCmd.Flags().StringP("zone", "z", "", "SKS cluster zone")
sksCmd.AddCommand(sksUpgradeCmd)
}