h4. What was done here?
In the following PR we added a workaround to not allow apply the APP CR in a namespace which is not declared in an ENV VAR. In this way, the operator will work with apps which are just applied in the specific namespaces as it is done currently for Graphana.
PR: https://github.com/aerogear/mobile-security-service-operator/pull/57
h4. Was possible impl the workarround to create N managers to watch/cache just the declared namespaces in the EnvVar? I tried this suggested approach but it doesn't work. Following the code impl to check it in the main.go
{code:java} func main() {
{....} //Create cmd Manager for the Operator namespace, err := k8sutil.GetWatchNamespace() handleManagerPerNamespace(cfg, string(namespace))
//Get all custom namespace which will be watched by the operator watchAppNamespacesEnvVar , err := utils.GetAppNamespaces() if err != nil { log.Error(err, "Failed to get APP_NAMESPACES") os.Exit(1) }
//Create a cmd manager and add schemas for each namespace specified in the APP_NAMESPACES env var for _, ns := range strings.Split(watchAppNamespacesEnvVar, ";") { log.Info("Creating manager for the namespace: " + string(ns)) handleManagerPerNamespace(cfg, string(ns)) }
{....} }
//handleManagerPerNamespace create the manager, add schemas and start it func handleManagerPerNamespace(cfg *rest.Config, ns string) { mgr := createNamespaceCmdManager(cfg, ns) addSchemeToManager(mgr) startCmdManager(mgr) }
//createNamespaceCmdManager creates a manager for an specific Namespace func createNamespaceCmdManager(cfg *rest.Config, namespace string) manager.Manager { // Create a new Cmd to provide shared dependencies and start components mgr, err := manager.New(cfg, manager.Options{ Namespace: namespace, })
if err != nil { log.Error(err, "") os.Exit(1) } return mgr }
//startCmdManager func startCmdManager(mgr manager.Manager) { log.Info("Starting the Cmd.") // Start the Cmd if err := mgr.Start(signals.SetupSignalHandler()); err != nil { log.Error(err, "Manager exited non-zero") os.Exit(1) } }
//addSchemeToManager will register the schemas for each manager func addSchemeToManager(mgr manager.Manager) { log.Info("Registering Components.") // Setup Scheme for all resources if err := apis.AddToScheme(mgr.GetScheme()); err != nil { log.Error(err, "") os.Exit(1) } //Add route Openshift scheme if err := routev1.AddToScheme(mgr.GetScheme().); err != nil { log.Error(err, "") os.Exit(1) } // Setup all Controllers if err := controller.AddToManager(mgr); err != nil { log.Error(err, "") os.Exit(1) } }
{code}
*IMPORTANT:* The controller/reconcile impl of this oper will use the cmd.manager to manage the resources and it does not work for namespaces which are not passed as an option for its watch/cache besides the comments in the code of ks8 shows that it will be restrictive for the CR/reconcile actions . h4. Will we able to do it in the future?
The great news that I'd like to share with you is that the solution for it is impl already and merged in the master branch see the commit[1] and the test[2] with this need attended.
Unfortunately, show that the version released with, v0.2.0-alpha.0[3], has break changes and cannot be used with the current version of OCP 3.11 and the Kube used by it.
We opened an issue in this repo to ask if they can release a new stable version for we are able to get this feature/implementation. See here[4].
[1] - https://github.com/kubernetes-sigs/controller-runtime/commit/fc804a411c06919561edbcb0453601c436556613 [2] - https://github.com/kubernetes-sigs/controller-runtime/blob/68ae79ea094aab567d78d7d8596accac2dc27fd0/pkg/manager/example_test.go#L59 [3] - https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.2.0-alpha.0 [4] - https://github.com/kubernetes-sigs/controller-runtime/issues/413
*IMPORTANT:* The author of this impl works in RedHat and I already speak with him before. I am trying to contact him privately to check if they can release a new stable version with just this feature impl to attend us. I will send an email in the operator-sdk too and check if they can attend us and/or check what they can suggest/recommend as a workaround.
c/c [~dffrench] [~weil] [~peter.braun] [~chrisfoley]
|
|