Skip to content

Commit d365ccc

Browse files
committed
Make garbage collection configurable
This PR allows to configure garbage collection and define what clean-up tasks to execute during cluster deprovisioning.
1 parent 29c442b commit d365ccc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

exp/api/v1beta2/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const (
2626
// ExternalResourceGCAnnotation is the name of an annotation that indicates if
2727
// external resources should be garbage collected for the cluster.
2828
ExternalResourceGCAnnotation = "aws.cluster.x-k8s.io/external-resource-gc"
29+
30+
// ExternalResourceGCTasksAnnotation is the name of an annotation that indicates what
31+
// external resources tasks should be executed by garbage collector for the cluster.
32+
ExternalResourceGCTasksAnnotation = "aws.cluster.x-k8s.io/external-resource-tasks-gc"
2933
)
3034

3135
// EBS can be used to automatically set up EBS volumes when an instance is launched.

pkg/cloud/services/gc/cleanup.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,27 @@ func (s *Service) deleteResources(ctx context.Context) error {
6969
return fmt.Errorf("collecting resources: %w", err)
7070
}
7171

72-
if deleteErr := s.cleanupFuncs.Execute(ctx, resources); deleteErr != nil {
72+
cleanupFuncs := s.cleanupFuncs
73+
74+
if val, found := annotations.Get(s.scope.InfraCluster(), expinfrav1.ExternalResourceGCTasksAnnotation); found {
75+
var gcTaskToFunc = map[string]ResourceCleanupFunc{
76+
"load-balancer": s.deleteLoadBalancers,
77+
"target-group": s.deleteTargetGroups,
78+
"security-group": s.deleteSecurityGroups,
79+
}
80+
81+
cleanupFuncs = ResourceCleanupFuncs{}
82+
83+
tasks := strings.Split(val, ",")
84+
85+
// TODO: add some validation here.
86+
87+
for _, task := range tasks {
88+
cleanupFuncs = append(cleanupFuncs, gcTaskToFunc[task])
89+
}
90+
}
91+
92+
if deleteErr := cleanupFuncs.Execute(ctx, resources); deleteErr != nil {
7393
return fmt.Errorf("deleting resources: %w", deleteErr)
7494
}
7595

0 commit comments

Comments
 (0)