Skip to content

Commit

Permalink
kubernetes - add support for surge upgrades (digitalocean#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
varshavaradarajan authored Jul 16, 2020
1 parent c46bc28 commit d36624d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
8 changes: 4 additions & 4 deletions 1-click.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const oneClickBasePath = "v2/1-clicks"
// See: https://developers.digitalocean.com/documentation/v2/#1-click-applications
type OneClickService interface {
List(context.Context, string) ([]*OneClick, *Response, error)
InstallKubernetes(context.Context, *InstallKubernetesAppsRequest)(*InstallKubernetesAppsResponse, *Response, error)
InstallKubernetes(context.Context, *InstallKubernetesAppsRequest) (*InstallKubernetesAppsResponse, *Response, error)
}

var _ OneClickService = &OneClickServiceOp{}
Expand Down Expand Up @@ -42,7 +42,7 @@ type InstallKubernetesAppsRequest struct {

// InstallKubernetesAppsResponse is the response of a kubernetes 1-click install request
type InstallKubernetesAppsResponse struct {
Message string `json:"message"`
Message string `json:"message"`
}

// List returns a list of the available 1-click applications.
Expand All @@ -64,8 +64,8 @@ func (ocs *OneClickServiceOp) List(ctx context.Context, oneClickType string) ([]
}

// InstallKubernetes installs an addon on a kubernetes cluster
func (ocs *OneClickServiceOp) InstallKubernetes(ctx context.Context, install *InstallKubernetesAppsRequest ) (*InstallKubernetesAppsResponse, *Response, error) {
path := fmt.Sprintf(oneClickBasePath+"/kubernetes")
func (ocs *OneClickServiceOp) InstallKubernetes(ctx context.Context, install *InstallKubernetesAppsRequest) (*InstallKubernetesAppsResponse, *Response, error) {
path := fmt.Sprintf(oneClickBasePath + "/kubernetes")

req, err := ocs.client.NewRequest(ctx, http.MethodPost, path, install)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions 1-click_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var testMessageJSON = `

var kubernetesPayload = &InstallKubernetesAppsRequest{
ClusterUUID: "123",
Slugs: []string{"slug1", "slug2"},
Slugs: []string{"slug1", "slug2"},
}

func TestOneClick_List(t *testing.T) {
Expand Down Expand Up @@ -62,15 +62,13 @@ func TestOneClick_List(t *testing.T) {
assert.Equal(t, want, got)
}


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

svc := client.OneClick
path := "/v2/1-clicks/kubernetes"


mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, testMessageJSON)
Expand Down
3 changes: 3 additions & 0 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type KubernetesClusterCreateRequest struct {

MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy"`
AutoUpgrade bool `json:"auto_upgrade"`
SurgeUpgrade bool `json:"surge_upgrade"`
}

// KubernetesClusterUpdateRequest represents a request to update a Kubernetes cluster.
Expand All @@ -74,6 +75,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"`
}

// KubernetesClusterUpgradeRequest represents a request to upgrade a Kubernetes cluster.
Expand Down Expand Up @@ -143,6 +145,7 @@ type KubernetesCluster struct {

MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy,omitempty"`
AutoUpgrade bool `json:"auto_upgrade,omitempty"`
SurgeUpgrade bool `json:"surge_upgrade,omitempty"`

Status *KubernetesClusterStatus `json:"status,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
Expand Down
18 changes: 12 additions & 6 deletions kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ func TestKubernetesClusters_Create(t *testing.T) {
ServiceSubnet: "10.245.0.0/16",
Tags: []string{"cluster-tag-1", "cluster-tag-2"},
VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6",
SurgeUpgrade: true,
NodePools: []*KubernetesNodePool{
&KubernetesNodePool{
ID: "8d91899c-0739-4a1a-acc5-deadbeefbb8a",
Expand All @@ -538,11 +539,12 @@ func TestKubernetesClusters_Create(t *testing.T) {
},
}
createRequest := &KubernetesClusterCreateRequest{
Name: want.Name,
RegionSlug: want.RegionSlug,
VersionSlug: want.VersionSlug,
Tags: want.Tags,
VPCUUID: want.VPCUUID,
Name: want.Name,
RegionSlug: want.RegionSlug,
VersionSlug: want.VersionSlug,
Tags: want.Tags,
VPCUUID: want.VPCUUID,
SurgeUpgrade: true,
NodePools: []*KubernetesNodePoolCreateRequest{
&KubernetesNodePoolCreateRequest{
Size: want.NodePools[0].Size,
Expand Down Expand Up @@ -572,6 +574,7 @@ func TestKubernetesClusters_Create(t *testing.T) {
"cluster-tag-2"
],
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6",
"surge_upgrade": true,
"node_pools": [
{
"id": "8d91899c-0739-4a1a-acc5-deadbeefbb8a",
Expand Down Expand Up @@ -729,6 +732,7 @@ func TestKubernetesClusters_Update(t *testing.T) {
ServiceSubnet: "10.245.0.0/16",
Tags: []string{"cluster-tag-1", "cluster-tag-2"},
VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6",
SurgeUpgrade: true,
NodePools: []*KubernetesNodePool{
&KubernetesNodePool{
ID: "8d91899c-0739-4a1a-acc5-deadbeefbb8a",
Expand All @@ -750,6 +754,7 @@ func TestKubernetesClusters_Update(t *testing.T) {
Name: want.Name,
Tags: want.Tags,
MaintenancePolicy: want.MaintenancePolicy,
SurgeUpgrade: true,
}

jBlob := `
Expand All @@ -766,6 +771,7 @@ func TestKubernetesClusters_Update(t *testing.T) {
"cluster-tag-2"
],
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6",
"surge_upgrade": true,
"node_pools": [
{
"id": "8d91899c-0739-4a1a-acc5-deadbeefbb8a",
Expand All @@ -787,7 +793,7 @@ func TestKubernetesClusters_Update(t *testing.T) {
}
}`

expectedReqJSON := `{"name":"antoine-test-cluster","tags":["cluster-tag-1","cluster-tag-2"],"maintenance_policy":{"start_time":"00:00","duration":"","day":"monday"}}
expectedReqJSON := `{"name":"antoine-test-cluster","tags":["cluster-tag-1","cluster-tag-2"],"maintenance_policy":{"start_time":"00:00","duration":"","day":"monday"},"surge_upgrade":true}
`

mux.HandleFunc("/v2/kubernetes/clusters/8d91899c-0739-4a1a-acc5-deadbeefbb8f", func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit d36624d

Please sign in to comment.