Skip to content

Commit

Permalink
Merge pull request #22 from h3poteto/fix-cleanup
Browse files Browse the repository at this point in the history
fix: Find related pods using job-name to cleanup old pods
  • Loading branch information
h3poteto authored Jun 13, 2019
2 parents bc823b1 + 22012f0 commit a237271
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
log "github.com/sirupsen/logrus"

"github.com/ghodss/yaml"
"k8s.io/api/batch/v1"
v1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -227,14 +227,15 @@ func (j *Job) Cleanup() error {
if err != nil {
return err
}
log.Info("Removing the job...")
log.Infof("Removing the job: %s", j.CurrentJob.Name)
options := metav1.DeleteOptions{}
return j.client.BatchV1().Jobs(j.CurrentJob.Namespace).Delete(j.CurrentJob.Name, &options)
}

func (j *Job) removePods() error {
log.Info("Removing related pods...")
labels := parseLabels(j.CurrentJob.Spec.Template.Labels)
// Use job-name to find pods which are related the job.
labels := "job-name=" + j.CurrentJob.Name
log.Infof("Remove related pods which labels is: %s", labels)
listOptions := metav1.ListOptions{
LabelSelector: labels,
}
Expand Down
2 changes: 1 addition & 1 deletion job/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

log "github.com/sirupsen/logrus"
"k8s.io/api/batch/v1"
v1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down

0 comments on commit a237271

Please sign in to comment.