Skip to content

Commit ffcac8c

Browse files
authored
Merge pull request #143 from displague/latest-lke
Update LKE methods for GA LKE API
2 parents 81a6bb0 + 7cef056 commit ffcac8c

14 files changed

+248
-214
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
1414
.glide/
1515

16+
17+
# Common IDE paths
18+
.vscode/
19+
1620
vendor/**/
1721
.env
1822
coverage.txt

account_events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const (
9898
ActionLinodeConfigDelete EventAction = "linode_config_delete"
9999
ActionLinodeConfigUpdate EventAction = "linode_config_update"
100100
ActionLishBoot EventAction = "lish_boot"
101+
ActionLKENodeCreate EventAction = "lke_node_create"
101102
ActionLongviewClientCreate EventAction = "longviewclient_create"
102103
ActionLongviewClientDelete EventAction = "longviewclient_delete"
103104
ActionLongviewClientUpdate EventAction = "longviewclient_update"

client.go

Lines changed: 98 additions & 95 deletions
Large diffs are not rendered by default.

lke_cluster_pools.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const (
1818

1919
// LKEClusterPoolLinode represents a LKEClusterPoolLinode object
2020
type LKEClusterPoolLinode struct {
21-
ID string `json:"id"`
22-
Status LKELinodeStatus `json:"status"`
21+
ID string `json:"id"`
22+
InstanceID int `json:"instance_id"`
23+
Status LKELinodeStatus `json:"status"`
2324
}
2425

2526
// LKEClusterPool represents a LKEClusterPool object

lke_clusters.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ type LKEClusterCreateOptions struct {
4141

4242
// LKEClusterUpdateOptions fields are those accepted by UpdateLKECluster
4343
type LKEClusterUpdateOptions struct {
44-
Label string `json:"label,omitempty"`
44+
Label string `json:"label,omitempty"`
45+
Tags *[]string `json:"tags,omitempty"`
4546
}
4647

47-
// LKEClusterAPIEndpoint fields are those returned by GetLKEClusterAPIEndpoint
48+
// LKEClusterAPIEndpoint fields are those returned by ListLKEClusterAPIEndpoints
4849
type LKEClusterAPIEndpoint struct {
49-
Endpoints []string `json:"endpoints"`
50+
Endpoint string `json:"endpoint"`
5051
}
5152

5253
// LKEClusterKubeconfig fields are those returned by GetLKEClusterKubeconfig
@@ -94,6 +95,7 @@ func (i LKECluster) GetCreateOptions() (o LKEClusterCreateOptions) {
9495
// GetUpdateOptions converts a LKECluster to LKEClusterUpdateOptions for use in UpdateLKECluster
9596
func (i LKECluster) GetUpdateOptions() (o LKEClusterUpdateOptions) {
9697
o.Label = i.Label
98+
o.Tags = &i.Tags
9799
return
98100
}
99101

@@ -103,6 +105,12 @@ type LKEClustersPagedResponse struct {
103105
Data []LKECluster `json:"data"`
104106
}
105107

108+
// LKEClusterAPIEndpointsPagedResponse represents a paginated LKEClusterAPIEndpoints API response
109+
type LKEClusterAPIEndpointsPagedResponse struct {
110+
*PageOptions
111+
Data []LKEClusterAPIEndpoint `json:"data"`
112+
}
113+
106114
// LKEVersionsPagedResponse represents a paginated LKEVersion API response
107115
type LKEVersionsPagedResponse struct {
108116
*PageOptions
@@ -132,6 +140,20 @@ func (LKEVersionsPagedResponse) endpoint(c *Client) string {
132140
return endpoint
133141
}
134142

143+
// endpoint gets the endpoint URL for LKEClusterAPIEndpoints
144+
func (LKEClusterAPIEndpointsPagedResponse) endpointWithID(c *Client, id int) string {
145+
endpoint, err := c.LKEClusterAPIEndpoints.endpointWithID(id)
146+
if err != nil {
147+
panic(err)
148+
}
149+
return endpoint
150+
}
151+
152+
// appendData appends LKEClusterAPIEndpoints when processing paginated LKEClusterAPIEndpoints responses
153+
func (resp *LKEClusterAPIEndpointsPagedResponse) appendData(r *LKEClusterAPIEndpointsPagedResponse) {
154+
resp.Data = append(resp.Data, r.Data...)
155+
}
156+
135157
// appendData appends LKEVersions when processing paginated LKEVersion responses
136158
func (resp *LKEVersionsPagedResponse) appendData(r *LKEVersionsPagedResponse) {
137159
resp.Data = append(resp.Data, r.Data...)
@@ -226,18 +248,14 @@ func (c *Client) DeleteLKECluster(ctx context.Context, id int) error {
226248
return err
227249
}
228250

229-
// GetLKEClusterAPIEndpoint gets the API Endpoint for the LKE Cluster specified
230-
func (c *Client) GetLKEClusterAPIEndpoint(ctx context.Context, id int) (*LKEClusterAPIEndpoint, error) {
231-
e, err := c.LKEClusters.Endpoint()
251+
// ListLKEClusterAPIEndpoints gets the API Endpoint for the LKE Cluster specified
252+
func (c *Client) ListLKEClusterAPIEndpoints(ctx context.Context, clusterID int, opts *ListOptions) ([]LKEClusterAPIEndpoint, error) {
253+
response := LKEClusterAPIEndpointsPagedResponse{}
254+
err := c.listHelperWithID(ctx, &response, clusterID, opts)
232255
if err != nil {
233256
return nil, err
234257
}
235-
e = fmt.Sprintf("%s/%d/api-endpoint", e, id)
236-
r, err := coupleAPIErrors(c.R(ctx).SetResult(&LKEClusterAPIEndpoint{}).Get(e))
237-
if err != nil {
238-
return nil, err
239-
}
240-
return r.Result().(*LKEClusterAPIEndpoint), nil
258+
return response.Data, nil
241259
}
242260

243261
// GetLKEClusterKubeconfig gets the Kubeconfig for the LKE Cluster specified

pagination.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ func (c *Client) listHelperWithID(ctx context.Context, i interface{}, idRaw inte
348348
results = r.Result().(*InvoiceItemsPagedResponse).Results
349349
v.appendData(r.Result().(*InvoiceItemsPagedResponse))
350350
}
351+
case *LKEClusterAPIEndpointsPagedResponse:
352+
if r, err = coupleAPIErrors(req.SetResult(LKEClusterAPIEndpointsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil {
353+
pages = r.Result().(*LKEClusterAPIEndpointsPagedResponse).Pages
354+
results = r.Result().(*LKEClusterAPIEndpointsPagedResponse).Results
355+
v.appendData(r.Result().(*LKEClusterAPIEndpointsPagedResponse))
356+
}
351357
case *LKEClusterPoolsPagedResponse:
352358
if r, err = coupleAPIErrors(req.SetResult(LKEClusterPoolsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil {
353359
pages = r.Result().(*LKEClusterPoolsPagedResponse).Pages

resources.go

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,81 +10,83 @@ import (
1010
)
1111

1212
const (
13-
accountName = "account"
14-
accountSettingsName = "accountsettings"
15-
domainRecordsName = "records"
16-
domainsName = "domains"
17-
eventsName = "events"
18-
firewallsName = "firewalls"
19-
imagesName = "images"
20-
instanceConfigsName = "configs"
21-
instanceDisksName = "disks"
22-
instanceIPsName = "ips"
23-
instanceSnapshotsName = "snapshots"
24-
instanceStatsName = "instancestats"
25-
instanceVolumesName = "instancevolumes"
26-
instancesName = "instances"
27-
invoiceItemsName = "invoiceitems"
28-
invoicesName = "invoices"
29-
ipaddressesName = "ipaddresses"
30-
ipv6poolsName = "ipv6pools"
31-
ipv6rangesName = "ipv6ranges"
32-
kernelsName = "kernels"
33-
lkeClustersName = "lkeclusters"
34-
lkeClusterPoolsName = "lkeclusterpools"
35-
lkeVersionsName = "lkeversions"
36-
longviewName = "longview"
37-
longviewclientsName = "longviewclients"
38-
longviewsubscriptionsName = "longviewsubscriptions"
39-
managedName = "managed"
40-
nodebalancerconfigsName = "nodebalancerconfigs"
41-
nodebalancernodesName = "nodebalancernodes"
42-
nodebalancerStatsName = "nodebalancerstats"
43-
nodebalancersName = "nodebalancers"
44-
notificationsName = "notifications"
45-
oauthClientsName = "oauthClients"
46-
objectStorageBucketsName = "objectstoragebuckets"
47-
objectStorageClustersName = "objectstorageclusters"
48-
objectStorageKeysName = "objectstoragekeys"
49-
paymentsName = "payments"
50-
profileName = "profile"
51-
regionsName = "regions"
52-
sshkeysName = "sshkeys"
53-
stackscriptsName = "stackscripts"
54-
tagsName = "tags"
55-
ticketsName = "tickets"
56-
tokensName = "tokens"
57-
typesName = "types"
58-
usersName = "users"
59-
volumesName = "volumes"
60-
61-
accountEndpoint = "account"
62-
accountSettingsEndpoint = "account/settings"
63-
domainRecordsEndpoint = "domains/{{ .ID }}/records"
64-
domainsEndpoint = "domains"
65-
eventsEndpoint = "account/events"
66-
firewallsEndpoint = "networking/firewalls"
67-
imagesEndpoint = "images"
68-
instanceConfigsEndpoint = "linode/instances/{{ .ID }}/configs"
69-
instanceDisksEndpoint = "linode/instances/{{ .ID }}/disks"
70-
instanceIPsEndpoint = "linode/instances/{{ .ID }}/ips"
71-
instanceSnapshotsEndpoint = "linode/instances/{{ .ID }}/backups"
72-
instanceStatsEndpoint = "linode/instances/{{ .ID }}/stats"
73-
instanceVolumesEndpoint = "linode/instances/{{ .ID }}/volumes"
74-
instancesEndpoint = "linode/instances"
75-
invoiceItemsEndpoint = "account/invoices/{{ .ID }}/items"
76-
invoicesEndpoint = "account/invoices"
77-
ipaddressesEndpoint = "networking/ips"
78-
ipv6poolsEndpoint = "networking/ipv6/pools"
79-
ipv6rangesEndpoint = "networking/ipv6/ranges"
80-
kernelsEndpoint = "linode/kernels"
81-
lkeClustersEndpoint = "lke/clusters"
82-
lkeClusterPoolsEndpoint = "lke/clusters/{{ .ID }}/pools"
83-
lkeVersionsEndpoint = "lke/versions"
84-
longviewEndpoint = "longview"
85-
longviewclientsEndpoint = "longview/clients"
86-
longviewsubscriptionsEndpoint = "longview/subscriptions"
87-
managedEndpoint = "managed"
13+
accountName = "account"
14+
accountSettingsName = "accountsettings"
15+
domainRecordsName = "records"
16+
domainsName = "domains"
17+
eventsName = "events"
18+
firewallsName = "firewalls"
19+
imagesName = "images"
20+
instanceConfigsName = "configs"
21+
instanceDisksName = "disks"
22+
instanceIPsName = "ips"
23+
instanceSnapshotsName = "snapshots"
24+
instanceStatsName = "instancestats"
25+
instanceVolumesName = "instancevolumes"
26+
instancesName = "instances"
27+
invoiceItemsName = "invoiceitems"
28+
invoicesName = "invoices"
29+
ipaddressesName = "ipaddresses"
30+
ipv6poolsName = "ipv6pools"
31+
ipv6rangesName = "ipv6ranges"
32+
kernelsName = "kernels"
33+
lkeClusterAPIEndpointsName = "lkeclusterapiendpoints"
34+
lkeClustersName = "lkeclusters"
35+
lkeClusterPoolsName = "lkeclusterpools"
36+
lkeVersionsName = "lkeversions"
37+
longviewName = "longview"
38+
longviewclientsName = "longviewclients"
39+
longviewsubscriptionsName = "longviewsubscriptions"
40+
managedName = "managed"
41+
nodebalancerconfigsName = "nodebalancerconfigs"
42+
nodebalancernodesName = "nodebalancernodes"
43+
nodebalancerStatsName = "nodebalancerstats"
44+
nodebalancersName = "nodebalancers"
45+
notificationsName = "notifications"
46+
oauthClientsName = "oauthClients"
47+
objectStorageBucketsName = "objectstoragebuckets"
48+
objectStorageClustersName = "objectstorageclusters"
49+
objectStorageKeysName = "objectstoragekeys"
50+
paymentsName = "payments"
51+
profileName = "profile"
52+
regionsName = "regions"
53+
sshkeysName = "sshkeys"
54+
stackscriptsName = "stackscripts"
55+
tagsName = "tags"
56+
ticketsName = "tickets"
57+
tokensName = "tokens"
58+
typesName = "types"
59+
usersName = "users"
60+
volumesName = "volumes"
61+
62+
accountEndpoint = "account"
63+
accountSettingsEndpoint = "account/settings"
64+
domainRecordsEndpoint = "domains/{{ .ID }}/records"
65+
domainsEndpoint = "domains"
66+
eventsEndpoint = "account/events"
67+
firewallsEndpoint = "networking/firewalls"
68+
imagesEndpoint = "images"
69+
instanceConfigsEndpoint = "linode/instances/{{ .ID }}/configs"
70+
instanceDisksEndpoint = "linode/instances/{{ .ID }}/disks"
71+
instanceIPsEndpoint = "linode/instances/{{ .ID }}/ips"
72+
instanceSnapshotsEndpoint = "linode/instances/{{ .ID }}/backups"
73+
instanceStatsEndpoint = "linode/instances/{{ .ID }}/stats"
74+
instanceVolumesEndpoint = "linode/instances/{{ .ID }}/volumes"
75+
instancesEndpoint = "linode/instances"
76+
invoiceItemsEndpoint = "account/invoices/{{ .ID }}/items"
77+
invoicesEndpoint = "account/invoices"
78+
ipaddressesEndpoint = "networking/ips"
79+
ipv6poolsEndpoint = "networking/ipv6/pools"
80+
ipv6rangesEndpoint = "networking/ipv6/ranges"
81+
kernelsEndpoint = "linode/kernels"
82+
lkeClustersEndpoint = "lke/clusters"
83+
lkeClusterAPIEndpointsEndpoint = "lke/clusters/{{ .ID }}/api-endpoints"
84+
lkeClusterPoolsEndpoint = "lke/clusters/{{ .ID }}/pools"
85+
lkeVersionsEndpoint = "lke/versions"
86+
longviewEndpoint = "longview"
87+
longviewclientsEndpoint = "longview/clients"
88+
longviewsubscriptionsEndpoint = "longview/subscriptions"
89+
managedEndpoint = "managed"
8890
// @TODO we can't use these nodebalancer endpoints unless we include these templated fields
8991
// The API seems inconsistent about including parent IDs in objects, (compare instance configs to nb configs)
9092
// Parent IDs would be immutable for updates and are ignored in create requests ..

test/integration/fixtures/TestGetLKEClusterKubeconfig.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
version: 1
33
interactions:
44
- request:
5-
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"02q3ns6i40tz-linodego-testing","region":"us-central","version":"1.16","tags":["testing"]}'
5+
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"02q3ns6i40tz-linodego-testing","region":"us-central","k8s_version":"1.17","tags":["testing"]}'
66
form: {}
77
headers:
88
Accept:
@@ -16,7 +16,7 @@ interactions:
1616
response:
1717
body: '{"id": 892, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
1818
"2018-01-02T03:04:05", "label": "02q3ns6i40tz-linodego-testing", "region": "us-central",
19-
"version": "1.16", "tags": []}'
19+
"k8s_version": "1.17", "tags": []}'
2020
headers:
2121
Access-Control-Allow-Credentials:
2222
- "true"
@@ -85,7 +85,7 @@ interactions:
8585
response:
8686
body: '{"id": 892, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
8787
"2018-01-02T03:04:05", "label": "02q3ns6i40tz-linodego-testing", "region": "us-central",
88-
"version": "1.16", "tags": []}'
88+
"k8s_version": "1.17", "tags": []}'
8989
headers:
9090
Access-Control-Allow-Credentials:
9191
- "true"

test/integration/fixtures/TestGetLKEClusterPool_found.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
version: 1
33
interactions:
44
- request:
5-
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"a83ef3go2h76-linodego-testing","region":"us-central","version":"1.16","tags":["testing"]}'
5+
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"a83ef3go2h76-linodego-testing","region":"us-central","k8s_version":"1.17","tags":["testing"]}'
66
form: {}
77
headers:
88
Accept:
@@ -16,7 +16,7 @@ interactions:
1616
response:
1717
body: '{"id": 888, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
1818
"2018-01-02T03:04:05", "label": "a83ef3go2h76-linodego-testing", "region": "us-central",
19-
"version": "1.16", "tags": []}'
19+
"k8s_version": "1.17", "tags": []}'
2020
headers:
2121
Access-Control-Allow-Credentials:
2222
- "true"

test/integration/fixtures/TestGetLKECluster_found.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
version: 1
33
interactions:
44
- request:
5-
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"9a6i7ack382y-linodego-testing","region":"us-central","version":"1.16","tags":["testing"]}'
5+
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"9a6i7ack382y-linodego-testing","region":"us-central","k8s_version":"1.17","tags":["testing"]}'
66
form: {}
77
headers:
88
Accept:
@@ -16,7 +16,7 @@ interactions:
1616
response:
1717
body: '{"id": 890, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
1818
"2018-01-02T03:04:05", "label": "9a6i7ack382y-linodego-testing", "region": "us-central",
19-
"version": "1.16", "tags": []}'
19+
"k8s_version": "1.17", "tags": []}'
2020
headers:
2121
Access-Control-Allow-Credentials:
2222
- "true"
@@ -85,7 +85,7 @@ interactions:
8585
response:
8686
body: '{"id": 890, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
8787
"2018-01-02T03:04:05", "label": "9a6i7ack382y-linodego-testing", "region": "us-central",
88-
"version": "1.16", "tags": []}'
88+
"k8s_version": "1.17", "tags": []}'
8989
headers:
9090
Access-Control-Allow-Credentials:
9191
- "true"

0 commit comments

Comments
 (0)