From fa63b4db12ad52166c316c861afbf87ab271adfb Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Fri, 11 Oct 2024 19:25:30 +0200 Subject: [PATCH] update: use namespace dyniamically from operator env than hardcode value (#1298) - thses are only needed when it is downstream speicific cases Signed-off-by: Wen Zhou --- controllers/dscinitialization/utils.go | 8 +++++++- main.go | 6 +++++- pkg/cluster/cluster_config.go | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/controllers/dscinitialization/utils.go b/controllers/dscinitialization/utils.go index b2990c68ef3..e2e0cd10b22 100644 --- a/controllers/dscinitialization/utils.go +++ b/controllers/dscinitialization/utils.go @@ -195,8 +195,14 @@ func (r *DSCInitializationReconciler) createDefaultRoleBinding(ctx context.Conte func (r *DSCInitializationReconciler) reconcileDefaultNetworkPolicy(ctx context.Context, name string, dscInit *dsciv1.DSCInitialization, platform cluster.Platform) error { log := r.Log if platform == cluster.ManagedRhods || platform == cluster.SelfManagedRhods { + // Get operator namepsace + operatorNs, err := cluster.GetOperatorNamespace() + if err != nil { + log.Error(err, "error getting operator namespace for networkplicy creation") + return err + } // Deploy networkpolicy for operator namespace - err := deploy.DeployManifestsFromPath(ctx, r.Client, dscInit, networkpolicyPath+"/operator", "redhat-ods-operator", "networkpolicy", true) + err = deploy.DeployManifestsFromPath(ctx, r.Client, dscInit, networkpolicyPath+"/operator", operatorNs, "networkpolicy", true) if err != nil { log.Error(err, "error to set networkpolicy in operator namespace", "path", networkpolicyPath) return err diff --git a/main.go b/main.go index 778a829f5ee..c7d38cfb1c3 100644 --- a/main.go +++ b/main.go @@ -359,7 +359,11 @@ func createSecretCacheConfig(platform cluster.Platform) map[string]cache.Config case cluster.ManagedRhods: namespaceConfigs["redhat-ods-monitoring"] = cache.Config{} namespaceConfigs["redhat-ods-applications"] = cache.Config{} - namespaceConfigs["redhat-ods-operator"] = cache.Config{} + operatorNs, err := cluster.GetOperatorNamespace() + if err != nil { + operatorNs = "redhat-ods-operator" // fall back case + } + namespaceConfigs[operatorNs] = cache.Config{} case cluster.SelfManagedRhods: namespaceConfigs["redhat-ods-applications"] = cache.Config{} default: diff --git a/pkg/cluster/cluster_config.go b/pkg/cluster/cluster_config.go index 22a3b6b574e..442878baf2f 100644 --- a/pkg/cluster/cluster_config.go +++ b/pkg/cluster/cluster_config.go @@ -160,7 +160,11 @@ func detectSelfManaged(ctx context.Context, cli client.Client) (Platform, error) // detectManagedRHODS checks if catsrc CR add-on exists ManagedRhods. func detectManagedRHODS(ctx context.Context, cli client.Client) (Platform, error) { catalogSource := &ofapiv1alpha1.CatalogSource{} - err := cli.Get(ctx, client.ObjectKey{Name: "addon-managed-odh-catalog", Namespace: "redhat-ods-operator"}, catalogSource) + operatorNs, err := GetOperatorNamespace() + if err != nil { + operatorNs = "redhat-ods-operator" + } + err = cli.Get(ctx, client.ObjectKey{Name: "addon-managed-odh-catalog", Namespace: operatorNs}, catalogSource) if err != nil { return Unknown, client.IgnoreNotFound(err) }