Skip to content

Conversation

@fabianlindfors
Copy link
Contributor

@fabianlindfors fabianlindfors commented Jul 21, 2020

All Submissions:

  • Have you signed our CLA?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change

This PR implements a custom handler.EventHandler called ResourceWatcher. This will allow us to watch for changes to specific secondary resources outside of the main MDB CRD. This PR is part of the work to implement support for TLS certificate rotations. The idea is to have one ResourceWatcher on the Reconciler for each resource type we want to watch. If we for example have a secretWatcher on our Reconciler we can register it like:

// Watch for changes to primary resource MongoDB
err = c.Watch(&source.Kind{Type: &mdbv1.MongoDB{}}, &handler.EnqueueRequestForObject{}, predicates.OnlyOnSpecChange())
if err != nil {
	return err
}

// Watch for changes to secondary Secrets
err = c.Watch(&source.Kind{Type: &corev1.Secret{}}, r.secretWatcher)
if err != nil {
	return err
}

Resource to watch can then be added from the reconciliation loop using: r.secretWatcher.Watch(objectToWatch, dependentObject).

Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean implementation! I only had 2 small comments, nice work!

}

// Add will add a new object to watch.
func (w ResourceWatcher) Add(watchedName, dependentName types.NamespacedName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The name Add is a bit misleading, I think maybe something like EnsureAdded or EnsureWatched would be more accurate, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that Add is a bit misleading but I'm not sure including Ensure adds much. How about Watch? Feels natural that you would Watch with a Watcher!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm okay with Watch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed!

Comment on lines 33 to 37
for _, existingName := range existing {
if dependentName == existingName {
return
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cloud maybe add a contains.NamespacedName(nsNames, nsName) for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, added!

@fabianlindfors fabianlindfors requested a review from bznein July 21, 2020 14:11
Comment on lines +26 to +33
func NamespacedName(nsNames []types.NamespacedName, nsName types.NamespacedName) bool {
for _, elem := range nsNames {
if elem == nsName {
return true
}
}
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants