From 742e182c104f0ded67d0c932eaa32e2ba7bb0240 Mon Sep 17 00:00:00 2001 From: Blake Ryan Date: Mon, 11 May 2020 07:49:34 +0000 Subject: [PATCH] --- google/resource_container_node_pool.go | 27 +++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/google/resource_container_node_pool.go b/google/resource_container_node_pool.go index c0f197ab115..fac5f5fd732 100644 --- a/google/resource_container_node_pool.go +++ b/google/resource_container_node_pool.go @@ -395,20 +395,23 @@ 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 }) @@ -416,8 +419,10 @@ func resourceContainerNodePoolDelete(d *schema.ResourceData, meta interface{}) e 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 }