Skip to content

Commit

Permalink
Add support for LKE HA Control Planes (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
LBGarber authored Nov 10, 2021
1 parent 05fb9cb commit b637283
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 61 deletions.
42 changes: 26 additions & 16 deletions lke_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,33 @@ const (

// LKECluster represents a LKECluster object
type LKECluster struct {
ID int `json:"id"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Label string `json:"label"`
Region string `json:"region"`
Status LKEClusterStatus `json:"status"`
K8sVersion string `json:"k8s_version"`
Tags []string `json:"tags"`
ID int `json:"id"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Label string `json:"label"`
Region string `json:"region"`
Status LKEClusterStatus `json:"status"`
K8sVersion string `json:"k8s_version"`
Tags []string `json:"tags"`
ControlPlane LKEClusterControlPlane `json:"control_plane"`
}

// LKEClusterCreateOptions fields are those accepted by CreateLKECluster
type LKEClusterCreateOptions struct {
NodePools []LKEClusterPoolCreateOptions `json:"node_pools"`
Label string `json:"label"`
Region string `json:"region"`
K8sVersion string `json:"k8s_version"`
Tags []string `json:"tags,omitempty"`
NodePools []LKEClusterPoolCreateOptions `json:"node_pools"`
Label string `json:"label"`
Region string `json:"region"`
K8sVersion string `json:"k8s_version"`
Tags []string `json:"tags,omitempty"`
ControlPlane *LKEClusterControlPlane `json:"control_plane,omitempty"`
}

// LKEClusterUpdateOptions fields are those accepted by UpdateLKECluster
type LKEClusterUpdateOptions struct {
K8sVersion string `json:"k8s_version,omitempty"`
Label string `json:"label,omitempty"`
Tags *[]string `json:"tags,omitempty"`
K8sVersion string `json:"k8s_version,omitempty"`
Label string `json:"label,omitempty"`
Tags *[]string `json:"tags,omitempty"`
ControlPlane *LKEClusterControlPlane `json:"control_plane,omitempty"`
}

// LKEClusterAPIEndpoint fields are those returned by ListLKEClusterAPIEndpoints
Expand All @@ -56,6 +59,11 @@ type LKEClusterKubeconfig struct {
KubeConfig string `json:"kubeconfig"`
}

// LKEClusterControlPlane fields contained within the `control_plane` attribute of an LKE cluster.
type LKEClusterControlPlane struct {
HighAvailability bool `json:"high_availability"`
}

// LKEVersion fields are those returned by GetLKEVersion
type LKEVersion struct {
ID string `json:"id"`
Expand Down Expand Up @@ -89,6 +97,7 @@ func (i LKECluster) GetCreateOptions() (o LKEClusterCreateOptions) {
o.Region = i.Region
o.K8sVersion = i.K8sVersion
o.Tags = i.Tags
o.ControlPlane = &i.ControlPlane
// @TODO copy NodePools?
return
}
Expand All @@ -98,6 +107,7 @@ func (i LKECluster) GetUpdateOptions() (o LKEClusterUpdateOptions) {
o.K8sVersion = i.K8sVersion
o.Label = i.Label
o.Tags = &i.Tags
o.ControlPlane = &i.ControlPlane
return
}

Expand Down
1 change: 1 addition & 0 deletions template.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package linodego
Expand Down
34 changes: 17 additions & 17 deletions test/integration/fixtures/TestUpdateLKECluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
version: 1
interactions:
- request:
body: '{"node_pools":[{"count":1,"type":"g6-standard-2","disks":null}],"label":"a83ef3go2h76-linodego-testing","region":"us-central","k8s_version":"1.17","tags":["testing"]}'
body: '{"node_pools":[{"count":1,"type":"g6-standard-2","disks":null,"tags":["test"]}],"label":"5n5lxn8931co-linodego-testing","region":"us-central","k8s_version":"1.21","tags":["testing"]}'
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters
method: POST
response:
body: '{"id": 19394, "status": "ready", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "label": "a83ef3go2h76-linodego-testing", "region": "us-central", "k8s_version": "1.17", "tags": ["testing"]}'
body: '{"id": 42668, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "5n5lxn8931co-linodego-testing", "region": "us-central",
"k8s_version": "1.21", "control_plane": {"high_availability": false}, "tags":
["testing"]}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -29,7 +32,7 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "210"
- "257"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand All @@ -49,27 +52,28 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
- request:
body: '{"k8s_version":"1.17","label":"newa83ef3go2h76-linodego-testing","tags":["test=true"]}'
body: '{"k8s_version":"1.21","label":"new5n5lxn8931co-linodego-testing","tags":["test=true"],"control_plane":{"high_availability":true}}'
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/19394
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/42668
method: PUT
response:
body: '{"id": 19394, "status": "ready", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "label": "newa83ef3go2h76-linodego-testing", "region": "us-central", "k8s_version": "1.17", "tags": ["test=true"]}'
body: '{"id": 42668, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "new5n5lxn8931co-linodego-testing", "region":
"us-central", "k8s_version": "1.21", "control_plane": {"high_availability":
true}, "tags": ["test=true"]}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -84,7 +88,7 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "215"
- "261"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand All @@ -104,8 +108,6 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand All @@ -120,8 +122,8 @@ interactions:
Content-Type:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/19394
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/42668
method: DELETE
response:
body: '{}'
Expand Down Expand Up @@ -159,8 +161,6 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand Down
43 changes: 16 additions & 27 deletions test/integration/fixtures/TestUpdateLKEClusterPool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ interactions:
url: https://api.linode.com/v4beta/lke/clusters
method: POST
response:
body: '{"id": 33992, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
body: '{"id": 42667, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "xf886ld17qx5-linodego-testing", "region": "us-central",
"k8s_version": "1.21", "tags": ["testing"]}'
"k8s_version": "1.21", "control_plane": {"high_availability": false}, "tags":
["testing"]}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -31,7 +32,7 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "210"
- "257"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand All @@ -51,8 +52,6 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand All @@ -68,11 +67,11 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/33992/pools
url: https://api.linode.com/v4beta/lke/clusters/42667/pools
method: POST
response:
body: '{"id": 52528, "type": "g6-standard-2", "count": 2, "nodes": [{"id": "52528-6112b28a96bd",
"instance_id": null, "status": "not_ready"}, {"id": "52528-6112b28aa0c0", "instance_id":
body: '{"id": 69468, "type": "g6-standard-2", "count": 2, "nodes": [{"id": "69468-618ad2665892",
"instance_id": null, "status": "not_ready"}, {"id": "69468-618ad26662b4", "instance_id":
null, "status": "not_ready"}], "disks": [{"size": 1000, "type": "ext4"}], "autoscaler":
{"enabled": false, "min": 2, "max": 2}, "tags": ["testing"]}'
headers:
Expand Down Expand Up @@ -109,8 +108,6 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand All @@ -126,11 +123,11 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/33992/pools/52528
url: https://api.linode.com/v4beta/lke/clusters/42667/pools/69468
method: PUT
response:
body: '{"id": 52528, "type": "g6-standard-2", "count": 2, "nodes": [{"id": "52528-6112b28a96bd",
"instance_id": null, "status": "not_ready"}, {"id": "52528-6112b28aa0c0", "instance_id":
body: '{"id": 69468, "type": "g6-standard-2", "count": 2, "nodes": [{"id": "69468-618ad2665892",
"instance_id": null, "status": "not_ready"}, {"id": "69468-618ad26662b4", "instance_id":
null, "status": "not_ready"}], "disks": [{"size": 1000, "type": "ext4"}], "autoscaler":
{"enabled": true, "min": 2, "max": 5}, "tags": []}'
headers:
Expand Down Expand Up @@ -167,8 +164,6 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand All @@ -184,12 +179,12 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/33992/pools/52528
url: https://api.linode.com/v4beta/lke/clusters/42667/pools/69468
method: PUT
response:
body: '{"id": 52528, "type": "g6-standard-2", "count": 3, "nodes": [{"id": "52528-6112b28a96bd",
"instance_id": null, "status": "not_ready"}, {"id": "52528-6112b28aa0c0", "instance_id":
null, "status": "not_ready"}, {"id": "52528-6112b28b5ef5", "instance_id": null,
body: '{"id": 69468, "type": "g6-standard-2", "count": 3, "nodes": [{"id": "69468-618ad2665892",
"instance_id": null, "status": "not_ready"}, {"id": "69468-618ad26662b4", "instance_id":
null, "status": "not_ready"}, {"id": "69468-618ad266da27", "instance_id": null,
"status": "not_ready"}], "disks": [{"size": 1000, "type": "ext4"}], "autoscaler":
{"enabled": true, "min": 2, "max": 5}, "tags": ["bar", "foo", "test"]}'
headers:
Expand Down Expand Up @@ -226,8 +221,6 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand All @@ -243,7 +236,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/33992/pools/52528
url: https://api.linode.com/v4beta/lke/clusters/42667/pools/69468
method: DELETE
response:
body: '{}'
Expand Down Expand Up @@ -281,8 +274,6 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand All @@ -298,7 +289,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/33992
url: https://api.linode.com/v4beta/lke/clusters/42667
method: DELETE
response:
body: '{}'
Expand Down Expand Up @@ -336,8 +327,6 @@ interactions:
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand Down
10 changes: 9 additions & 1 deletion test/integration/lke_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ func TestUpdateLKECluster(t *testing.T) {

updatedTags := []string{"test=true"}
updatedLabel := "new" + cluster.Label
updatedK8sVersion := "1.17"
updatedK8sVersion := "1.21"
updatedControlPlane := &linodego.LKEClusterControlPlane{HighAvailability: true}
updatedCluster, err := client.UpdateLKECluster(context.TODO(), cluster.ID, linodego.LKEClusterUpdateOptions{
Tags: &updatedTags,
Label: updatedLabel,
K8sVersion: updatedK8sVersion,
ControlPlane: updatedControlPlane,
})
if err != nil {
t.Fatalf("failed to update LKE Cluster (%d): %s", cluster.ID, err)
Expand All @@ -93,12 +95,18 @@ func TestUpdateLKECluster(t *testing.T) {
if updatedCluster.Label != updatedLabel {
t.Errorf("expected label to be updated to %q; got %q", updatedLabel, updatedCluster.Label)
}

if updatedCluster.K8sVersion != updatedK8sVersion {
t.Errorf("expected k8s version to be updated to %q; got %q", updatedK8sVersion, updatedCluster.K8sVersion)
}

if !reflect.DeepEqual(updatedTags, updatedCluster.Tags) {
t.Errorf("expected tags to be updated to %#v; got %#v", updatedTags, updatedCluster.Tags)
}

if !reflect.DeepEqual(*updatedControlPlane, updatedCluster.ControlPlane) {
t.Errorf("expected control plane to be updated to %#v; got %#v", updatedControlPlane, updatedCluster.ControlPlane)
}
}

func TestRecycleLKEClusterNodes(t *testing.T) {
Expand Down

0 comments on commit b637283

Please sign in to comment.