diff --git a/go.mod b/go.mod index 4e4e078f..0b41c008 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.16 require ( github.com/hashicorp/hcl/v2 v2.10.1 github.com/hashicorp/packer-plugin-sdk v0.2.5 - github.com/vultr/govultr/v2 v2.7.1 + github.com/vultr/govultr/v2 v2.8.1 github.com/zclconf/go-cty v1.9.1 golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f diff --git a/go.sum b/go.sum index a0649d1f..b60a669b 100644 --- a/go.sum +++ b/go.sum @@ -545,8 +545,8 @@ github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= -github.com/vultr/govultr/v2 v2.7.1 h1:uF9ERet++Gb+7Cqs3p1P6b6yebeaZqVd7t5P2uZCaJU= -github.com/vultr/govultr/v2 v2.7.1/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 a959c6a9..df555493 100644 --- a/vendor/github.com/vultr/govultr/v2/CHANGELOG.md +++ b/vendor/github.com/vultr/govultr/v2/CHANGELOG.md @@ -2,6 +2,18 @@ ## 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) + ## [v2.7.1](https://github.com/vultr/govultr/compare/v2.7.0..v2.7.1) (2021-07-15) ### Enhancement * BareMetal : Add support for `image_id` on update [152](https://github.com/vultr/govultr/pull/152) 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 8ae93834..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.7.1" + version = "2.8.1" defaultBase = "https://api.vultr.com" userAgent = "govultr/" + version rateLimit = 500 * time.Millisecond @@ -55,6 +55,7 @@ type Client struct { FirewallRule FireWallRuleService Instance InstanceService ISO ISOService + Kubernetes KubernetesService LoadBalancer LoadBalancerService Network NetworkService ObjectStorage ObjectStorageService @@ -106,6 +107,7 @@ func NewClient(httpClient *http.Client) *Client { client.FirewallRule = &FireWallRuleServiceHandler{client} client.Instance = &InstanceServiceHandler{client} client.ISO = &ISOServiceHandler{client} + client.Kubernetes = &KubernetesHandler{client} client.LoadBalancer = &LoadBalancerHandler{client} client.Network = &NetworkServiceHandler{client} client.ObjectStorage = &ObjectStorageServiceHandler{client} diff --git a/vendor/github.com/vultr/govultr/v2/kubernetes.go b/vendor/github.com/vultr/govultr/v2/kubernetes.go new file mode 100644 index 00000000..509e1562 --- /dev/null +++ b/vendor/github.com/vultr/govultr/v2/kubernetes.go @@ -0,0 +1,338 @@ +package govultr + +import ( + "context" + "fmt" + "net/http" + + "github.com/google/go-querystring/query" +) + +const vkePath = "/v2/kubernetes/clusters" + +// KubernetesService is the interface to interact with kubernetes endpoint on the Vultr API +// Link : https://www.vultr.com/api/#tag/kubernetes +type KubernetesService interface { + CreateCluster(ctx context.Context, createReq *ClusterReq) (*Cluster, error) + GetCluster(ctx context.Context, id string) (*Cluster, error) + 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) + GetNodePool(ctx context.Context, vkeID, nodePoolID string) (*NodePool, error) + UpdateNodePool(ctx context.Context, vkeID, nodePoolID string, updateReq *NodePoolReqUpdate) (*NodePool, error) + DeleteNodePool(ctx context.Context, vkeID, nodePoolID string) error + + DeleteNodePoolInstance(ctx context.Context, vkeID, nodePoolID, nodeID string) error + 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 +type KubernetesHandler struct { + client *Client +} + +// Cluster represents a full VKE cluster +type Cluster struct { + ID string `json:"id"` + Label string `json:"label"` + DateCreated string `json:"date_created"` + ClusterSubnet string `json:"cluster_subnet"` + ServiceSubnet string `json:"service_subnet"` + IP string `json:"ip"` + Endpoint string `json:"endpoint"` + Version string `json:"version"` + Region string `json:"region"` + Status string `json:"status"` + NodePools []NodePool `json:"node_pools"` +} + +// NodePool represents a pool of nodes that are grouped by their label and plan type +type NodePool struct { + ID string `json:"id"` + DateCreated string `json:"date_created"` + DateUpdated string `json:"date_updated"` + Label string `json:"label"` + PlanID string `json:"plan_id"` + Status string `json:"status"` + Count int `json:"count"` + Nodes []Node `json:"nodes"` +} + +// Node represents a node that will live within a nodepool +type Node struct { + ID string `json:"id"` + DateCreated string `json:"date_created"` + Label string `json:"label"` + Status string `json:"status"` +} + +// KubeConfig will contain the kubeconfig b64 encoded +type KubeConfig struct { + KubeConfig string `json:"kube_config"` +} + +// ClusterReq struct used to create a cluster +type ClusterReq struct { + Label string `json:"label"` + Region string `json:"region"` + Version string `json:"version"` + NodePools []NodePoolReq `json:"node_pools"` +} + +// ClusterReqUpdate struct used to update update a cluster +type ClusterReqUpdate struct { + Label string `json:"label"` +} + +// NodePoolReq struct used to create a node pool +type NodePoolReq struct { + NodeQuantity int `json:"node_quantity"` + Label string `json:"label"` + Plan string `json:"plan"` +} + +// NodePoolReqUpdate struct used to update a node pool +type NodePoolReqUpdate struct { + NodeQuantity int `json:"node_quantity"` +} + +type vkeClustersBase struct { + VKEClusters []Cluster `json:"vke_clusters"` + Meta *Meta `json:"meta"` +} + +type vkeClusterBase struct { + VKECluster *Cluster `json:"vke_cluster"` +} + +type vkeNodePoolsBase struct { + NodePools []NodePool `json:"node_pools"` + Meta *Meta `json:"meta"` +} + +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) + if err != nil { + return nil, err + } + + var k8 = new(vkeClusterBase) + if err = k.client.DoWithContext(ctx, req, &k8); err != nil { + return nil, err + } + + return k8.VKECluster, nil +} + +// GetCluster will return a Kubernetes cluster. +func (k *KubernetesHandler) GetCluster(ctx context.Context, id string) (*Cluster, error) { + req, err := k.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s", vkePath, id), nil) + if err != nil { + return nil, err + } + + k8 := new(vkeClusterBase) + if err = k.client.DoWithContext(ctx, req, &k8); err != nil { + return nil, err + } + + return k8.VKECluster, nil +} + +// ListClusters will return all kubernetes clusters. +func (k *KubernetesHandler) ListClusters(ctx context.Context, options *ListOptions) ([]Cluster, *Meta, error) { + req, err := k.client.NewRequest(ctx, http.MethodGet, vkePath, nil) + if err != nil { + return nil, nil, err + } + + newValues, err := query.Values(options) + if err != nil { + return nil, nil, err + } + + req.URL.RawQuery = newValues.Encode() + + k8s := new(vkeClustersBase) + if err = k.client.DoWithContext(ctx, req, &k8s); err != nil { + return nil, nil, err + } + + return k8s.VKEClusters, k8s.Meta, nil +} + +// UpdateCluster updates label on VKE cluster +func (k *KubernetesHandler) UpdateCluster(ctx context.Context, vkeID string, updateReq *ClusterReqUpdate) error { + req, err := k.client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("%s/%s", vkePath, vkeID), updateReq) + if err != nil { + return err + } + + return k.client.DoWithContext(ctx, req, nil) +} + +// DeleteCluster will delete a Kubernetes cluster. +func (k *KubernetesHandler) DeleteCluster(ctx context.Context, id string) error { + req, err := k.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s", vkePath, id), nil) + if err != nil { + return err + } + + 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) + if err != nil { + return nil, err + } + + n := new(vkeNodePoolBase) + err = k.client.DoWithContext(ctx, req, n) + if err != nil { + return nil, err + } + + return n.NodePool, nil +} + +// ListNodePools will return all nodepools for a given VKE cluster +func (k *KubernetesHandler) ListNodePools(ctx context.Context, vkeID string, options *ListOptions) ([]NodePool, *Meta, error) { + req, err := k.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s/node-pools", vkePath, vkeID), nil) + if err != nil { + return nil, nil, err + } + + newValues, err := query.Values(options) + if err != nil { + return nil, nil, err + } + + req.URL.RawQuery = newValues.Encode() + + n := new(vkeNodePoolsBase) + if err = k.client.DoWithContext(ctx, req, &n); err != nil { + return nil, nil, err + } + + return n.NodePools, n.Meta, nil +} + +// GetNodePool will return a single nodepool +func (k *KubernetesHandler) GetNodePool(ctx context.Context, vkeID, nodePoolID string) (*NodePool, error) { + req, err := k.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s/node-pools/%s", vkePath, vkeID, nodePoolID), nil) + if err != nil { + return nil, err + } + + n := new(vkeNodePoolBase) + if err = k.client.DoWithContext(ctx, req, &n); err != nil { + return nil, err + } + + return n.NodePool, nil +} + +// UpdateNodePool will allow you change the quantity of nodes within a nodepool +func (k *KubernetesHandler) UpdateNodePool(ctx context.Context, vkeID, nodePoolID string, updateReq *NodePoolReqUpdate) (*NodePool, error) { + req, err := k.client.NewRequest(ctx, http.MethodPatch, fmt.Sprintf("%s/%s/node-pools/%s", vkePath, vkeID, nodePoolID), updateReq) + if err != nil { + return nil, err + } + + np := new(vkeNodePoolBase) + if err = k.client.DoWithContext(ctx, req, np); err != nil { + return nil, err + } + + return np.NodePool, nil +} + +// DeleteNodePool will remove a nodepool from a VKE cluster +func (k *KubernetesHandler) DeleteNodePool(ctx context.Context, vkeID, nodePoolID string) error { + req, err := k.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s/node-pools/%s", vkePath, vkeID, nodePoolID), nil) + if err != nil { + return err + } + + return k.client.DoWithContext(ctx, req, nil) +} + +// DeleteNodePoolInstance will remove a specified node from a nodepool +func (k *KubernetesHandler) DeleteNodePoolInstance(ctx context.Context, vkeID, nodePoolID, nodeID string) error { + req, err := k.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s/node-pools/%s/nodes/%s", vkePath, vkeID, nodePoolID, nodeID), nil) + if err != nil { + return err + } + + return k.client.DoWithContext(ctx, req, nil) +} + +// RecycleNodePoolInstance will recycle (destroy + redeploy) a given node on a nodepool +func (k *KubernetesHandler) RecycleNodePoolInstance(ctx context.Context, vkeID, nodePoolID, nodeID string) error { + req, err := k.client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("%s/%s/node-pools/%s/nodes/%s/recycle", vkePath, vkeID, nodePoolID, nodeID), nil) + if err != nil { + return err + } + + return k.client.DoWithContext(ctx, req, nil) +} + +// GetKubeConfig returns the kubeconfig for the specified VKE cluster +func (k *KubernetesHandler) GetKubeConfig(ctx context.Context, vkeID string) (*KubeConfig, error) { + req, err := k.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s/config", vkePath, vkeID), nil) + if err != nil { + return nil, err + } + + kc := new(KubeConfig) + if err = k.client.DoWithContext(ctx, req, &kc); err != nil { + return nil, err + } + + 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 9a2ce47d..aff8a958 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -257,7 +257,7 @@ github.com/ulikunitz/xz github.com/ulikunitz/xz/internal/hash github.com/ulikunitz/xz/internal/xlog github.com/ulikunitz/xz/lzma -# github.com/vultr/govultr/v2 v2.7.1 +# github.com/vultr/govultr/v2 v2.8.1 ## explicit github.com/vultr/govultr/v2 # github.com/zclconf/go-cty v1.9.1