controller: pass `ctx` parameter from top level to sub functions, instead of creating one new or using default context
What would you like to be added:
pass ctx parameter from top level to sub functions, instead of creating one new or using default context
Why is this needed:
- When create controllerManager,
Options.BaseContextis empty: https://github.com/karmada-io/karmada/blob/026781f207005c07b5f4cb0e76cf79b055bf53c0/cmd/controller-manager/app/controllermanager.go#L117
https://github.com/karmada-io/karmada/blob/026781f207005c07b5f4cb0e76cf79b055bf53c0/vendor/sigs.k8s.io/controller-runtime/pkg/manager/manager.go#L245
- When create
Runnables,Options.BaseContextempty, sorunnableGroup.ctxwill bedefaultBaseContext: https://github.com/karmada-io/karmada/blob/026781f207005c07b5f4cb0e76cf79b055bf53c0/vendor/sigs.k8s.io/controller-runtime/pkg/manager/manager.go#L616
https://github.com/karmada-io/karmada/blob/026781f207005c07b5f4cb0e76cf79b055bf53c0/vendor/sigs.k8s.io/controller-runtime/pkg/manager/runnable_group.go#L103
-
When run resource
reconcilefunction, they use thedefaultBaseContext: https://github.com/karmada-io/karmada/blob/026781f207005c07b5f4cb0e76cf79b055bf53c0/vendor/sigs.k8s.io/controller-runtime/pkg/manager/runnable_group.go#L219 -
this
ctxwill be passed to resourceReconcilefunction: https://github.com/karmada-io/karmada/blob/026781f207005c07b5f4cb0e76cf79b055bf53c0/pkg/controllers/namespace/namespace_sync_controller.go#L49
This will cause: cancel signal can't control some sub functions
cc @RainbowMango
/kind cleanup /remove-kind feature
@jwcesign Hi , I just take a pr for that , PTAL