diff --git a/scaleway/helpers_k8s.go b/scaleway/helpers_k8s.go index 4a73bb3fb0..8d43fe4215 100644 --- a/scaleway/helpers_k8s.go +++ b/scaleway/helpers_k8s.go @@ -37,7 +37,7 @@ type KubeconfigStruct struct { const ( K8SClusterWaitForReadyTimeout = 10 * time.Minute K8SClusterWaitForDeletedTimeout = 10 * time.Minute - K8SPoolNodesWaitForReadyTimeout = 10 * time.Minute + K8SPoolWaitForReadyTimeout = 10 * time.Minute ) func k8sAPIWithRegion(d *schema.ResourceData, m interface{}) (*k8s.API, scw.Region, error) { @@ -73,14 +73,6 @@ func waitK8SClusterReady(k8sAPI *k8s.API, region scw.Region, clusterID string) e return fmt.Errorf("Cluster %s has state %s, wants %s", clusterID, cluster.Status.String(), k8s.ClusterStatusReady.String()) } -func waitK8SClusterNodesReady(k8sAPI *k8s.API, region scw.Region, clusterID string) error { - return k8sAPI.WaitForClusterPools(&k8s.WaitForClusterPoolsRequest{ - ClusterID: clusterID, - Region: region, - Timeout: scw.DurationPtr(K8SPoolNodesWaitForReadyTimeout), - }) -} - func waitK8SClusterDeleted(k8sAPI *k8s.API, region scw.Region, clusterID string) error { cluster, err := k8sAPI.WaitForCluster(&k8s.WaitForClusterRequest{ ClusterID: clusterID, @@ -97,6 +89,14 @@ func waitK8SClusterDeleted(k8sAPI *k8s.API, region scw.Region, clusterID string) return fmt.Errorf("Cluster %s has state %s, wants %s", clusterID, cluster.Status.String(), k8s.ClusterStatusDeleted.String()) } +func waitK8SPoolReady(k8sAPI *k8s.API, region scw.Region, poolID string) error { + return k8sAPI.WaitForPool(&k8s.WaitForPoolRequest{ + PoolID: poolID, + Region: region, + Timeout: scw.DurationPtr(K8SPoolWaitForReadyTimeout), + }) +} + // convert a list of nodes to a list of map func convertNodes(res *k8s.ListNodesResponse) []map[string]interface{} { var result []map[string]interface{} diff --git a/scaleway/resource_k8s_cluster_beta.go b/scaleway/resource_k8s_cluster_beta.go index 2d71797e98..c788c4883c 100644 --- a/scaleway/resource_k8s_cluster_beta.go +++ b/scaleway/resource_k8s_cluster_beta.go @@ -194,6 +194,12 @@ func resourceScalewayK8SClusterBeta() *schema.Resource { k8s.RuntimeCrio.String(), }, false), }, + "wait_for_pool_ready": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Whether to wait for the pool to be ready", + }, // Computed elements "pool_id": { Type: schema.TypeString, @@ -251,12 +257,6 @@ func resourceScalewayK8SClusterBeta() *schema.Resource { }, }, }, - "wait_for_pools": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "Whether to wait for all pools of the cluster to be ready", - }, "region": regionSchema(), "organization_id": organizationIDSchema(), // Computed elements @@ -452,14 +452,18 @@ func resourceScalewayK8SClusterBetaCreate(d *schema.ResourceData, m interface{}) return err } - if d.Get("wait_for_pools").(bool) { // wait for nodes to be ready if specified - err = waitK8SClusterNodesReady(k8sAPI, region, res.ID) + clusterRead := resourceScalewayK8SClusterBetaRead(d, m) // ensure that 'default_pool.0.pool_id' is set + + if d.Get("default_pool.0.wait_for_pool_ready").(bool) { // wait for the pool to be ready if specified + defaultPoolID := d.Get("default_pool.0.pool_id").(string) + + err = waitK8SPoolReady(k8sAPI, region, defaultPoolID) if err != nil { return err } } - return resourceScalewayK8SClusterBetaRead(d, m) + return clusterRead } // resourceScalewayK8SClusterBetaDefaultPoolRead is only called after a resourceScalewayK8SClusterBetaCreate @@ -714,6 +718,13 @@ func resourceScalewayK8SClusterBetaDefaultPoolUpdate(d *schema.ResourceData, m i } } } + + if d.Get("default_pool.0.wait_for_pool_ready").(bool) { // wait for the pool to be ready if specified + err = waitK8SPoolReady(k8sAPI, region, defaultPoolID) + if err != nil { + return err + } + } } return resourceScalewayK8SClusterBetaDefaultPoolRead(d, m) @@ -836,13 +847,6 @@ func resourceScalewayK8SClusterBetaUpdate(d *schema.ResourceData, m interface{}) return err } - if d.Get("wait_for_pools").(bool) { // wait for nodes to be ready if specified - err = waitK8SClusterNodesReady(k8sAPI, region, clusterID) - if err != nil { - return err - } - } - return resourceScalewayK8SClusterBetaRead(d, m) } diff --git a/scaleway/resource_k8s_pool_beta.go b/scaleway/resource_k8s_pool_beta.go index 17c41a625e..a1a6778316 100644 --- a/scaleway/resource_k8s_pool_beta.go +++ b/scaleway/resource_k8s_pool_beta.go @@ -77,6 +77,12 @@ func resourceScalewayK8SPoolBeta() *schema.Resource { k8s.RuntimeCrio.String(), }, false), }, + "wait_for_pool_ready": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Whether to wait for the pool to be ready", + }, "placement_group_id": { Type: schema.TypeString, Optional: true, @@ -183,6 +189,13 @@ func resourceScalewayK8SPoolBetaCreate(d *schema.ResourceData, m interface{}) er d.SetId(newRegionalId(region, res.ID)) + if d.Get("wait_for_pool_ready").(bool) { // wait for nodes to be ready if specified + err = waitK8SPoolReady(k8sAPI, region, res.ID) + if err != nil { + return err + } + } + return resourceScalewayK8SPoolBetaRead(d, m) } @@ -267,11 +280,18 @@ func resourceScalewayK8SPoolBetaUpdate(d *schema.ResourceData, m interface{}) er updateRequest.Size = scw.Uint32Ptr(uint32(d.Get("size").(int))) } - _, err = k8sAPI.UpdatePool(updateRequest) + res, err := k8sAPI.UpdatePool(updateRequest) if err != nil { return err } + if d.Get("wait_for_pool_ready").(bool) { // wait for nodes to be ready if specified + err = waitK8SPoolReady(k8sAPI, region, res.ID) + if err != nil { + return err + } + } + return resourceScalewayK8SPoolBetaRead(d, m) } diff --git a/website/docs/r/k8s_cluster_beta.html.markdown b/website/docs/r/k8s_cluster_beta.html.markdown index 1b8dff83bd..515f539f69 100644 --- a/website/docs/r/k8s_cluster_beta.html.markdown +++ b/website/docs/r/k8s_cluster_beta.html.markdown @@ -151,7 +151,7 @@ The following arguments are supported: - `container_runtime` - (Defaults to `docker`) The container runtime of the default pool. ~> **Important:** Updates to this field will recreate a new default pool. -- `wait_for_pools` - (Default to `false`) Whether to wait for all pools of the cluster to be ready + - `wait_for_pool_ready` - (Default to `false`) Whether to wait for the pool to be ready - `region` - (Defaults to [provider](../index.html#region) `region`) The [region](../guides/regions_and_zones.html#regions) in which the cluster should be created. diff --git a/website/docs/r/k8s_pool_beta.html.markdown b/website/docs/r/k8s_pool_beta.html.markdown index 0bbbba551c..d69b43325d 100644 --- a/website/docs/r/k8s_pool_beta.html.markdown +++ b/website/docs/r/k8s_pool_beta.html.markdown @@ -67,6 +67,8 @@ The following arguments are supported: - `region` - (Defaults to [provider](../index.html#region) `region`) The [region](../guides/regions_and_zones.html#regions) in which the pool should be created. +- `wait_for_pool_ready` - (Default to `false`) Whether to wait for the pool to be ready + ## Attributes Reference In addition to all above arguments, the following attributes are exported: