Skip to content

Commit 3afe005

Browse files
committed
OCPBUGS-65512: Removing resources on destroy by other filters
** Firewall rules seem to be an issue on destroy with load balancers. The load balancers may have resource names created with a name such as a9123-xxxxx-xxxx. These resources are only discovered once, and it is possible when a failure occurs that the destroy process will skip finding these resources later. Now the firewall rules will be found using the name OR target tags. When the name does not appear to be part of the cluster (including the cluster id), then the target tags should be searched to determine if they are part of the cluster. This should handle the load balancer resources too.
1 parent 4180662 commit 3afe005

File tree

2 files changed

+24
-52
lines changed

2 files changed

+24
-52
lines changed

pkg/destroy/gcp/cloudcontroller.go

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -127,33 +127,14 @@ func (o *ClusterUninstaller) discoverCloudControllerLoadBalancerResources(ctx co
127127
}
128128
o.insertPendingItems(regionalAddressResource, found)
129129

130-
// Discover associated firewall rules: loadBalancerName
131-
found, err = o.listFirewallsWithFilter(ctx, "items(name),nextPageToken", loadBalancerFilterFunc)
132-
if err != nil {
133-
return err
134-
}
135-
o.insertPendingItems(firewallResourceName, found)
136-
137-
// Discover associated firewall rules: loadBalancerName-hc
138-
found, err = o.listFirewallsWithFilter(ctx, "items(name),nextPageToken", o.createLoadBalancerFilterFunc(fmt.Sprintf("%s-hc", loadBalancerName)))
139-
if err != nil {
140-
return err
141-
}
142-
o.insertPendingItems(firewallResourceName, found)
143-
144-
// Discover associated firewall rules: k8s-fw-loadBalancerName
145-
found, err = o.listFirewallsWithFilter(ctx, "items(name),nextPageToken",
146-
o.createLoadBalancerFilterFunc(fmt.Sprintf("k8s-fw-%s", loadBalancerName)),
147-
)
148-
if err != nil {
149-
return err
150-
}
151-
o.insertPendingItems(firewallResourceName, found)
152-
153-
// Discover associated firewall rules: k8s-loadBalancerName-http-hc
154-
found, err = o.listFirewallsWithFilter(ctx, "items(name),nextPageToken",
155-
o.createLoadBalancerFilterFunc(fmt.Sprintf("k8s-%s-http-hc", loadBalancerName)),
156-
)
130+
// Discover associated firewall rules:
131+
// 1. loadBalancerName
132+
// 2. loadBalancerName-hc
133+
// 3. k8s-fw-loadBalancerName
134+
// 4. k8s-loadBalancerName-http-hc
135+
// 5. k8s-%s-node-hc
136+
// 6. k8s-%s-node-http-hc
137+
found, err = o.listFirewallsWithFilter(ctx, "items(name,targetTags),nextPageToken", o.firewallFilterFunc)
157138
if err != nil {
158139
return err
159140
}
@@ -271,23 +252,6 @@ func (o *ClusterUninstaller) discoverCloudControllerResources(ctx context.Contex
271252
return err
272253
}
273254
o.insertPendingItems(httpHealthCheckResourceName, found)
274-
275-
// Discover Cloud Controller firewall rules: k8s-cloudControllerUID-node-hc, k8s-cloudControllerUID-node-http-hc
276-
found, err = o.listFirewallsWithFilter(ctx, "items(name),nextPageToken",
277-
o.createLoadBalancerFilterFunc(fmt.Sprintf("k8s-%s-node-hc", o.cloudControllerUID)),
278-
)
279-
if err != nil {
280-
return err
281-
}
282-
o.insertPendingItems(firewallResourceName, found)
283-
284-
found, err = o.listFirewallsWithFilter(ctx, "items(name),nextPageToken",
285-
o.createLoadBalancerFilterFunc(fmt.Sprintf("k8s-%s-node-http-hc", o.cloudControllerUID)),
286-
)
287-
if err != nil {
288-
return err
289-
}
290-
o.insertPendingItems(firewallResourceName, found)
291255
}
292256

293257
return aggregateError(errs, 0)

pkg/destroy/gcp/firewall.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@ const (
1515
firewallResourceName = "firewall"
1616
)
1717

18+
func (o *ClusterUninstaller) firewallFilterFunc(item *compute.Firewall) bool {
19+
if strings.Contains(item.Name, o.ClusterID) {
20+
return true
21+
}
22+
for _, tag := range item.TargetTags {
23+
if o.isClusterResource(tag) {
24+
return true
25+
}
26+
}
27+
return false
28+
}
29+
1830
func (o *ClusterUninstaller) listFirewalls(ctx context.Context) ([]cloudResource, error) {
19-
// The firewall rules that the destroyer is searching for here include a
20-
// pattern before and after the cluster ID. Use a regular expression that allows
21-
// wildcard values before and after the cluster ID.
22-
return o.listFirewallsWithFilter(ctx, "items(name),nextPageToken", func(item string) bool {
23-
return strings.Contains(item, o.ClusterID)
24-
})
31+
return o.listFirewallsWithFilter(ctx, "items(name,targetTags),nextPageToken", o.firewallFilterFunc)
2532
}
2633

2734
// listFirewallsWithFilter lists firewall rules in the project that satisfy the filter criteria.
2835
// The fields parameter specifies which fields should be returned in the result, the filter string contains
2936
// a filter string passed to the API to filter results. The filterFunc is a client-side filtering function
3037
// that determines whether a particular result should be returned or not.
31-
func (o *ClusterUninstaller) listFirewallsWithFilter(ctx context.Context, fields string, filterFunc resourceFilterFunc) ([]cloudResource, error) {
38+
func (o *ClusterUninstaller) listFirewallsWithFilter(ctx context.Context, fields string, filterFunc func(item *compute.Firewall) bool) ([]cloudResource, error) {
39+
//func (o *ClusterUninstaller) listFirewallsWithFilter(ctx context.Context, fields string, filterFunc resourceFilterFunc) ([]cloudResource, error) {
3240
o.Logger.Debugf("Listing firewall rules")
3341
results := []cloudResource{}
3442

@@ -40,7 +48,7 @@ func (o *ClusterUninstaller) listFirewallsWithFilter(ctx context.Context, fields
4048

4149
err := req.Pages(ctx, func(list *compute.FirewallList) error {
4250
for _, item := range list.Items {
43-
if filterFunc(item.Name) {
51+
if filterFunc(item) {
4452
o.Logger.Debugf("Found firewall rule: %s", item.Name)
4553
result = append(result, cloudResource{
4654
key: item.Name,

0 commit comments

Comments
 (0)