diff --git a/README.md b/README.md index d73b0f2b..10aaf83c 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Available Commands: firewall firewall is used to access firewall commands help Help about any command iso iso is used to access iso commands + kubernetes kubernetes is used to access kubernetes commands load-balancer load balancer commands network network interacts with network actions object-storage object storage commands diff --git a/cmd/kubernetes.go b/cmd/kubernetes.go index 5e5a7756..a956225e 100644 --- a/cmd/kubernetes.go +++ b/cmd/kubernetes.go @@ -82,6 +82,12 @@ var ( vultr-cli k d ffd31f18-5f77-454c-9065-212f942c3c35' ` + deleteWithResourcesLong = `Delete a specific kubernetes cluster and all linked load balancers and block storages off your Vultr Account` + deleteWithResourcesExample = ` + # Full example + vultr-cli kubernetes delete-with-resources ffd31f18-5f77-454c-9065-212f942c3c35 + ` + getConfigLong = `Returns a base64 encoded config of a specified kubernetes cluster on your Vultr Account` getConfigExample = ` # Full example @@ -91,6 +97,15 @@ var ( vultr-cli k config ffd31f18-5f77-454c-9065-212f942c3c35' ` + getVersionsLong = `Returns a list of supported kubernetes versions you can deploy` + getVersionsExample = ` + # Full example + vultr-cli kubernetes versions + + # Shortened with alias commands + vultr-cli k v' + ` + nodepoolLong = `Get all available commands for Kubernetes node pools` nodepoolExample = ` # Full example @@ -185,7 +200,7 @@ func Kubernetes() *cobra.Command { Example: kubernetesExample, } - kubernetesCmd.AddCommand(k8Create, k8Get, k8List, k8GetConfig, k8Update, k8Delete) + kubernetesCmd.AddCommand(k8Create, k8Get, k8List, k8GetConfig, k8Update, k8Delete, k8DeleteWithResources, k8GetVersions) k8Create.Flags().StringP("label", "l", "", "label for your kubernetes cluster") k8Create.Flags().StringP("region", "r", "", "region you want your kubernetes cluster to be located in") k8Create.Flags().StringP("version", "v", "", "the kubernetes version you want for your cluster") @@ -371,6 +386,28 @@ var k8Delete = &cobra.Command{ }, } +var k8DeleteWithResources = &cobra.Command{ + Use: "delete-with-resources ", + Short: "delete a kubernetes cluster and related resources", + Long: deleteWithResourcesLong, + Example: deleteWithResourcesExample, + Args: func(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return errors.New("please provide a clusterID") + } + return nil + }, + Run: func(cmd *cobra.Command, args []string) { + id := args[0] + if err := client.Kubernetes.DeleteClusterWithResources(context.Background(), id); err != nil { + fmt.Printf("error deleting kubernetes cluster : %v\n", err) + os.Exit(1) + } + + fmt.Println("kubernetes cluster and related resources have been deleted") + }, +} + var k8GetConfig = &cobra.Command{ Use: "config ", Short: "gets a kubernetes cluster's config", @@ -394,6 +431,23 @@ var k8GetConfig = &cobra.Command{ }, } +var k8GetVersions = &cobra.Command{ + Use: "versions", + Short: "gets supported kubernetes versions", + Long: getVersionsLong, + Example: getVersionsExample, + Aliases: []string{"v"}, + Run: func(cmd *cobra.Command, args []string) { + versions, err := client.Kubernetes.GetVersions(context.Background()) + if err != nil { + fmt.Printf("error retrieving supported versions : %v\n", err) + os.Exit(1) + } + + printer.K8Versions(versions) + }, +} + var npCreate = &cobra.Command{ Use: "create ", Short: "creates a node pool in a kubernetes cluster", diff --git a/cmd/printer/kubernetes.go b/cmd/printer/kubernetes.go index 9d6623e8..843054e2 100644 --- a/cmd/printer/kubernetes.go +++ b/cmd/printer/kubernetes.go @@ -123,3 +123,12 @@ func NodePool(np *govultr.NodePool) { flush() } + +func K8Versions(versions *govultr.Versions) { + display(columns{"VERSIONS"}) + for _, v := range versions.Versions { + display(columns{v}) + } + + flush() +} diff --git a/go.mod b/go.mod index 4e9c25e3..7e9d80c5 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,6 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.8.1 - github.com/vultr/govultr/v2 v2.8.0 + github.com/vultr/govultr/v2 v2.8.1 golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 ) diff --git a/go.sum b/go.sum index f81df7b8..6756f436 100644 --- a/go.sum +++ b/go.sum @@ -247,6 +247,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/vultr/govultr/v2 v2.8.0 h1:7wYAjmhkoP8svMVrv6L6VXwzGAdBj8tZv+4293FF/W4= github.com/vultr/govultr/v2 v2.8.0/go.mod h1:BvOhVe6/ZpjwcoL6/unkdQshmbS9VGbowI4QT+3DGVU= +github.com/vultr/govultr/v2 v2.8.1 h1:AjRcJWfTfb4DidRNCeojUIgLVC5XShuc5IAW99K3wHU= +github.com/vultr/govultr/v2 v2.8.1/go.mod h1:JjUljQdSZx+MELCAJvZ/JH32bJotmflnsyS0NOjb8Jg= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/vendor/github.com/vultr/govultr/v2/.travis.yml b/vendor/github.com/vultr/govultr/v2/.travis.yml index 2fa895b3..d748f442 100644 --- a/vendor/github.com/vultr/govultr/v2/.travis.yml +++ b/vendor/github.com/vultr/govultr/v2/.travis.yml @@ -1,8 +1,8 @@ language: go go: - - 1.15.x - 1.16.x + - 1.17.x - tip matrix: diff --git a/vendor/github.com/vultr/govultr/v2/CHANGELOG.md b/vendor/github.com/vultr/govultr/v2/CHANGELOG.md index 959fde83..df555493 100644 --- a/vendor/github.com/vultr/govultr/v2/CHANGELOG.md +++ b/vendor/github.com/vultr/govultr/v2/CHANGELOG.md @@ -2,6 +2,14 @@ ## GoVultr v1 changelog is located [here](https://github.com/vultr/govultr/blob/v1/CHANGELOG.md) +## [v2.8.1](https://github.com/vultr/govultr/compare/v2.8.0..v2.8.1) (2021-08-31) +### Enhancement +* Kubernetes : Add support for deletion with resources [159](https://github.com/vultr/govultr/pull/159) +* Kubernetes : Add support for getting available versions[159](https://github.com/vultr/govultr/pull/159) + +### Dependency Update +* Bump Go version to 1.16 [158](https://github.com/vultr/govultr/pull/158) + ## [v2.8.0](https://github.com/vultr/govultr/compare/v2.7.1..v2.8.0) (2021-08-18) ### Enhancement * Added support for Vultr Kubernetes Engine [156](https://github.com/vultr/govultr/pull/156) diff --git a/vendor/github.com/vultr/govultr/v2/go.mod b/vendor/github.com/vultr/govultr/v2/go.mod index f090009b..36add092 100644 --- a/vendor/github.com/vultr/govultr/v2/go.mod +++ b/vendor/github.com/vultr/govultr/v2/go.mod @@ -1,6 +1,6 @@ module github.com/vultr/govultr/v2 -go 1.14 +go 1.16 require ( github.com/google/go-querystring v1.1.0 diff --git a/vendor/github.com/vultr/govultr/v2/go.sum b/vendor/github.com/vultr/govultr/v2/go.sum index 91c67578..ea425ca0 100644 --- a/vendor/github.com/vultr/govultr/v2/go.sum +++ b/vendor/github.com/vultr/govultr/v2/go.sum @@ -1,4 +1,3 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -10,9 +9,6 @@ github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxC github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4= github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/vendor/github.com/vultr/govultr/v2/govultr.go b/vendor/github.com/vultr/govultr/v2/govultr.go index ecc584a5..c08348b0 100644 --- a/vendor/github.com/vultr/govultr/v2/govultr.go +++ b/vendor/github.com/vultr/govultr/v2/govultr.go @@ -16,7 +16,7 @@ import ( ) const ( - version = "2.8.0" + version = "2.8.1" defaultBase = "https://api.vultr.com" userAgent = "govultr/" + version rateLimit = 500 * time.Millisecond diff --git a/vendor/github.com/vultr/govultr/v2/kubernetes.go b/vendor/github.com/vultr/govultr/v2/kubernetes.go index b6e5afe0..509e1562 100644 --- a/vendor/github.com/vultr/govultr/v2/kubernetes.go +++ b/vendor/github.com/vultr/govultr/v2/kubernetes.go @@ -18,6 +18,7 @@ type KubernetesService interface { ListClusters(ctx context.Context, options *ListOptions) ([]Cluster, *Meta, error) UpdateCluster(ctx context.Context, vkeID string, updateReq *ClusterReqUpdate) error DeleteCluster(ctx context.Context, id string) error + DeleteClusterWithResources(ctx context.Context, id string) error CreateNodePool(ctx context.Context, vkeID string, nodePoolReq *NodePoolReq) (*NodePool, error) ListNodePools(ctx context.Context, vkeID string, options *ListOptions) ([]NodePool, *Meta, error) @@ -29,6 +30,7 @@ type KubernetesService interface { RecycleNodePoolInstance(ctx context.Context, vkeID, nodePoolID, nodeID string) error GetKubeConfig(ctx context.Context, vkeID string) (*KubeConfig, error) + GetVersions(ctx context.Context) (*Versions, error) } // KubernetesHandler handles interaction with the kubernetes methods for the Vultr API @@ -119,6 +121,11 @@ type vkeNodePoolBase struct { NodePool *NodePool `json:"node_pool"` } +// Versions that are supported for VKE +type Versions struct { + Versions []string `json:"versions"` +} + // CreateCluster will create a Kubernetes cluster. func (k *KubernetesHandler) CreateCluster(ctx context.Context, createReq *ClusterReq) (*Cluster, error) { req, err := k.client.NewRequest(ctx, http.MethodPost, vkePath, createReq) @@ -191,6 +198,16 @@ func (k *KubernetesHandler) DeleteCluster(ctx context.Context, id string) error return k.client.DoWithContext(ctx, req, nil) } +// DeleteClusterWithResources will delete a Kubernetes cluster and all related resources. +func (k *KubernetesHandler) DeleteClusterWithResources(ctx context.Context, id string) error { + req, err := k.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s/delete-with-linked-resources", vkePath, id), nil) + if err != nil { + return err + } + + return k.client.DoWithContext(ctx, req, nil) +} + // CreateNodePool creates a nodepool on a VKE cluster func (k *KubernetesHandler) CreateNodePool(ctx context.Context, vkeID string, nodePoolReq *NodePoolReq) (*NodePool, error) { req, err := k.client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("%s/%s/node-pools", vkePath, vkeID), nodePoolReq) @@ -303,3 +320,19 @@ func (k *KubernetesHandler) GetKubeConfig(ctx context.Context, vkeID string) (*K return kc, nil } + +// GetVersions returns the supported kubernetes versions +func (k *KubernetesHandler) GetVersions(ctx context.Context) (*Versions, error) { + uri := "/v2/kubernetes/versions" + req, err := k.client.NewRequest(ctx, http.MethodGet, uri, nil) + if err != nil { + return nil, err + } + + versions := new(Versions) + if err = k.client.DoWithContext(ctx, req, &versions); err != nil { + return nil, err + } + + return versions, nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 9625aff1..db7713a3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -45,7 +45,7 @@ github.com/spf13/pflag github.com/spf13/viper # github.com/subosito/gotenv v1.2.0 github.com/subosito/gotenv -# github.com/vultr/govultr/v2 v2.8.0 +# github.com/vultr/govultr/v2 v2.8.1 ## explicit github.com/vultr/govultr/v2 # golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4