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

Support LKE tier version #676

Merged
merged 4 commits into from
Feb 21, 2025
Merged
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
28 changes: 28 additions & 0 deletions lke_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ type LKEVersion struct {
ID string `json:"id"`
}

// LKETierVersion fields are those returned by GetLKETierVersion
// NOTE: It may not currently be available to all users and can only be used with v4beta.
type LKETierVersion struct {
ID string `json:"id"`
Tier LKEVersionTier `json:"tier"`
}

// LKEVersionTier enums represents different LKE tiers
type LKEVersionTier string

// LKEVersionTier enums start with LKEVersion
const (
LKEVersionStandard LKEVersionTier = "standard"
LKEVersionEnterprise LKEVersionTier = "enterprise"
)

// LKEClusterRegenerateOptions fields are those accepted by RegenerateLKECluster
type LKEClusterRegenerateOptions struct {
KubeConfig bool `json:"kubeconfig"`
Expand Down Expand Up @@ -185,6 +201,18 @@ func (c *Client) GetLKEVersion(ctx context.Context, version string) (*LKEVersion
return response, nil
}

// ListLKETierVersions lists all Kubernetes versions available given tier through LKE.
// NOTE: This endpoint may not currently be available to all users and can only be used with v4beta.
func (c *Client) ListLKETierVersions(ctx context.Context, tier string, opts *ListOptions) ([]LKETierVersion, error) {
return getPaginatedResults[LKETierVersion](ctx, c, formatAPIPath("lke/versions/%s", tier), opts)
}

// GetLKETierVersion gets the details of a specific LKE tier version.
// NOTE: This endpoint may not currently be available to all users and can only be used with v4beta.
func (c *Client) GetLKETierVersion(ctx context.Context, tier string, versionID string) (*LKETierVersion, error) {
return doGETRequest[LKETierVersion](ctx, c, formatAPIPath("lke/versions/%s/%s", tier, versionID))
}

// ListLKEClusterAPIEndpoints gets the API Endpoint for the LKE Cluster specified
func (c *Client) ListLKEClusterAPIEndpoints(ctx context.Context, clusterID int, opts *ListOptions) ([]LKEClusterAPIEndpoint, error) {
return getPaginatedResults[LKEClusterAPIEndpoint](ctx, c, formatAPIPath("lke/clusters/%d/api-endpoints", clusterID), opts)
Expand Down
132 changes: 132 additions & 0 deletions test/integration/fixtures/TestLKETierVersion_ListAndGet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/versions/standard?page=1
method: GET
response:
body: '{"data": [{"id": "1.31", "tier": "standard"}, {"id": "1.30", "tier": "standard"}],
"page": 1, "pages": 1, "results": 2}'
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
Access-Control-Allow-Methods:
- HEAD, GET, OPTIONS, POST, PUT, DELETE
Access-Control-Allow-Origin:
- '*'
Access-Control-Expose-Headers:
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
Akamai-Internal-Account:
- '*'
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
- keep-alive
Content-Length:
- "119"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Mon, 10 Feb 2025 17:36:11 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization, X-Filter
- Authorization, X-Filter
X-Accepted-Oauth-Scopes:
- lke:read_only
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
- DENY
X-Oauth-Scopes:
- account:read_write databases:read_write domains:read_write events:read_write
firewall:read_write images:read_write ips:read_write linodes:read_write lke:read_write
longview:read_write nodebalancers:read_write object_storage:read_write stackscripts:read_write
volumes:read_write vpc:read_write
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/lke/versions/standard/1.31
method: GET
response:
body: '{"id": "1.31", "tier": "standard"}'
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
Access-Control-Allow-Methods:
- HEAD, GET, OPTIONS, POST, PUT, DELETE
Access-Control-Allow-Origin:
- '*'
Access-Control-Expose-Headers:
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
Akamai-Internal-Account:
- '*'
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
- keep-alive
Content-Length:
- "34"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Mon, 10 Feb 2025 17:36:12 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization, X-Filter
- Authorization, X-Filter
X-Accepted-Oauth-Scopes:
- lke:read_only
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
- DENY
X-Oauth-Scopes:
- account:read_write databases:read_write domains:read_write events:read_write
firewall:read_write images:read_write ips:read_write linodes:read_write lke:read_write
longview:read_write nodebalancers:read_write object_storage:read_write stackscripts:read_write
volumes:read_write vpc:read_write
X-Ratelimit-Limit:
- "1600"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
30 changes: 30 additions & 0 deletions test/integration/lke_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,33 @@ func TestLKECluster_APLEnabled_smoke(t *testing.T) {
t.Errorf("Expected an APL health check URL %v, but got a different one %v", expectedHealthCheckURL, healthCheckURL)
}
}

func TestLKETierVersion_ListAndGet(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLKETierVersion_ListAndGet")
defer teardown()

tier := "standard"
versions, err := client.ListLKETierVersions(context.Background(), tier, nil)
if err != nil {
t.Errorf("Error listing versions, expected struct, got %v and error %v", versions, err)
}

if len(versions) == 0 {
t.Errorf("Expected a list of versions, but got none %v", versions)
}

for _, version := range versions {
if string(version.Tier) != tier {
t.Errorf("Expected version tier %v, but got %v", tier, version.Tier)
}
}

v, err := client.GetLKETierVersion(context.Background(), tier, versions[0].ID)
if err != nil {
t.Errorf("Error getting version, expected struct, got %v and error %v", v, err)
}

if v.ID != versions[0].ID {
t.Errorf("Expected a specific version %v, but got a different one %v", versions[0].ID, v.ID)
}
}