Skip to content

Commit

Permalink
add flags for doks routing-agent plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
m3co-code committed Feb 18, 2025
1 parent 439be09 commit ec751cf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
8 changes: 8 additions & 0 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
38 changes: 34 additions & 4 deletions kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -824,6 +845,9 @@ func TestKubernetesClusters_Update(t *testing.T) {
ScaleDownUtilizationThreshold: &scaleDownUtilizationThreshold,
ScaleDownUnneededTime: &scaleDownUnneededTime,
},
RoutingAgent: &KubernetesRoutingAgent{
Enabled: PtrTo(true),
},
}
updateRequest := &KubernetesClusterUpdateRequest{
Name: want.Name,
Expand All @@ -840,6 +864,9 @@ func TestKubernetesClusters_Update(t *testing.T) {
ScaleDownUtilizationThreshold: &scaleDownUtilizationThreshold,
ScaleDownUnneededTime: &scaleDownUnneededTime,
},
RoutingAgent: &KubernetesRoutingAgent{
Enabled: PtrTo(true),
},
}

jBlob := `
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ec751cf

Please sign in to comment.