Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubernetes - use bool pointers to parse requests correctly #548

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type KubernetesClusterUpdateRequest struct {
Tags []string `json:"tags,omitempty"`
MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy,omitempty"`
AutoUpgrade *bool `json:"auto_upgrade,omitempty"`
SurgeUpgrade bool `json:"surge_upgrade,omitempty"`
SurgeUpgrade *bool `json:"surge_upgrade,omitempty"`
}

// KubernetesClusterDeleteSelectiveRequest represents a delete selective request to delete a cluster and it's associated resources.
Expand Down Expand Up @@ -126,7 +126,7 @@ type KubernetesNodePoolCreateRequest struct {
Tags []string `json:"tags,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Taints []Taint `json:"taints,omitempty"`
AutoScale bool `json:"auto_scale,omitempty"`
AutoScale *bool `json:"auto_scale,omitempty"`
MinNodes int `json:"min_nodes,omitempty"`
MaxNodes int `json:"max_nodes,omitempty"`
}
Expand Down
97 changes: 93 additions & 4 deletions kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func TestKubernetesClusters_Create(t *testing.T) {
Name: want.NodePools[0].Name,
Tags: want.NodePools[0].Tags,
Labels: want.NodePools[0].Labels,
AutoScale: want.NodePools[0].AutoScale,
AutoScale: &want.NodePools[0].AutoScale,
MinNodes: want.NodePools[0].MinNodes,
MaxNodes: want.NodePools[0].MaxNodes,
},
Expand Down Expand Up @@ -690,7 +690,7 @@ func TestKubernetesClusters_Create_AutoScalePool(t *testing.T) {
Count: want.NodePools[0].Count,
Name: want.NodePools[0].Name,
Tags: want.NodePools[0].Tags,
AutoScale: want.NodePools[0].AutoScale,
AutoScale: &want.NodePools[0].AutoScale,
MinNodes: want.NodePools[0].MinNodes,
MaxNodes: want.NodePools[0].MaxNodes,
},
Expand Down Expand Up @@ -787,7 +787,7 @@ func TestKubernetesClusters_Update(t *testing.T) {
Name: want.Name,
Tags: want.Tags,
MaintenancePolicy: want.MaintenancePolicy,
SurgeUpgrade: true,
SurgeUpgrade: boolPtr(true),
}

jBlob := `
Expand Down Expand Up @@ -936,6 +936,95 @@ func TestKubernetesClusters_Update_FalseAutoUpgrade(t *testing.T) {
require.Equal(t, want, got)
}

func TestKubernetesClusters_Update_FalseSurgeUpgrade(t *testing.T) {
setup()
defer teardown()

kubeSvc := client.Kubernetes

want := &KubernetesCluster{
ID: "8d91899c-0739-4a1a-acc5-deadbeefbb8f",
Name: "antoine-test-cluster",
RegionSlug: "s2r1",
VersionSlug: "1.10.0-gen0",
ClusterSubnet: "10.244.0.0/16",
ServiceSubnet: "10.245.0.0/16",
Tags: []string{"cluster-tag-1", "cluster-tag-2"},
VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6",
NodePools: []*KubernetesNodePool{
{
ID: "8d91899c-0739-4a1a-acc5-deadbeefbb8a",
Size: "s-1vcpu-1gb",
Count: 2,
Name: "pool-a",
Tags: []string{"tag-1"},
},
},
MaintenancePolicy: &KubernetesMaintenancePolicy{
StartTime: "00:00",
Day: KubernetesMaintenanceDayMonday,
},
SurgeUpgrade: false,
}
updateRequest := &KubernetesClusterUpdateRequest{
SurgeUpgrade: boolPtr(false),
}

jBlob := `
{
"kubernetes_cluster": {
"id": "8d91899c-0739-4a1a-acc5-deadbeefbb8f",
"name": "antoine-test-cluster",
"region": "s2r1",
"version": "1.10.0-gen0",
"cluster_subnet": "10.244.0.0/16",
"service_subnet": "10.245.0.0/16",
"tags": [
"cluster-tag-1",
"cluster-tag-2"
],
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6",
"surge_upgrade": false,
"node_pools": [
{
"id": "8d91899c-0739-4a1a-acc5-deadbeefbb8a",
"size": "s-1vcpu-1gb",
"count": 2,
"name": "pool-a",
"tags": [
"tag-1"
]
}
],
"maintenance_policy": {
"start_time": "00:00",
"day": "monday"
}
}
}`

expectedReqJSON := `{"surge_upgrade":false}
`

mux.HandleFunc("/v2/kubernetes/clusters/8d91899c-0739-4a1a-acc5-deadbeefbb8f", func(w http.ResponseWriter, r *http.Request) {
buf := new(bytes.Buffer)
buf.ReadFrom(r.Body)
require.Equal(t, expectedReqJSON, buf.String())

v := new(KubernetesClusterUpdateRequest)
err := json.NewDecoder(buf).Decode(v)
require.NoError(t, err)

testMethod(t, r, http.MethodPut)
require.Equal(t, v, updateRequest)
fmt.Fprint(w, jBlob)
})

got, _, err := kubeSvc.Update(ctx, "8d91899c-0739-4a1a-acc5-deadbeefbb8f", updateRequest)
require.NoError(t, err)
require.Equal(t, want, got)
}

func TestKubernetesClusters_Upgrade(t *testing.T) {
setup()
defer teardown()
Expand Down Expand Up @@ -1161,7 +1250,7 @@ func TestKubernetesClusters_CreateNodePool_AutoScale(t *testing.T) {
Count: want.Count,
Name: want.Name,
Tags: want.Tags,
AutoScale: want.AutoScale,
AutoScale: &(want.AutoScale),
MinNodes: want.MinNodes,
MaxNodes: want.MaxNodes,
}
Expand Down