Skip to content

Commit

Permalink
Merge pull request #143 from displague/latest-lke
Browse files Browse the repository at this point in the history
Update LKE methods for GA LKE API
  • Loading branch information
0xch4z authored Apr 29, 2020
2 parents 81a6bb0 + 7cef056 commit ffcac8c
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 214 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/


# Common IDE paths
.vscode/

vendor/**/
.env
coverage.txt
Expand Down
1 change: 1 addition & 0 deletions account_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const (
ActionLinodeConfigDelete EventAction = "linode_config_delete"
ActionLinodeConfigUpdate EventAction = "linode_config_update"
ActionLishBoot EventAction = "lish_boot"
ActionLKENodeCreate EventAction = "lke_node_create"
ActionLongviewClientCreate EventAction = "longviewclient_create"
ActionLongviewClientDelete EventAction = "longviewclient_delete"
ActionLongviewClientUpdate EventAction = "longviewclient_update"
Expand Down
193 changes: 98 additions & 95 deletions client.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions lke_cluster_pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ const (

// LKEClusterPoolLinode represents a LKEClusterPoolLinode object
type LKEClusterPoolLinode struct {
ID string `json:"id"`
Status LKELinodeStatus `json:"status"`
ID string `json:"id"`
InstanceID int `json:"instance_id"`
Status LKELinodeStatus `json:"status"`
}

// LKEClusterPool represents a LKEClusterPool object
Expand Down
42 changes: 30 additions & 12 deletions lke_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ type LKEClusterCreateOptions struct {

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

// LKEClusterAPIEndpoint fields are those returned by GetLKEClusterAPIEndpoint
// LKEClusterAPIEndpoint fields are those returned by ListLKEClusterAPIEndpoints
type LKEClusterAPIEndpoint struct {
Endpoints []string `json:"endpoints"`
Endpoint string `json:"endpoint"`
}

// LKEClusterKubeconfig fields are those returned by GetLKEClusterKubeconfig
Expand Down Expand Up @@ -94,6 +95,7 @@ func (i LKECluster) GetCreateOptions() (o LKEClusterCreateOptions) {
// GetUpdateOptions converts a LKECluster to LKEClusterUpdateOptions for use in UpdateLKECluster
func (i LKECluster) GetUpdateOptions() (o LKEClusterUpdateOptions) {
o.Label = i.Label
o.Tags = &i.Tags
return
}

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

// LKEClusterAPIEndpointsPagedResponse represents a paginated LKEClusterAPIEndpoints API response
type LKEClusterAPIEndpointsPagedResponse struct {
*PageOptions
Data []LKEClusterAPIEndpoint `json:"data"`
}

// LKEVersionsPagedResponse represents a paginated LKEVersion API response
type LKEVersionsPagedResponse struct {
*PageOptions
Expand Down Expand Up @@ -132,6 +140,20 @@ func (LKEVersionsPagedResponse) endpoint(c *Client) string {
return endpoint
}

// endpoint gets the endpoint URL for LKEClusterAPIEndpoints
func (LKEClusterAPIEndpointsPagedResponse) endpointWithID(c *Client, id int) string {
endpoint, err := c.LKEClusterAPIEndpoints.endpointWithID(id)
if err != nil {
panic(err)
}
return endpoint
}

// appendData appends LKEClusterAPIEndpoints when processing paginated LKEClusterAPIEndpoints responses
func (resp *LKEClusterAPIEndpointsPagedResponse) appendData(r *LKEClusterAPIEndpointsPagedResponse) {
resp.Data = append(resp.Data, r.Data...)
}

// appendData appends LKEVersions when processing paginated LKEVersion responses
func (resp *LKEVersionsPagedResponse) appendData(r *LKEVersionsPagedResponse) {
resp.Data = append(resp.Data, r.Data...)
Expand Down Expand Up @@ -226,18 +248,14 @@ func (c *Client) DeleteLKECluster(ctx context.Context, id int) error {
return err
}

// GetLKEClusterAPIEndpoint gets the API Endpoint for the LKE Cluster specified
func (c *Client) GetLKEClusterAPIEndpoint(ctx context.Context, id int) (*LKEClusterAPIEndpoint, error) {
e, err := c.LKEClusters.Endpoint()
// ListLKEClusterAPIEndpoints gets the API Endpoint for the LKE Cluster specified
func (c *Client) ListLKEClusterAPIEndpoints(ctx context.Context, clusterID int, opts *ListOptions) ([]LKEClusterAPIEndpoint, error) {
response := LKEClusterAPIEndpointsPagedResponse{}
err := c.listHelperWithID(ctx, &response, clusterID, opts)
if err != nil {
return nil, err
}
e = fmt.Sprintf("%s/%d/api-endpoint", e, id)
r, err := coupleAPIErrors(c.R(ctx).SetResult(&LKEClusterAPIEndpoint{}).Get(e))
if err != nil {
return nil, err
}
return r.Result().(*LKEClusterAPIEndpoint), nil
return response.Data, nil
}

// GetLKEClusterKubeconfig gets the Kubeconfig for the LKE Cluster specified
Expand Down
6 changes: 6 additions & 0 deletions pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ func (c *Client) listHelperWithID(ctx context.Context, i interface{}, idRaw inte
results = r.Result().(*InvoiceItemsPagedResponse).Results
v.appendData(r.Result().(*InvoiceItemsPagedResponse))
}
case *LKEClusterAPIEndpointsPagedResponse:
if r, err = coupleAPIErrors(req.SetResult(LKEClusterAPIEndpointsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil {
pages = r.Result().(*LKEClusterAPIEndpointsPagedResponse).Pages
results = r.Result().(*LKEClusterAPIEndpointsPagedResponse).Results
v.appendData(r.Result().(*LKEClusterAPIEndpointsPagedResponse))
}
case *LKEClusterPoolsPagedResponse:
if r, err = coupleAPIErrors(req.SetResult(LKEClusterPoolsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil {
pages = r.Result().(*LKEClusterPoolsPagedResponse).Pages
Expand Down
152 changes: 77 additions & 75 deletions resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,81 +10,83 @@ import (
)

const (
accountName = "account"
accountSettingsName = "accountsettings"
domainRecordsName = "records"
domainsName = "domains"
eventsName = "events"
firewallsName = "firewalls"
imagesName = "images"
instanceConfigsName = "configs"
instanceDisksName = "disks"
instanceIPsName = "ips"
instanceSnapshotsName = "snapshots"
instanceStatsName = "instancestats"
instanceVolumesName = "instancevolumes"
instancesName = "instances"
invoiceItemsName = "invoiceitems"
invoicesName = "invoices"
ipaddressesName = "ipaddresses"
ipv6poolsName = "ipv6pools"
ipv6rangesName = "ipv6ranges"
kernelsName = "kernels"
lkeClustersName = "lkeclusters"
lkeClusterPoolsName = "lkeclusterpools"
lkeVersionsName = "lkeversions"
longviewName = "longview"
longviewclientsName = "longviewclients"
longviewsubscriptionsName = "longviewsubscriptions"
managedName = "managed"
nodebalancerconfigsName = "nodebalancerconfigs"
nodebalancernodesName = "nodebalancernodes"
nodebalancerStatsName = "nodebalancerstats"
nodebalancersName = "nodebalancers"
notificationsName = "notifications"
oauthClientsName = "oauthClients"
objectStorageBucketsName = "objectstoragebuckets"
objectStorageClustersName = "objectstorageclusters"
objectStorageKeysName = "objectstoragekeys"
paymentsName = "payments"
profileName = "profile"
regionsName = "regions"
sshkeysName = "sshkeys"
stackscriptsName = "stackscripts"
tagsName = "tags"
ticketsName = "tickets"
tokensName = "tokens"
typesName = "types"
usersName = "users"
volumesName = "volumes"

accountEndpoint = "account"
accountSettingsEndpoint = "account/settings"
domainRecordsEndpoint = "domains/{{ .ID }}/records"
domainsEndpoint = "domains"
eventsEndpoint = "account/events"
firewallsEndpoint = "networking/firewalls"
imagesEndpoint = "images"
instanceConfigsEndpoint = "linode/instances/{{ .ID }}/configs"
instanceDisksEndpoint = "linode/instances/{{ .ID }}/disks"
instanceIPsEndpoint = "linode/instances/{{ .ID }}/ips"
instanceSnapshotsEndpoint = "linode/instances/{{ .ID }}/backups"
instanceStatsEndpoint = "linode/instances/{{ .ID }}/stats"
instanceVolumesEndpoint = "linode/instances/{{ .ID }}/volumes"
instancesEndpoint = "linode/instances"
invoiceItemsEndpoint = "account/invoices/{{ .ID }}/items"
invoicesEndpoint = "account/invoices"
ipaddressesEndpoint = "networking/ips"
ipv6poolsEndpoint = "networking/ipv6/pools"
ipv6rangesEndpoint = "networking/ipv6/ranges"
kernelsEndpoint = "linode/kernels"
lkeClustersEndpoint = "lke/clusters"
lkeClusterPoolsEndpoint = "lke/clusters/{{ .ID }}/pools"
lkeVersionsEndpoint = "lke/versions"
longviewEndpoint = "longview"
longviewclientsEndpoint = "longview/clients"
longviewsubscriptionsEndpoint = "longview/subscriptions"
managedEndpoint = "managed"
accountName = "account"
accountSettingsName = "accountsettings"
domainRecordsName = "records"
domainsName = "domains"
eventsName = "events"
firewallsName = "firewalls"
imagesName = "images"
instanceConfigsName = "configs"
instanceDisksName = "disks"
instanceIPsName = "ips"
instanceSnapshotsName = "snapshots"
instanceStatsName = "instancestats"
instanceVolumesName = "instancevolumes"
instancesName = "instances"
invoiceItemsName = "invoiceitems"
invoicesName = "invoices"
ipaddressesName = "ipaddresses"
ipv6poolsName = "ipv6pools"
ipv6rangesName = "ipv6ranges"
kernelsName = "kernels"
lkeClusterAPIEndpointsName = "lkeclusterapiendpoints"
lkeClustersName = "lkeclusters"
lkeClusterPoolsName = "lkeclusterpools"
lkeVersionsName = "lkeversions"
longviewName = "longview"
longviewclientsName = "longviewclients"
longviewsubscriptionsName = "longviewsubscriptions"
managedName = "managed"
nodebalancerconfigsName = "nodebalancerconfigs"
nodebalancernodesName = "nodebalancernodes"
nodebalancerStatsName = "nodebalancerstats"
nodebalancersName = "nodebalancers"
notificationsName = "notifications"
oauthClientsName = "oauthClients"
objectStorageBucketsName = "objectstoragebuckets"
objectStorageClustersName = "objectstorageclusters"
objectStorageKeysName = "objectstoragekeys"
paymentsName = "payments"
profileName = "profile"
regionsName = "regions"
sshkeysName = "sshkeys"
stackscriptsName = "stackscripts"
tagsName = "tags"
ticketsName = "tickets"
tokensName = "tokens"
typesName = "types"
usersName = "users"
volumesName = "volumes"

accountEndpoint = "account"
accountSettingsEndpoint = "account/settings"
domainRecordsEndpoint = "domains/{{ .ID }}/records"
domainsEndpoint = "domains"
eventsEndpoint = "account/events"
firewallsEndpoint = "networking/firewalls"
imagesEndpoint = "images"
instanceConfigsEndpoint = "linode/instances/{{ .ID }}/configs"
instanceDisksEndpoint = "linode/instances/{{ .ID }}/disks"
instanceIPsEndpoint = "linode/instances/{{ .ID }}/ips"
instanceSnapshotsEndpoint = "linode/instances/{{ .ID }}/backups"
instanceStatsEndpoint = "linode/instances/{{ .ID }}/stats"
instanceVolumesEndpoint = "linode/instances/{{ .ID }}/volumes"
instancesEndpoint = "linode/instances"
invoiceItemsEndpoint = "account/invoices/{{ .ID }}/items"
invoicesEndpoint = "account/invoices"
ipaddressesEndpoint = "networking/ips"
ipv6poolsEndpoint = "networking/ipv6/pools"
ipv6rangesEndpoint = "networking/ipv6/ranges"
kernelsEndpoint = "linode/kernels"
lkeClustersEndpoint = "lke/clusters"
lkeClusterAPIEndpointsEndpoint = "lke/clusters/{{ .ID }}/api-endpoints"
lkeClusterPoolsEndpoint = "lke/clusters/{{ .ID }}/pools"
lkeVersionsEndpoint = "lke/versions"
longviewEndpoint = "longview"
longviewclientsEndpoint = "longview/clients"
longviewsubscriptionsEndpoint = "longview/subscriptions"
managedEndpoint = "managed"
// @TODO we can't use these nodebalancer endpoints unless we include these templated fields
// The API seems inconsistent about including parent IDs in objects, (compare instance configs to nb configs)
// Parent IDs would be immutable for updates and are ignored in create requests ..
Expand Down
6 changes: 3 additions & 3 deletions test/integration/fixtures/TestGetLKEClusterKubeconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"02q3ns6i40tz-linodego-testing","region":"us-central","version":"1.16","tags":["testing"]}'
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"02q3ns6i40tz-linodego-testing","region":"us-central","k8s_version":"1.17","tags":["testing"]}'
form: {}
headers:
Accept:
Expand All @@ -16,7 +16,7 @@ interactions:
response:
body: '{"id": 892, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "02q3ns6i40tz-linodego-testing", "region": "us-central",
"version": "1.16", "tags": []}'
"k8s_version": "1.17", "tags": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down Expand Up @@ -85,7 +85,7 @@ interactions:
response:
body: '{"id": 892, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "02q3ns6i40tz-linodego-testing", "region": "us-central",
"version": "1.16", "tags": []}'
"k8s_version": "1.17", "tags": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fixtures/TestGetLKEClusterPool_found.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"a83ef3go2h76-linodego-testing","region":"us-central","version":"1.16","tags":["testing"]}'
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"a83ef3go2h76-linodego-testing","region":"us-central","k8s_version":"1.17","tags":["testing"]}'
form: {}
headers:
Accept:
Expand All @@ -16,7 +16,7 @@ interactions:
response:
body: '{"id": 888, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "a83ef3go2h76-linodego-testing", "region": "us-central",
"version": "1.16", "tags": []}'
"k8s_version": "1.17", "tags": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down
6 changes: 3 additions & 3 deletions test/integration/fixtures/TestGetLKECluster_found.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"9a6i7ack382y-linodego-testing","region":"us-central","version":"1.16","tags":["testing"]}'
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"9a6i7ack382y-linodego-testing","region":"us-central","k8s_version":"1.17","tags":["testing"]}'
form: {}
headers:
Accept:
Expand All @@ -16,7 +16,7 @@ interactions:
response:
body: '{"id": 890, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "9a6i7ack382y-linodego-testing", "region": "us-central",
"version": "1.16", "tags": []}'
"k8s_version": "1.17", "tags": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down Expand Up @@ -85,7 +85,7 @@ interactions:
response:
body: '{"id": 890, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "9a6i7ack382y-linodego-testing", "region": "us-central",
"version": "1.16", "tags": []}'
"k8s_version": "1.17", "tags": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 1
interactions:
- request:
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"1ry04ss8s3t8-linodego-testing","region":"us-central","version":"1.16","tags":["testing"]}'
body: '{"node_pools":[{"count":1,"type":"g6-standard-2"}],"label":"1ry04ss8s3t8-linodego-testing","region":"us-central","k8s_version":"1.17","tags":["testing"]}'
form: {}
headers:
Accept:
Expand All @@ -16,7 +16,7 @@ interactions:
response:
body: '{"id": 891, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "1ry04ss8s3t8-linodego-testing", "region": "us-central",
"version": "1.16", "tags": []}'
"k8s_version": "1.17", "tags": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down Expand Up @@ -85,7 +85,7 @@ interactions:
response:
body: '{"id": 891, "status": "ready", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "label": "1ry04ss8s3t8-linodego-testing", "region": "us-central",
"version": "1.16", "tags": []}'
"k8s_version": "1.17", "tags": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down Expand Up @@ -151,10 +151,10 @@ interactions:
- application/json
User-Agent:
- linodego 0.12.0 https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/clusters/891/api-endpoint
url: https://api.linode.com/v4beta/lke/clusters/891/api-endpoints
method: GET
response:
body: '{"endpoints": ["https://10.20.30.40:6443"]}'
body: '{"data": [ {"endpoint": "https://10.20.30.40:6443"} ], "page": 1, "pages": 1, "results": 1}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down
Loading

0 comments on commit ffcac8c

Please sign in to comment.