Skip to content

Commit

Permalink
move waitForCluster to the beginning of the cluster datasource read
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltan Illes authored and hkantare committed Sep 10, 2024
1 parent acd65cd commit b1220fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
31 changes: 16 additions & 15 deletions ibm/service/kubernetes/data_source_ibm_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func DataSourceIBMContainerCluster() *schema.Resource {
"wait_till": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{oneWorkerNodeReady, clusterNormal}, true),
ValidateFunc: validation.StringInSlice([]string{masterNodeReady, oneWorkerNodeReady, clusterNormal}, true),
Description: "wait_till can be configured for Master Ready, One worker Ready, Ingress Ready or Normal",
},
"wait_till_timeout": {
Expand Down Expand Up @@ -423,6 +423,21 @@ func dataSourceIBMContainerClusterRead(d *schema.ResourceData, meta interface{})
if err != nil {
return fmt.Errorf("[ERROR] Error retrieving cluster: %s", err)
}

d.SetId(clusterFields.ID)

if timeoutStage != "" {
err = waitForCluster(d, timeoutStage, timeout, meta)
if err != nil {
return err
}

clusterFields, err = csAPI.Find(name, targetEnv)
if err != nil {
return fmt.Errorf("[ERROR] Error retrieving cluster after waitForCluster: %s", err)
}
}

workerFields, err := wrkAPI.List(name, targetEnv)
if err != nil {
return fmt.Errorf("[ERROR] Error retrieving workers for cluster: %s", err)
Expand Down Expand Up @@ -462,20 +477,6 @@ func dataSourceIBMContainerClusterRead(d *schema.ResourceData, meta interface{})
filterType := d.Get("alb_type").(string)
filteredAlbs := flex.FlattenAlbs(albs, filterType)

d.SetId(clusterFields.ID)

if timeoutStage != "" {
err = waitForCluster(d, timeoutStage, timeout, meta)
if err != nil {
return err
}

clusterFields, err = csAPI.Find(name, targetEnv)
if err != nil {
return fmt.Errorf("[ERROR] Error retrieving cluster after waitForCluster: %s", err)
}
}

d.Set("state", clusterFields.State)
d.Set("worker_count", clusterFields.WorkerCount)
d.Set("workers", workers)
Expand Down
17 changes: 12 additions & 5 deletions ibm/service/kubernetes/data_source_ibm_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ func TestAccIBMContainerClusterDataSource_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"data.ibm_container_cluster.testacc_ds_cluster", "id"),
resource.TestCheckResourceAttrWith("data.ibm_container_cluster.testacc_ds_cluster", "state", func(value string) error {
switch value {
case "deploying", "deployed":
return nil
}
return fmt.Errorf("state is not deploying, it was %s", value)
}),
resource.TestCheckResourceAttr(
"data.ibm_container_cluster.testacc_ds_cluster", "state", "deploying"),
"data.ibm_container_cluster.testacc_ds_cluster", "worker_pools.#", "1"),
),
},
{
Config: testAccCheckIBMContainerClusterDataSourceBasic_update(clusterName),
Config: testAccCheckIBMContainerClusterDataSourceBasic_waitTillNormal(clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"data.ibm_container_cluster.testacc_ds_cluster", "id"),
Expand Down Expand Up @@ -86,16 +93,16 @@ func testAccIBMClusterVlansCheck(n string) resource.TestCheckFunc {
}

func testAccCheckIBMContainerClusterDataSourceBasic(clusterName string) string {
return testAccCheckIBMContainerClusterBasic(clusterName, "IngressReady") + `
return testAccCheckIBMContainerClusterBasic(clusterName, "MasterNodeReady") + `
data "ibm_container_cluster" "testacc_ds_cluster" {
cluster_name_id = ibm_container_cluster.testacc_cluster.id
list_bounded_services = "false"
}
`
}

func testAccCheckIBMContainerClusterDataSourceBasic_update(clusterName string) string {
return testAccCheckIBMContainerClusterBasic(clusterName, "IngressReady") + `
func testAccCheckIBMContainerClusterDataSourceBasic_waitTillNormal(clusterName string) string {
return testAccCheckIBMContainerClusterBasic(clusterName, "MasterNodeReady") + `
data "ibm_container_cluster" "testacc_ds_cluster" {
cluster_name_id = ibm_container_cluster.testacc_cluster.id
list_bounded_services = "false"
Expand Down

0 comments on commit b1220fa

Please sign in to comment.