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 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
func main() {
{....}
namespace, err := k8sutil.GetWatchNamespace()
handleManagerPerNamespace(cfg, string(namespace))
watchAppNamespacesEnvVar , err := utils.GetAppNamespaces()
if err != nil {
log.Error(err, "Failed to get APP_NAMESPACES")
os.Exit(1)
}
for _, ns := range strings.Split(watchAppNamespacesEnvVar, ";") {
log.Info("Creating manager for the namespace: " + string(ns))
handleManagerPerNamespace(cfg, string(ns))
}
{....}
}
func handleManagerPerNamespace(cfg *rest.Config, ns string) {
mgr := createNamespaceCmdManager(cfg, ns)
addSchemeToManager(mgr)
startCmdManager(mgr)
}
func createNamespaceCmdManager(cfg *rest.Config, namespace string) manager.Manager {
mgr, err := manager.New(cfg, manager.Options{
Namespace: namespace,
})
if err != nil {
log.Error(err, "")
os.Exit(1)
}
return mgr
}
func startCmdManager(mgr manager.Manager) {
log.Info("Starting the Cmd.")
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Error(err, "Manager exited non-zero")
os.Exit(1)
}
}
func addSchemeToManager(mgr manager.Manager) {
log.Info("Registering Components.")
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
os.Exit(1)
}
if err := routev1.AddToScheme(mgr.GetScheme().); err != nil {
log.Error(err, "")
os.Exit(1)
}
if err := controller.AddToManager(mgr); err != nil {
log.Error(err, "")
os.Exit(1)
}
}
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. 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. c/c David Ffrench Wei Li Peter Braun Christopher Foley |