From dedfe0b296e867f00b0409232ccc275b7ea66348 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Tue, 20 Feb 2024 16:13:22 -0500 Subject: [PATCH] Kubernetes: add support for nodepool labels (#296) --- kubernetes.go | 40 +++++++++++++++++++++------------------- kubernetes_test.go | 12 ++++++++++++ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/kubernetes.go b/kubernetes.go index 90ead5a..e6fae10 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -60,18 +60,19 @@ type Cluster struct { // 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"` - Plan string `json:"plan"` - Status string `json:"status"` - NodeQuantity int `json:"node_quantity"` - MinNodes int `json:"min_nodes"` - MaxNodes int `json:"max_nodes"` - AutoScaler bool `json:"auto_scaler"` - Tag string `json:"tag"` - Nodes []Node `json:"nodes"` + ID string `json:"id"` + DateCreated string `json:"date_created"` + DateUpdated string `json:"date_updated"` + Label string `json:"label"` + Plan string `json:"plan"` + Status string `json:"status"` + NodeQuantity int `json:"node_quantity"` + MinNodes int `json:"min_nodes"` + MaxNodes int `json:"max_nodes"` + AutoScaler bool `json:"auto_scaler"` + Tag string `json:"tag"` + Labels map[string]string `json:"labels"` + Nodes []Node `json:"nodes"` } // Node represents a node that will live within a nodepool @@ -104,13 +105,14 @@ type ClusterReqUpdate struct { // NodePoolReq struct used to create a node pool type NodePoolReq struct { - NodeQuantity int `json:"node_quantity"` - Label string `json:"label"` - Plan string `json:"plan"` - Tag string `json:"tag"` - MinNodes int `json:"min_nodes,omitempty"` - MaxNodes int `json:"max_nodes,omitempty"` - AutoScaler *bool `json:"auto_scaler"` + NodeQuantity int `json:"node_quantity"` + Label string `json:"label"` + Plan string `json:"plan"` + Tag string `json:"tag"` + MinNodes int `json:"min_nodes,omitempty"` + MaxNodes int `json:"max_nodes,omitempty"` + AutoScaler *bool `json:"auto_scaler"` + Labels map[string]string `json:"labels,omitempty"` } // NodePoolReqUpdate struct used to update a node pool diff --git a/kubernetes_test.go b/kubernetes_test.go index 20c4690..7aec749 100644 --- a/kubernetes_test.go +++ b/kubernetes_test.go @@ -378,6 +378,10 @@ func TestKubernetesHandler_CreateNodePool(t *testing.T) { "max_nodes": 2, "auto_scaler": true, "tag": "mytag", + "labels": { + "vultr.com/label1": "value1", + "vultr.com/label2": "value2" + }, "nodes": [ { "id": "3e1ca1e0-25be-4977-907a-3dee42b9bb15", @@ -396,6 +400,10 @@ func TestKubernetesHandler_CreateNodePool(t *testing.T) { Label: "nodepool-48959140", Plan: "vc2-1c-2gb", Tag: "mytag", + Labels: map[string]string{ + "vultr.com/label1": "value1", + "vultr.com/label2": "value2", + }, } np, _, err := client.Kubernetes.CreateNodePool(ctx, "1", createReq) if err != nil { @@ -413,6 +421,10 @@ func TestKubernetesHandler_CreateNodePool(t *testing.T) { MaxNodes: 2, AutoScaler: true, Tag: "mytag", + Labels: map[string]string{ + "vultr.com/label1": "value1", + "vultr.com/label2": "value2", + }, Nodes: []Node{ { ID: "3e1ca1e0-25be-4977-907a-3dee42b9bb15",