-
Notifications
You must be signed in to change notification settings - Fork 22
/
delete.go
56 lines (49 loc) · 1.59 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package gke
import (
"context"
"strings"
"time"
gkev1 "github.com/rancher/gke-operator/pkg/apis/gke.cattle.io/v1"
"github.com/rancher/gke-operator/pkg/gke/services"
"k8s.io/apimachinery/pkg/util/wait"
)
const (
waitSec = 30
backoffSteps = 12
)
var backoff = wait.Backoff{
Duration: waitSec * time.Second,
Steps: backoffSteps,
}
// RemoveCluster attempts to delete a cluster and retries the delete request if the cluster is busy.
func RemoveCluster(ctx context.Context, gkeClient services.GKEClusterService, config *gkev1.GKEClusterConfig) error {
return wait.ExponentialBackoff(backoff, func() (bool, error) {
_, err := gkeClient.ClusterDelete(ctx,
ClusterRRN(config.Spec.ProjectID, Location(config.Spec.Region, config.Spec.Zone), config.Spec.ClusterName))
if err != nil && strings.Contains(err.Error(), errWait) {
return false, nil
}
if err != nil && strings.Contains(err.Error(), errNotFound) {
return true, nil
}
if err != nil {
return false, err
}
return true, nil
})
}
// RemoveNodePool deletes a node pool
func RemoveNodePool(ctx context.Context, gkeClient services.GKEClusterService, config *gkev1.GKEClusterConfig, nodePoolName string) (Status, error) {
_, err := gkeClient.NodePoolDelete(ctx,
NodePoolRRN(config.Spec.ProjectID, Location(config.Spec.Region, config.Spec.Zone), config.Spec.ClusterName, nodePoolName))
if err != nil && strings.Contains(err.Error(), errWait) {
return Retry, nil
}
if err != nil && strings.Contains(err.Error(), errNotFound) {
return NotChanged, nil
}
if err != nil {
return NotChanged, err
}
return Changed, nil
}