// 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 jobs to appear in the active list of a cronjob or not. // When failIfNonEmpty is set, this fails if the active set of jobs is still non-empty after // the timeout. When failIfNonEmpty is not set, this fails if the active set of jobs is still // empty after the timeout. func waitForNoJobs(c clientset.Interface, ns, jobName string, failIfNonEmpty bool) error { return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) { curr, err := c.BatchV2alpha1().CronJobs(ns).Get(jobName, metav1.GetOptions{}) if err != nil { return false, err } if failIfNonEmpty { return len(curr.Status.Active) == 0, nil } else { 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 newCronJobInformer(client clientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { sharedIndexInformer := cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.BatchV2alpha1().CronJobs(v1.NamespaceAll).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { return client.BatchV2alpha1().CronJobs(v1.NamespaceAll).Watch(options) }, }, &batch_v2alpha1.CronJob{}, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, ) return sharedIndexInformer }
// checkNoEventWithReason checks no events with a reason within a list has occured func checkNoEventWithReason(c clientset.Interface, ns, cronJobName string, reasons []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 { for _, reason := range reasons { if e.Reason == reason { return fmt.Errorf("Found event with reason %s: %#v", reason, e) } } } return nil }
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) }