File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ const (
26
26
// ExternalResourceGCAnnotation is the name of an annotation that indicates if
27
27
// external resources should be garbage collected for the cluster.
28
28
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"
29
33
)
30
34
31
35
// EBS can be used to automatically set up EBS volumes when an instance is launched.
Original file line number Diff line number Diff line change @@ -69,7 +69,27 @@ func (s *Service) deleteResources(ctx context.Context) error {
69
69
return fmt .Errorf ("collecting resources: %w" , err )
70
70
}
71
71
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 {
73
93
return fmt .Errorf ("deleting resources: %w" , deleteErr )
74
94
}
75
95
You can’t perform that action at this time.
0 commit comments