Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting up dependent watches for some resource types, even if dependent watches are disabled #19

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

misberner
Copy link
Contributor

This PR adds an WithExtraDependentWatches option, that allows marking certain resources as watched, even if dependent watches are generally disabled.

Copy link
Member

@SimonBaeumer SimonBaeumer left a comment

Choose a reason for hiding this comment

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

Nice change!
Looks good so far, I would only improve the docs and function naming a little bit to be more specific about the new use-case of the boolean parameter.

@@ -267,6 +268,16 @@ func SkipDependentWatches(skip bool) Option {
}
}

// WithExtraDependentWatches is an option that configures whether the reconciler
// will watch objects of the given kind. These objects will be watched even if
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// will watch objects of the given kind. These objects will be watched even if
// will watch objects created by the underlying Helm chart of the given kind. These objects will be watched even if

Comment on lines 39 to +40

func NewDependentResourceWatcher(c controller.Controller, rm meta.RESTMapper) hook.PostHook {
func NewDependentResourceWatcher(c controller.Controller, rm meta.RESTMapper, watchReleaseResources bool, extraWatches ...schema.GroupVersionKind) hook.PostHook {
Copy link
Member

Choose a reason for hiding this comment

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

I think it is confusing to have watchReleaseResources and extraWatches as parameters in one function and letting the caller decide which one to choose.

Imho adding two functions with different names delegating to a private newDependentResourceWatcher is preferred by me.

// NewDependentResourceWatcherForResources adds depended watches on specific configured resources. 
func NewDependentResourceWatcherForResources(c controller.Controller, rm meta.RESTMapper, watches ...schema.GroupVersionKind) hook.PostHook {
  return newDependentResourceWatcher(c, rm, false, watches)
}

// NewDependentReleaseResourceWatcher adds watchers to all objects created by the Helm release.
func NewDependentReleaseResourceWatcher(c controller.Controller, rm meta.RESTMapper) hook.PostHook {
  newDependentResourceWatcher(c, rm, true)
}

Writing documentation for it is imho more complex and involves mental overhead to understand the concept to why I should add extraWatches if I already added all watched dependencies by setting watchReleaseResources = true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But with this change we can no longer separate the "skip dependent watches" and "watch extra resources" parameters. This has to be a single watcher, we cannot just call this function once with watchReleaseResources = true and then with the extra watches; if we ever go back to not skipping dependent watches, this would cause two reconciliations for each update to the resources specified here. Maybe not a concern because we would just drop the extra watches then, but it does complicate the option design substantially.

Copy link
Member

Choose a reason for hiding this comment

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

Agree!

Comment on lines +964 to +965
if !r.skipDependentWatches || len(r.extraDependentWatches) > 0 {
r.postHooks = append([]hook.PostHook{internalhook.NewDependentResourceWatcher(c, mgr.GetRESTMapper(), !r.skipDependentWatches, r.extraDependentWatches...)}, r.postHooks...)
Copy link
Member

Choose a reason for hiding this comment

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

The renaming of the NewDependetWatches... funcs also removes the need for inverted boolean parameters:

Suggested change
if !r.skipDependentWatches || len(r.extraDependentWatches) > 0 {
r.postHooks = append([]hook.PostHook{internalhook.NewDependentResourceWatcher(c, mgr.GetRESTMapper(), !r.skipDependentWatches, r.extraDependentWatches...)}, r.postHooks...)
if !r.skipDependentWatches {
r.postHooks = append([]hook.PostHook{internalhook. NewDependentReleaseResourceWatcher(c, mgr.GetRESTMapper())}, r.postHooks...)
}
if len(r.extraDependentWatches) > 0 {
r.postHooks = append([]hook.PostHook{internalhook. NewDependentResourceWatcherForResources(c, mgr.GetRESTMapper(), r.extraDependentWatches...)}, r.postHooks...)
}

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

Successfully merging this pull request may close these issues.

3 participants