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

Add controller to the manager dynamically at runtime #1994

Closed
clyang82 opened this issue Sep 6, 2022 · 3 comments
Closed

Add controller to the manager dynamically at runtime #1994

clyang82 opened this issue Sep 6, 2022 · 3 comments

Comments

@clyang82
Copy link
Contributor

clyang82 commented Sep 6, 2022

I have a use case is:

  1. the CRD does not exist in the runtime environment at the beginning.
  2. if the users create this CRD and CR, I want to start a controller to watch the CR for reconciling.

for this case, I cannot add this controller to the manager before the manager starts, because the CRD does not exist. so I want to watch the CustomResourceDefinitions to see if my desired CRD is created and the CR is also created, then I want to dynamically start a controller to watch this CR. Is it possible to add a controller to the manager when the manager is running? or How can I start the controller manually? I saw the controller is not exposed -

blder.ctrl, err = newController(controllerName, blder.mgr, ctrlOptions)

Thanks.

@clyang82
Copy link
Contributor Author

clyang82 commented Sep 7, 2022

@DirectXMan12 any insights or best practices can be shared? Thanks.

@FillZpp
Copy link
Contributor

FillZpp commented Sep 8, 2022

Is it possible to add a controller to the manager when the manager is running?

Yes.

How can I start the controller manually?

Same as the normal ones:

func (r *YourDynamicController) SetupWithManager(mgr ctrl.Manager) error {
	return ctrl.NewControllerManagedBy(mgr).
		For(&groupversion.Foo{}).
		Complete(r)
}

@clyang82
Copy link
Contributor Author

clyang82 commented Sep 9, 2022

Yes. It works. Thanks @FillZpp

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

No branches or pull requests

2 participants