// Wait for at least given amount of active jobs. func waitForActiveJobs(c clientset.Interface, ns, cronJobName string, active int) error { return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) { curr, err := c.BatchV2alpha1().CronJobs(ns).Get(cronJobName, metav1.GetOptions{}) if err != nil { return false, err } return len(curr.Status.Active) >= active, nil }) }
// Wait for no jobs to appear. func waitForNoJobs(c clientset.Interface, ns, jobName string) error { return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) { curr, err := c.BatchV2alpha1().CronJobs(ns).Get(jobName) if err != nil { return false, err } return len(curr.Status.Active) != 0, nil }) }
// checkNoUnexpectedEvents checks unexpected events didn't happen. // Currently only "UnexpectedJob" is checked. func checkNoUnexpectedEvents(c clientset.Interface, ns, cronJobName string) error { sj, err := c.BatchV2alpha1().CronJobs(ns).Get(cronJobName, metav1.GetOptions{}) if err != nil { return fmt.Errorf("error in getting cronjob %s/%s: %v", ns, cronJobName, err) } events, err := c.Core().Events(ns).Search(sj) if err != nil { return fmt.Errorf("error in listing events: %s", err) } for _, e := range events.Items { if e.Reason == "UnexpectedJob" { return fmt.Errorf("found unexpected event: %#v", e) } } return nil }
func newJobInformer(client release_1_5.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { sharedIndexInformer := cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.BatchV2alpha1().Jobs(v1.NamespaceAll).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { return client.BatchV2alpha1().Jobs(v1.NamespaceAll).Watch(options) }, }, &batch_v2alpha1.Job{}, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, ) return sharedIndexInformer }
func deleteCronJob(c clientset.Interface, ns, name string) error { return c.BatchV2alpha1().CronJobs(ns).Delete(name, nil) }
func getCronJob(c clientset.Interface, ns, name string) (*batch.CronJob, error) { return c.BatchV2alpha1().CronJobs(ns).Get(name, metav1.GetOptions{}) }
func createCronJob(c clientset.Interface, ns string, cronJob *batch.CronJob) (*batch.CronJob, error) { return c.BatchV2alpha1().CronJobs(ns).Create(cronJob) }