From 07b01c2c16f3ac3dd82628608ea5e3ea69d6e563 Mon Sep 17 00:00:00 2001 From: Marco Jantke Date: Tue, 18 Feb 2025 16:10:07 +0100 Subject: [PATCH] add flags for doks routing-agent plugin (#786) --- kubernetes.go | 8 ++++++++ kubernetes_test.go | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/kubernetes.go b/kubernetes.go index 1147868..4a1530a 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -84,6 +84,7 @@ type KubernetesClusterCreateRequest struct { SurgeUpgrade bool `json:"surge_upgrade"` ControlPlaneFirewall *KubernetesControlPlaneFirewall `json:"control_plane_firewall,omitempty"` ClusterAutoscalerConfiguration *KubernetesClusterAutoscalerConfiguration `json:"cluster_autoscaler_configuration,omitempty"` + RoutingAgent *KubernetesRoutingAgent `json:"routing_agent,omitempty"` } // KubernetesClusterUpdateRequest represents a request to update a Kubernetes cluster. @@ -95,6 +96,7 @@ type KubernetesClusterUpdateRequest struct { SurgeUpgrade bool `json:"surge_upgrade,omitempty"` ControlPlaneFirewall *KubernetesControlPlaneFirewall `json:"control_plane_firewall,omitempty"` ClusterAutoscalerConfiguration *KubernetesClusterAutoscalerConfiguration `json:"cluster_autoscaler_configuration,omitempty"` + RoutingAgent *KubernetesRoutingAgent `json:"routing_agent,omitempty"` // Convert cluster to run highly available control plane HA *bool `json:"ha,omitempty"` @@ -214,6 +216,7 @@ type KubernetesCluster struct { RegistryEnabled bool `json:"registry_enabled,omitempty"` ControlPlaneFirewall *KubernetesControlPlaneFirewall `json:"control_plane_firewall,omitempty"` ClusterAutoscalerConfiguration *KubernetesClusterAutoscalerConfiguration `json:"cluster_autoscaler_configuration,omitempty"` + RoutingAgent *KubernetesRoutingAgent `json:"routing_agent,omitempty"` Status *KubernetesClusterStatus `json:"status,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` @@ -256,6 +259,11 @@ type KubernetesControlPlaneFirewall struct { AllowedAddresses []string `json:"allowed_addresses"` } +// KubernetesRoutingAgent represents information about the routing-agent cluster plugin. +type KubernetesRoutingAgent struct { + Enabled *bool `json:"enabled"` +} + // KubernetesClusterAutoscalerConfiguration represents Kubernetes cluster autoscaler configuration. type KubernetesClusterAutoscalerConfiguration struct { ScaleDownUtilizationThreshold *float64 `json:"scale_down_utilization_threshold"` diff --git a/kubernetes_test.go b/kubernetes_test.go index 0aa01d9..b59d7a2 100644 --- a/kubernetes_test.go +++ b/kubernetes_test.go @@ -32,6 +32,9 @@ func TestKubernetesClusters_ListClusters(t *testing.T) { Status: &KubernetesClusterStatus{ State: KubernetesClusterStatusRunning, }, + RoutingAgent: &KubernetesRoutingAgent{ + Enabled: PtrTo(true), + }, NodePools: []*KubernetesNodePool{ { ID: "1a17a012-cb31-4886-a787-deadbeef1191", @@ -122,6 +125,9 @@ func TestKubernetesClusters_ListClusters(t *testing.T) { "status": { "state": "running" }, + "routing_agent": { + "enabled": true + }, "node_pools": [ { "id": "1a17a012-cb31-4886-a787-deadbeef1191", @@ -263,6 +269,9 @@ func TestKubernetesClusters_Get(t *testing.T) { Status: &KubernetesClusterStatus{ State: KubernetesClusterStatusRunning, }, + RoutingAgent: &KubernetesRoutingAgent{ + Enabled: PtrTo(true), + }, NodePools: []*KubernetesNodePool{ { ID: "deadbeef-dead-beef-dead-deadbeefb4b3", @@ -314,6 +323,9 @@ func TestKubernetesClusters_Get(t *testing.T) { "status": { "state": "running" }, + "routing_agent": { + "enabled": true + }, "node_pools": [ { "id": "deadbeef-dead-beef-dead-deadbeefb4b3", @@ -559,6 +571,9 @@ func TestKubernetesClusters_Create(t *testing.T) { VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6", HA: true, SurgeUpgrade: true, + RoutingAgent: &KubernetesRoutingAgent{ + Enabled: PtrTo(true), + }, NodePools: []*KubernetesNodePool{ { ID: "8d91899c-0739-4a1a-acc5-deadbeefbb8a", @@ -594,6 +609,9 @@ func TestKubernetesClusters_Create(t *testing.T) { ServiceSubnet: want.ServiceSubnet, SurgeUpgrade: true, HA: true, + RoutingAgent: &KubernetesRoutingAgent{ + Enabled: PtrTo(true), + }, NodePools: []*KubernetesNodePoolCreateRequest{ { Size: want.NodePools[0].Size, @@ -626,6 +644,9 @@ func TestKubernetesClusters_Create(t *testing.T) { "vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6", "ha": true, "surge_upgrade": true, + "routing_agent": { + "enabled": true + }, "node_pools": [ { "id": "8d91899c-0739-4a1a-acc5-deadbeefbb8a", @@ -824,6 +845,9 @@ func TestKubernetesClusters_Update(t *testing.T) { ScaleDownUtilizationThreshold: &scaleDownUtilizationThreshold, ScaleDownUnneededTime: &scaleDownUnneededTime, }, + RoutingAgent: &KubernetesRoutingAgent{ + Enabled: PtrTo(true), + }, } updateRequest := &KubernetesClusterUpdateRequest{ Name: want.Name, @@ -840,6 +864,9 @@ func TestKubernetesClusters_Update(t *testing.T) { ScaleDownUtilizationThreshold: &scaleDownUtilizationThreshold, ScaleDownUnneededTime: &scaleDownUnneededTime, }, + RoutingAgent: &KubernetesRoutingAgent{ + Enabled: PtrTo(true), + }, } jBlob := ` @@ -883,13 +910,16 @@ func TestKubernetesClusters_Update(t *testing.T) { ] }, "cluster_autoscaler_configuration": { - "scale_down_utilization_threshold": 0.2, - "scale_down_unneeded_time": "1m27s" - } + "scale_down_utilization_threshold": 0.2, + "scale_down_unneeded_time": "1m27s" + }, + "routing_agent": { + "enabled": true + } } }` - expectedReqJSON := `{"name":"antoine-test-cluster","tags":["cluster-tag-1","cluster-tag-2"],"maintenance_policy":{"start_time":"00:00","duration":"","day":"monday"},"surge_upgrade":true,"control_plane_firewall":{"enabled":true,"allowed_addresses":["1.2.3.4/32"]},"cluster_autoscaler_configuration":{"scale_down_utilization_threshold":0.2,"scale_down_unneeded_time":"1m27s"}} + expectedReqJSON := `{"name":"antoine-test-cluster","tags":["cluster-tag-1","cluster-tag-2"],"maintenance_policy":{"start_time":"00:00","duration":"","day":"monday"},"surge_upgrade":true,"control_plane_firewall":{"enabled":true,"allowed_addresses":["1.2.3.4/32"]},"cluster_autoscaler_configuration":{"scale_down_utilization_threshold":0.2,"scale_down_unneeded_time":"1m27s"},"routing_agent":{"enabled":true}} ` mux.HandleFunc("/v2/kubernetes/clusters/8d91899c-0739-4a1a-acc5-deadbeefbb8f", func(w http.ResponseWriter, r *http.Request) {