Skip to content

Commit

Permalink
cleanup orphaned pods left from removed jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
pepov committed Sep 24, 2020
1 parent f04024b commit 817364f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/helm/templatereconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package templatereconciler

import (
"context"
"net/http"
"time"

Expand Down Expand Up @@ -194,6 +195,17 @@ func (rec *HelmReconciler) reconcile(parent reconciler.ResourceOwner, component
return result, err
}

if !component.Enabled(parent) {
// cleanup orphaned pods left from removed jobs
if err := rec.client.DeleteAllOf(context.TODO(), &v1.Pod{},
client.MatchingLabels{"release": releaseData.ReleaseName},
client.HasLabels{"job-name"},
client.InNamespace(releaseData.Namespace),
); err != nil {
return result, errors.WrapIf(err, "failed to remove pods left from the release")
}
}

rec.logger.Info("reconciled")

return result, nil
Expand Down

0 comments on commit 817364f

Please sign in to comment.