Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for VKE version upgrades #263

Merged
merged 4 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 85 additions & 3 deletions cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var (
vultr-cli kubernetes config ffd31f18-5f77-454c-9065-212f942c3c35

# Shortened with alias commands
vultr-cli k config ffd31f18-5f77-454c-9065-212f942c3c35'
vultr-cli k config ffd31f18-5f77-454c-9065-212f942c3c35
`

getVersionsLong = `Returns a list of supported kubernetes versions you can deploy`
Expand All @@ -103,7 +103,34 @@ var (
vultr-cli kubernetes versions

# Shortened with alias commands
vultr-cli k v'
vultr-cli k v
`

upgradesLong = `Display available kubernetes upgrade commands`
upgradesExample = `
# Full example
vultr-cli kubernetes upgrades

# Shortened example with aliases
vultr-cli k e
`

getUpgradesLong = `Returns a list of available kubernetes version the cluster can be upgraded to`
getUpgradesExample = `
# Full example
vultr-cli kubernetes upgrades list d4908765-b82a-4e7d-83d9-c0bc4c6a36d0

# Shortened with alias commands
vultr-cli k e l d4908765-b82a-4e7d-83d9-c0bc4c6a36d0
`

upgradeLong = `Initiate an upgrade of the kubernetes version on a given cluster`
upgradeExample = `
# Full example
vultr-cli kubernetes upgrades start d4908765-b82a-4e7d-83d9-c0bc4c6a36d0 --version="v1.23.5+3"

# Shortened with alias commands
vultr-cli k e s d4908765-b82a-4e7d-83d9-c0bc4c6a36d0 -v="v1.23.5+3"
`

nodepoolLong = `Get all available commands for Kubernetes node pools`
Expand Down Expand Up @@ -217,6 +244,20 @@ func Kubernetes() *cobra.Command {
k8Update.Flags().StringP("label", "l", "", "label for your kubernetes cluster")
k8Update.MarkFlagRequired("label")

// Sub command for upgrade functions
k8UpgradeCmd := &cobra.Command{
Use: "upgrades",
Aliases: []string{"upgrade", "e"},
Short: `upgrade commands for kubernetes version upgrades`,
Long: upgradesLong,
Example: upgradesExample,
}

k8UpgradeCmd.AddCommand(k8Upgrade, k8GetUpgrades)
k8Upgrade.Flags().StringP("version", "v", "", "the version to upgrade the cluster to")
k8Upgrade.MarkFlagRequired("version")
kubernetesCmd.AddCommand(k8UpgradeCmd)

// Node Pools SubCommands
nodepoolsCmd := &cobra.Command{
Use: "node-pool",
Expand Down Expand Up @@ -455,6 +496,47 @@ var k8GetVersions = &cobra.Command{
},
}

var k8GetUpgrades = &cobra.Command{
Use: "list <clusterID>",
Short: "gets available upgrades for a cluster",
Long: getUpgradesLong,
Example: getUpgradesExample,
Aliases: []string{"l"},
Run: func(cmd *cobra.Command, args []string) {
id := args[0]
upgrades, err := client.Kubernetes.GetUpgrades(context.Background(), id)
if err != nil {
fmt.Printf("error retrieving available upgrades : %v\n", err)
os.Exit(1)
}

printer.K8Upgrades(upgrades)
},
}

var k8Upgrade = &cobra.Command{
Use: "start <clusterID>",
Short: "perform upgrade on a cluster",
Long: upgradeLong,
Example: upgradeExample,
Aliases: []string{"s"},
Run: func(cmd *cobra.Command, args []string) {
id := args[0]
version, _ := cmd.Flags().GetString("version")

options := &govultr.ClusterUpgradeReq{
UpgradeVersion: version,
}

if err := client.Kubernetes.Upgrade(context.Background(), id, options); err != nil {
fmt.Printf("error performing cluster upgrade : %v\n", err)
os.Exit(1)
}

fmt.Println("kubernetes cluster upgrade has been initiated")
},
}

var npCreate = &cobra.Command{
Use: "create <clusterID>",
Short: "creates a node pool in a kubernetes cluster",
Expand Down Expand Up @@ -722,7 +804,7 @@ func formatNodePools(nodePools []string) ([]govultr.NodePoolReq, error) {
case field == "max-nodes":
v, err := strconv.Atoi(val)
if err != nil {
return nil, fmt.Errorf("invalid value for node pool max-nodes: %v", err)
return nil, fmt.Errorf("invalid value for max-nodes: %v", err)
}
np.MaxNodes = v
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/printer/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,12 @@ func K8Versions(versions *govultr.Versions) {

flush()
}

func K8Upgrades(upgrades []string) {
display(columns{"UPGRADES"})
for _, v := range upgrades {
display(columns{v})
}

flush()
}