@@ -4,6 +4,7 @@ package alloydb
4
4
5
5
import (
6
6
"context"
7
+ "fmt"
7
8
"log"
8
9
"strings"
9
10
"testing"
@@ -49,7 +50,8 @@ func testSweepAlloydbCluster(region string) error {
49
50
},
50
51
}
51
52
52
- listTemplate := strings .Split ("https://alloydb.googleapis.com/v1beta/projects/{{project}}/locations/{{location}}/clusters" , "?" )[0 ]
53
+ // manual patch: use aggregated list instead of sweeper-specific location. This will clear secondary clusters.
54
+ listTemplate := strings .Split ("https://alloydb.googleapis.com/v1beta/projects/{{project}}/locations/-/clusters" , "?" )[0 ]
53
55
listUrl , err := tpgresource .ReplaceVars (d , config , listTemplate )
54
56
if err != nil {
55
57
log .Printf ("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s" , err )
@@ -81,29 +83,19 @@ func testSweepAlloydbCluster(region string) error {
81
83
nonPrefixCount := 0
82
84
for _ , ri := range rl {
83
85
obj := ri .(map [string ]interface {})
84
- var name string
85
- // Id detected in the delete URL, attempt to use id.
86
- if obj ["id" ] != nil {
87
- name = tpgresource .GetResourceNameFromSelfLink (obj ["id" ].(string ))
88
- } else if obj ["name" ] != nil {
89
- name = tpgresource .GetResourceNameFromSelfLink (obj ["name" ].(string ))
90
- } else {
91
- log .Printf ("[INFO][SWEEPER_LOG] %s resource name and id were nil" , resourceName )
92
- return nil
93
- }
86
+
87
+ // manual patch: use raw name for url instead of constructing it, so that resource locations are supplied through aggregated list
88
+ // manual patch: Using the force=true ensures that we delete instances as well.
89
+ name := obj ["name" ].(string )
90
+ shortname := tpgresource .GetResourceNameFromSelfLink (name )
94
91
// Skip resources that shouldn't be sweeped
95
- if ! sweeper .IsSweepableTestResource (name ) {
92
+ if ! sweeper .IsSweepableTestResource (shortname ) {
96
93
nonPrefixCount ++
97
94
continue
98
95
}
99
96
100
- deleteTemplate := "https://alloydb.googleapis.com/v1beta/projects/{{project}}/locations/{{location}}/clusters/{{cluster_id}}"
101
- deleteUrl , err := tpgresource .ReplaceVars (d , config , deleteTemplate )
102
- if err != nil {
103
- log .Printf ("[INFO][SWEEPER_LOG] error preparing delete url: %s" , err )
104
- return nil
105
- }
106
- deleteUrl = deleteUrl + name + "?force=true"
97
+ deleteTemplate := "https://alloydb.googleapis.com/v1beta/%s?force=true"
98
+ deleteUrl := fmt .Sprintf (deleteTemplate , name )
107
99
108
100
// Don't wait on operations as we may have a lot to delete
109
101
_ , err = transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
@@ -116,7 +108,7 @@ func testSweepAlloydbCluster(region string) error {
116
108
if err != nil {
117
109
log .Printf ("[INFO][SWEEPER_LOG] Error deleting for url %s : %s" , deleteUrl , err )
118
110
} else {
119
- log .Printf ("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s" , resourceName , name )
111
+ log .Printf ("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s" , name , shortname )
120
112
}
121
113
}
122
114
0 commit comments