-
Notifications
You must be signed in to change notification settings - Fork 19
/
sks_rotate_ccm_credentials.go
52 lines (41 loc) · 1.31 KB
/
sks_rotate_ccm_credentials.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
package cmd
import (
"fmt"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
var sksRotateCCMCredentialsCmd = &cobra.Command{
Use: "rotate-ccm-credentials CLUSTER-NAME|ID",
Short: "Rotate the Exoscale Cloud Controller IAM credentials for a SKS cluster",
Long: `This command rotates the Exoscale IAM credentials managed by the SKS control
plane for the Kubernetes Exoscale Cloud Controller Manager.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
cmdSetZoneFlagFromDefault(cmd)
return cmdCheckRequiredFlags(cmd, []string{"zone"})
},
RunE: func(cmd *cobra.Command, args []string) error {
c := args[0]
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
}
if err := cluster.RotateCCMCredentials(ctx); err != nil {
return fmt.Errorf("error rotating credentials: %s", err)
}
fmt.Println("CCM credentials rotated successfully")
return nil
},
}
func init() {
sksRotateCCMCredentialsCmd.Flags().StringP("zone", "z", "", "SKS cluster zone")
sksCmd.AddCommand(sksRotateCCMCredentialsCmd)
}