Skip to content

Instantly share code, notes, and snippets.

@d-kuro
Created March 7, 2019 19:44
Show Gist options
  • Save d-kuro/4ced00b833688ef6c5f0db78215ff67a to your computer and use it in GitHub Desktop.
Save d-kuro/4ced00b833688ef6c5f0db78215ff67a to your computer and use it in GitHub Desktop.
// from: https://github.com/kubernetes/kubernetes/blob/87f9429087d4e31201412548517d36e83abebc8d/pkg/controller/cronjob/utils.go#L74-L87
// groupJobsByParent groups jobs into a map keyed by the job parent UID (e.g. scheduledJob).
// It has no receiver, to facilitate testing.
func groupJobsByParent(js []batchv1.Job) map[types.UID][]batchv1.Job {
jobsBySj := make(map[types.UID][]batchv1.Job)
for _, job := range js {
parentUID, found := getParentUIDFromJob(job)
if !found {
klog.V(4).Infof("Unable to get parent uid from job %s in namespace %s", job.Name, job.Namespace)
continue
}
jobsBySj[parentUID] = append(jobsBySj[parentUID], job)
}
return jobsBySj
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment