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

fix: ibm_container_worker_pool_zone_attachment should wait for ALBs #1373

Merged
merged 2 commits into from
Apr 28, 2020
Merged
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
56 changes: 56 additions & 0 deletions ibm/resource_ibm_container_worker_pool_zone_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func resourceIBMContainerWorkerPoolZoneAttachmentCreate(d *schema.ResourceData,
"Error waiting for workers of worker pool (%s) of cluster (%s) to become ready: %s", workerPool, cluster, err)
}

_, err = waitForWorkerZoneALB(cluster, zone, meta, d.Timeout(schema.TimeoutUpdate), targetEnv)
if err != nil {
return fmt.Errorf(
"Error waiting for ALBs in zone (%s) of cluster (%s) to become ready: %s", zone, cluster, err)
}

return resourceIBMContainerWorkerPoolZoneAttachmentRead(d, meta)

}
Expand Down Expand Up @@ -356,3 +362,53 @@ func workerPoolZoneDeleteStateRefreshFunc(client v1.Workers, instanceID, workerP
return workerFields, workerDeleteState, nil
}
}

func waitForWorkerZoneALB(clusterNameOrID, zone string, meta interface{}, timeout time.Duration, target v1.ClusterTargetHeader) (interface{}, error) {
csClient, err := meta.(ClientSession).ContainerAPI()
if err != nil {
return nil, err
}

stateConf := &resource.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"ready"},
Refresh: workerZoneALBStateRefreshFunc(csClient.Albs(), clusterNameOrID, zone, target),
Timeout: timeout,
Delay: 10 * time.Second,
MinTimeout: 10 * time.Second,
}

return stateConf.WaitForState()
}

func workerZoneALBStateRefreshFunc(client v1.Albs, instanceID, zone string, target v1.ClusterTargetHeader) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
// Get all ALBs associated with cluster
albs, err := client.ListClusterALBs(instanceID, target)
if err != nil {
return nil, "", fmt.Errorf("Error retrieving ALBs for cluster: %s", err)
}

privateALBsByZone := []v1.ALBConfig{}
publicALBsByZone := []v1.ALBConfig{}

// Find ALBs by zone and type
for _, alb := range albs {
if alb.Zone == zone {
if alb.ALBType == "private" {
privateALBsByZone = append(privateALBsByZone, alb)
}
if alb.ALBType == "public" {
publicALBsByZone = append(publicALBsByZone, alb)
}
}
}

// Ready if both private and public ALBs are present
if len(privateALBsByZone) > 0 && len(publicALBsByZone) > 0 {
return albs, "ready", nil
}

return albs, "pending", nil
}
}