-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package triage | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"time" | ||
) | ||
|
||
// LeftoverJobs gets a kubernetes.Clientset and a specific namespace string | ||
// then proceeds to search if there are leftover cronjobs that were inactive for more than a month | ||
func LeftoverJobs(kubeCli *kubernetes.Clientset, namespace string) (*Triage, error) { | ||
listOfTriages := make([]string, 0) | ||
|
||
jobs, err := kubeCli.BatchV1beta1().CronJobs(namespace).List(v1.ListOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
currentTime := time.Now() | ||
for _, i := range jobs.Items { | ||
if i.Status.LastScheduleTime != nil { | ||
if currentTime.Sub(i.Status.LastScheduleTime.Local()) > 31 { | ||
listOfTriages = append(listOfTriages, i.GetName()) | ||
} | ||
} | ||
|
||
} | ||
return NewTriage("CronJobs", "Found leftover cronjobs in namespace: "+namespace, listOfTriages), nil | ||
} |