Skip to content

Having problems with the writing tests section of the Building Cronjob tutorial in the docs #4816

Closed Answered by jwilkicki
jwilkicki asked this question in Support
Discussion options

You must be logged in to vote

I found the answer by resetting back to the working code from the tutorial and then applying my refactorings one by one. It came down to this code:

// SetupWithManager sets up the controller with the Manager.
func (r *CronJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
	// set up a real clock, since we're not in a test
	if r.Clock == nil {
		r.Clock = realClock{}
	}

	if err := mgr.GetFieldIndexer().IndexField(context.Background(), &kbatch.Job{}, jobOwnerKey, func(rawObj client.Object) []string {
		// grab the job object, extract the owner...
		job := rawObj.(*kbatch.Job)
		owner := metav1.GetControllerOf(job)
		if owner == nil {
			return nil
		}
		// ...make sure it's a CronJo…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jwilkicki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
1 participant