Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unregister and delete completed pods #346

Merged
merged 2 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion controllers/githubactionrunner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,18 @@ func (r *GithubActionRunnerReconciler) unregisterRunner(ctx context.Context, cr

// handleFinalization will remove runner from github based on presence of finalizer
func (r *GithubActionRunnerReconciler) handleFinalization(ctx context.Context, cr *garov1alpha1.GithubActionRunner, list podRunnerPairList) error {
for _, item := range list.getPodsBeingDeletedOrEvicted() {
for _, item := range list.getPodsBeingDeletedOrEvictedOrCompleted() {
// 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
if err := r.unregisterRunner(ctx, cr, item); err != nil {
return err
}
if isCompleted(&item.pod) {
logr.FromContext(ctx).Info("Deleting succeeded pod", "podname", item.pod.Name)
err := r.DeleteResourceIfExists(ctx, &item.pod)
if err != nil {
return err
}
}
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions controllers/podrunner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (r podRunnerPairList) getIdles(sortOrder v1alpha1.SortOrder, minTTL time.Du
return idles
}

func (r podRunnerPairList) getPodsBeingDeletedOrEvicted() []podRunnerPair {
func (r podRunnerPairList) getPodsBeingDeletedOrEvictedOrCompleted() []podRunnerPair {
return funk.Filter(r.pairs, func(pair podRunnerPair) bool {
return util.IsBeingDeleted(&pair.pod) || isEvicted(&pair.pod)
return util.IsBeingDeleted(&pair.pod) || isEvicted(&pair.pod) || isCompleted(&pair.pod)
}).([]podRunnerPair)
}
4 changes: 4 additions & 0 deletions controllers/podutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ import (
func isEvicted(pod *v1.Pod) bool {
return strings.Contains(pod.Status.Reason, "Evicted")
}

func isCompleted(pod *v1.Pod) bool {
return pod.Status.Phase == v1.PodSucceeded
}