From 08fb96eab37925d4b26aa0ef28fdd18b7344f9fd Mon Sep 17 00:00:00 2001 From: nasark Date: Thu, 14 Sep 2023 12:02:05 -0400 Subject: [PATCH] deploy kafka networkpolicies only when needed --- .../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 7948ad35..f860cfc9 100644 --- a/manageiq-operator/internal/controller/manageiq_controller.go +++ b/manageiq-operator/internal/controller/manageiq_controller.go @@ -677,18 +677,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