From f945392b4d3608e982596e25fa1e3c83083e0579 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Mon, 18 Sep 2023 16:24:18 -0400 Subject: [PATCH] Merge pull request #990 from nasark/fix_messaging_network_policies Deploy Kafka network policies only when needed (cherry picked from commit a4e5689357a3684d48be368ae149c5703e824d16) --- .../controller/manageiq_controller.go | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/manageiq-operator/internal/controller/manageiq_controller.go b/manageiq-operator/internal/controller/manageiq_controller.go index a02e9483e..64071f632 100644 --- a/manageiq-operator/internal/controller/manageiq_controller.go +++ b/manageiq-operator/internal/controller/manageiq_controller.go @@ -673,18 +673,20 @@ func (r *ManageIQReconciler) generateNetworkPolicies(cr *miqv1alpha1.ManageIQ) e logger.Info("NetworkPolicy allow postgres has been reconciled", "component", "network_policy", "result", result) } - networkPolicyAllowKafka, mutateFunc := miqtool.NetworkPolicyAllowKafka(cr, r.Scheme, &r.Client) - if result, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, networkPolicyAllowKafka, mutateFunc); err != nil { - return err - } else if result != controllerutil.OperationResultNone { - logger.Info("NetworkPolicy allow kafka has been reconciled", "component", "network_policy", "result", result) - } + if *cr.Spec.DeployMessagingService == true { + networkPolicyAllowKafka, mutateFunc := miqtool.NetworkPolicyAllowKafka(cr, r.Scheme, &r.Client) + if result, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, networkPolicyAllowKafka, mutateFunc); err != nil { + return err + } else if result != controllerutil.OperationResultNone { + logger.Info("NetworkPolicy allow kafka has been reconciled", "component", "network_policy", "result", result) + } - networkPolicyAllowZookeeper, mutateFunc := miqtool.NetworkPolicyAllowZookeeper(cr, r.Scheme, &r.Client) - if result, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, networkPolicyAllowZookeeper, mutateFunc); err != nil { - return err - } else if result != controllerutil.OperationResultNone { - logger.Info("NetworkPolicy allow zookeeper has been reconciled", "component", "network_policy", "result", result) + networkPolicyAllowZookeeper, mutateFunc := miqtool.NetworkPolicyAllowZookeeper(cr, r.Scheme, &r.Client) + if result, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, networkPolicyAllowZookeeper, mutateFunc); err != nil { + return err + } else if result != controllerutil.OperationResultNone { + logger.Info("NetworkPolicy allow zookeeper has been reconciled", "component", "network_policy", "result", result) + } } return nil