Skip to content

Commit cd45f46

Browse files
lukashybner-ext90548Lukas Hybner
andauthored
Unregister and delete completed pods (#346)
Co-authored-by: Lukas Hybner <[email protected]>
1 parent ba5cb01 commit cd45f46

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

controllers/githubactionrunner_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,18 @@ func (r *GithubActionRunnerReconciler) unregisterRunner(ctx context.Context, cr
359359

360360
// handleFinalization will remove runner from github based on presence of finalizer
361361
func (r *GithubActionRunnerReconciler) handleFinalization(ctx context.Context, cr *garov1alpha1.GithubActionRunner, list podRunnerPairList) error {
362-
for _, item := range list.getPodsBeingDeletedOrEvicted() {
362+
for _, item := range list.getPodsBeingDeletedOrEvictedOrCompleted() {
363363
// TODO - cause of failure should be checked more closely, if it does not exist we can ignore it. If it is a comms error we should stick around
364364
if err := r.unregisterRunner(ctx, cr, item); err != nil {
365365
return err
366366
}
367+
if isCompleted(&item.pod) {
368+
logr.FromContext(ctx).Info("Deleting succeeded pod", "podname", item.pod.Name)
369+
err := r.DeleteResourceIfExists(ctx, &item.pod)
370+
if err != nil {
371+
return err
372+
}
373+
}
367374
}
368375

369376
return nil

controllers/podrunner_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ func (r podRunnerPairList) getIdles(sortOrder v1alpha1.SortOrder, minTTL time.Du
9393
return idles
9494
}
9595

96-
func (r podRunnerPairList) getPodsBeingDeletedOrEvicted() []podRunnerPair {
96+
func (r podRunnerPairList) getPodsBeingDeletedOrEvictedOrCompleted() []podRunnerPair {
9797
return funk.Filter(r.pairs, func(pair podRunnerPair) bool {
98-
return util.IsBeingDeleted(&pair.pod) || isEvicted(&pair.pod)
98+
return util.IsBeingDeleted(&pair.pod) || isEvicted(&pair.pod) || isCompleted(&pair.pod)
9999
}).([]podRunnerPair)
100100
}

controllers/podutil.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ import (
88
func isEvicted(pod *v1.Pod) bool {
99
return strings.Contains(pod.Status.Reason, "Evicted")
1010
}
11+
12+
func isCompleted(pod *v1.Pod) bool {
13+
return pod.Status.Phase == v1.PodSucceeded
14+
}

0 commit comments

Comments
 (0)