Skip to content

chore(k8s): migrate to context based workflow #619

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

Merged
merged 2 commits into from
Oct 12, 2020
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
21 changes: 11 additions & 10 deletions scaleway/helpers_k8s.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scaleway

import (
"context"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -68,15 +69,15 @@ func k8sGetMinorVersionFromFull(version string) (string, error) {
}

// k8sGetLatestVersionFromMinor returns the latest full version (x.y.z) for a given minor version (x.y)
func k8sGetLatestVersionFromMinor(k8sAPI *k8s.API, region scw.Region, version string) (string, error) {
func k8sGetLatestVersionFromMinor(ctx context.Context, k8sAPI *k8s.API, region scw.Region, version string) (string, error) {
versionSplit := strings.Split(version, ".")
if len(versionSplit) != 2 {
return "", fmt.Errorf("minor version should be like x.y not %s", version)
}

versionsResp, err := k8sAPI.ListVersions(&k8s.ListVersionsRequest{
Region: region,
})
}, scw.WithContext(ctx))
if err != nil {
return "", err
}
Expand All @@ -93,12 +94,12 @@ func k8sGetLatestVersionFromMinor(k8sAPI *k8s.API, region scw.Region, version st
return "", fmt.Errorf("no available upstream version found for %s", version)
}

func waitK8SCluster(k8sAPI *k8s.API, region scw.Region, clusterID string, desiredStates ...k8s.ClusterStatus) error {
func waitK8SCluster(ctx context.Context, k8sAPI *k8s.API, region scw.Region, clusterID string, desiredStates ...k8s.ClusterStatus) error {
cluster, err := k8sAPI.WaitForCluster(&k8s.WaitForClusterRequest{
ClusterID: clusterID,
Region: region,
Timeout: scw.TimeDurationPtr(K8SClusterWaitForPoolRequiredTimeout),
})
}, scw.WithContext(ctx))
if err != nil {
return err
}
Expand All @@ -112,12 +113,12 @@ func waitK8SCluster(k8sAPI *k8s.API, region scw.Region, clusterID string, desire
return fmt.Errorf("cluster %s has state %s, wants one of %+q", clusterID, cluster.Status, desiredStates)
}

func waitK8SClusterDeleted(k8sAPI *k8s.API, region scw.Region, clusterID string) error {
func waitK8SClusterDeleted(ctx context.Context, k8sAPI *k8s.API, region scw.Region, clusterID string) error {
cluster, err := k8sAPI.WaitForCluster(&k8s.WaitForClusterRequest{
ClusterID: clusterID,
Region: region,
Timeout: scw.TimeDurationPtr(K8SClusterWaitForDeletedTimeout),
})
}, scw.WithContext(ctx))
if err != nil {
if is404Error(err) {
return nil
Expand All @@ -128,12 +129,12 @@ func waitK8SClusterDeleted(k8sAPI *k8s.API, region scw.Region, clusterID string)
return fmt.Errorf("cluster %s has state %s, wants %s", clusterID, cluster.Status, k8s.ClusterStatusDeleted)
}

func waitK8SPoolReady(k8sAPI *k8s.API, region scw.Region, poolID string) error {
func waitK8SPoolReady(ctx context.Context, k8sAPI *k8s.API, region scw.Region, poolID string) error {
pool, err := k8sAPI.WaitForPool(&k8s.WaitForPoolRequest{
PoolID: poolID,
Region: region,
Timeout: scw.TimeDurationPtr(K8SPoolWaitForReadyTimeout),
})
}, scw.WithContext(ctx))

if err != nil {
return err
Expand Down Expand Up @@ -163,14 +164,14 @@ func convertNodes(res *k8s.ListNodesResponse) []map[string]interface{} {
return result
}

func getNodes(k8sAPI *k8s.API, pool *k8s.Pool) ([]map[string]interface{}, error) {
func getNodes(ctx context.Context, k8sAPI *k8s.API, pool *k8s.Pool) ([]map[string]interface{}, error) {
req := &k8s.ListNodesRequest{
Region: pool.Region,
ClusterID: pool.ClusterID,
PoolID: &pool.ID,
}

nodes, err := k8sAPI.ListNodes(req, scw.WithAllPages())
nodes, err := k8sAPI.ListNodes(req, scw.WithAllPages(), scw.WithContext(ctx))

if err != nil {
return nil, err
Expand Down
Loading