Skip to content

Commit

Permalink
Add precondition retry to node pool deletion - upstreams tpg#6334 (#3515
Browse files Browse the repository at this point in the history
)

* add precondition retry to node pool deletion - upstreams tpg#6335

* switch to Delete
  • Loading branch information
emilymye authored May 27, 2020
1 parent db86c81 commit d482e39
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions third_party/terraform/resources/resource_container_node_pool.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -395,29 +395,35 @@ 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 d482e39

Please sign in to comment.