Skip to content

Commit

Permalink
#6334 Node pool destroy retry on retryable error within configured ti… (
Browse files Browse the repository at this point in the history
  • Loading branch information
mancaus authored May 27, 2020
1 parent efd663c commit e17e98b
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions google/resource_container_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,29 +395,34 @@ func resourceContainerNodePoolDelete(d *schema.ResourceData, meta interface{}) e
mutexKV.Lock(nodePoolInfo.lockKey())
defer mutexKV.Unlock(nodePoolInfo.lockKey())

var op = &containerBeta.Operation{}
var count = 0
err = resource.Retry(30*time.Second, func() *resource.RetryError {
count++
op, err = config.clientContainerBeta.Projects.Locations.
Clusters.NodePools.Delete(nodePoolInfo.fullyQualifiedName(name)).Do()
timeout := d.Timeout(schema.TimeoutDelete)
startTime := time.Now()

var operation *containerBeta.Operation
err = resource.Retry(timeout, func() *resource.RetryError {
operation, err = config.clientContainerBeta.
Projects.Locations.Clusters.NodePools.Delete(nodePoolInfo.fullyQualifiedName(name)).Do()

if err != nil {
return resource.RetryableError(err)
if isFailedPreconditionError(err) {
// We get failed precondition errors if the cluster is updating
// while we try to delete the node pool.
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}

if count == 15 {
return resource.NonRetryableError(fmt.Errorf("Error retrying to delete node pool %s", name))
}
return nil
})

if err != nil {
return fmt.Errorf("Error deleting NodePool: %s", err)
}

timeout -= time.Since(startTime)

// Wait until it's deleted
waitErr := containerOperationWait(config, op, nodePoolInfo.project, nodePoolInfo.location, "deleting GKE NodePool", d.Timeout(schema.TimeoutDelete))
waitErr := containerOperationWait(config, operation, nodePoolInfo.project, nodePoolInfo.location, "deleting GKE NodePool", timeout)
if waitErr != nil {
return waitErr
}
Expand Down

0 comments on commit e17e98b

Please sign in to comment.