From f4cb7ff1296f3de4deaa3d1052968fd1035b5d62 Mon Sep 17 00:00:00 2001 From: Oliver Love Date: Tue, 28 May 2024 16:45:57 -0400 Subject: [PATCH 1/5] CON-10347 --- kubernetes.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/kubernetes.go b/kubernetes.go index 38c380a5..81d6de87 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -76,18 +76,20 @@ type KubernetesClusterCreateRequest struct { NodePools []*KubernetesNodePoolCreateRequest `json:"node_pools,omitempty"` - MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy"` - AutoUpgrade bool `json:"auto_upgrade"` - SurgeUpgrade bool `json:"surge_upgrade"` + MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy"` + AutoUpgrade bool `json:"auto_upgrade"` + SurgeUpgrade bool `json:"surge_upgrade"` + ControlPlanePermission *KubernetesControlPlanePermission `json:"control_plane_permission,omitempty"` } // KubernetesClusterUpdateRequest represents a request to update a Kubernetes cluster. type KubernetesClusterUpdateRequest struct { - Name string `json:"name,omitempty"` - Tags []string `json:"tags,omitempty"` - MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy,omitempty"` - AutoUpgrade *bool `json:"auto_upgrade,omitempty"` - SurgeUpgrade bool `json:"surge_upgrade,omitempty"` + Name string `json:"name,omitempty"` + Tags []string `json:"tags,omitempty"` + MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy,omitempty"` + AutoUpgrade *bool `json:"auto_upgrade,omitempty"` + SurgeUpgrade bool `json:"surge_upgrade,omitempty"` + ControlPlanePermission *KubernetesControlPlanePermission `json:"control_plane_permission,omitempty"` // Convert cluster to run highly available control plane HA *bool `json:"ha,omitempty"` @@ -240,6 +242,12 @@ type KubernetesMaintenancePolicy struct { Day KubernetesMaintenancePolicyDay `json:"day"` } +// KubernetesControlPlanePermission represents Kubernetes cluster control plane permission. +type KubernetesControlPlanePermission struct { + Enabled *bool `json:"enabled"` + AllowedAddresses []string `json:"allowed_addresses"` +} + // KubernetesMaintenancePolicyDay represents the possible days of a maintenance // window type KubernetesMaintenancePolicyDay int From a913fe518833c0c5a2bb7fe9c730e6a48e2eb0cf Mon Sep 17 00:00:00 2001 From: Oliver Love Date: Tue, 28 May 2024 16:52:24 -0400 Subject: [PATCH 2/5] CON-10347 --- kubernetes.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kubernetes.go b/kubernetes.go index 81d6de87..e275fa10 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -203,10 +203,11 @@ type KubernetesCluster struct { NodePools []*KubernetesNodePool `json:"node_pools,omitempty"` - MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy,omitempty"` - AutoUpgrade bool `json:"auto_upgrade,omitempty"` - SurgeUpgrade bool `json:"surge_upgrade,omitempty"` - RegistryEnabled bool `json:"registry_enabled,omitempty"` + MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy,omitempty"` + AutoUpgrade bool `json:"auto_upgrade,omitempty"` + SurgeUpgrade bool `json:"surge_upgrade,omitempty"` + RegistryEnabled bool `json:"registry_enabled,omitempty"` + ControlPlanePermission *KubernetesControlPlanePermission `json:"control_plane_permission,omitempty"` Status *KubernetesClusterStatus `json:"status,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` From 23d4ed83425db0a8dbd1877c0cead3b817a90ae2 Mon Sep 17 00:00:00 2001 From: Oliver Love Date: Tue, 28 May 2024 16:59:04 -0400 Subject: [PATCH 3/5] CON-10347 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ec066808..85a819c6 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/digitalocean/godo +module github.com/lldrlove/godo go 1.20 From c20b7cd0ffc84dd922b2418dd9f5d44c7b0d907b Mon Sep 17 00:00:00 2001 From: Oliver Love Date: Tue, 4 Jun 2024 10:35:59 -0400 Subject: [PATCH 4/5] CON-10347 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 85a819c6..ec066808 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/lldrlove/godo +module github.com/digitalocean/godo go 1.20 From 25312d8f7edc5438f080bba84134ca83fcc1bbc0 Mon Sep 17 00:00:00 2001 From: Oliver Love Date: Tue, 4 Jun 2024 12:22:05 -0400 Subject: [PATCH 5/5] CON-10347 add test --- kubernetes_test.go | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/kubernetes_test.go b/kubernetes_test.go index 2a542817..84903bb4 100644 --- a/kubernetes_test.go +++ b/kubernetes_test.go @@ -542,6 +542,7 @@ func TestKubernetesClusters_Create(t *testing.T) { defer teardown() kubeSvc := client.Kubernetes + enabled := true want := &KubernetesCluster{ ID: "8d91899c-0739-4a1a-acc5-deadbeefbb8f", @@ -568,6 +569,12 @@ func TestKubernetesClusters_Create(t *testing.T) { StartTime: "00:00", Day: KubernetesMaintenanceDayMonday, }, + ControlPlanePermission: &KubernetesControlPlanePermission{ + Enabled: &enabled, + AllowedAddresses: []string{ + "1.2.3.4/32", + }, + }, } createRequest := &KubernetesClusterCreateRequest{ Name: want.Name, @@ -625,7 +632,13 @@ func TestKubernetesClusters_Create(t *testing.T) { "maintenance_policy": { "start_time": "00:00", "day": "monday" - } + }, + "control_plane_permission": { + "enabled": true, + "allowed_addresses": [ + "1.2.3.4/32" + ] + } } }` @@ -755,6 +768,7 @@ func TestKubernetesClusters_Update(t *testing.T) { defer teardown() kubeSvc := client.Kubernetes + enabled := true want := &KubernetesCluster{ ID: "8d91899c-0739-4a1a-acc5-deadbeefbb8f", @@ -783,12 +797,24 @@ func TestKubernetesClusters_Update(t *testing.T) { StartTime: "00:00", Day: KubernetesMaintenanceDayMonday, }, + ControlPlanePermission: &KubernetesControlPlanePermission{ + Enabled: &enabled, + AllowedAddresses: []string{ + "1.2.3.4/32", + }, + }, } updateRequest := &KubernetesClusterUpdateRequest{ Name: want.Name, Tags: want.Tags, MaintenancePolicy: want.MaintenancePolicy, SurgeUpgrade: true, + ControlPlanePermission: &KubernetesControlPlanePermission{ + Enabled: &enabled, + AllowedAddresses: []string{ + "1.2.3.4/32", + }, + }, } jBlob := ` @@ -824,11 +850,17 @@ func TestKubernetesClusters_Update(t *testing.T) { "maintenance_policy": { "start_time": "00:00", "day": "monday" - } + }, + "control_plane_permission": { + "enabled": true, + "allowed_addresses": [ + "1.2.3.4/32" + ] + } } }` - expectedReqJSON := `{"name":"antoine-test-cluster","tags":["cluster-tag-1","cluster-tag-2"],"maintenance_policy":{"start_time":"00:00","duration":"","day":"monday"},"surge_upgrade":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_permission":{"enabled":true,"allowed_addresses":["1.2.3.4/32"]}} ` mux.HandleFunc("/v2/kubernetes/clusters/8d91899c-0739-4a1a-acc5-deadbeefbb8f", func(w http.ResponseWriter, r *http.Request) {