From 0b88655b9c539847a079d832103667e24b7be5c3 Mon Sep 17 00:00:00 2001 From: Jaime Silvela Date: Fri, 16 Dec 2022 09:54:13 +0100 Subject: [PATCH] fix: filter out replicas from nodeToClusters map (#1194) We have found that using HasLabels and MatchingLabels in the same Kubernetes List call leads to only one of them being applied. See kubernetes-sigs/controller-runtime#2098 This patch fixes one occurrence of this double usage in the operator code, avoiding some unneeded reconciliation cycles. Signed-off-by: Jaime Silvela (cherry picked from commit 2aaa31c5fdb14f825c621729724545de69946881) --- controllers/cluster_controller.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/controllers/cluster_controller.go b/controllers/cluster_controller.go index 435fa81434..d953d0b469 100644 --- a/controllers/cluster_controller.go +++ b/controllers/cluster_controller.go @@ -1098,8 +1098,10 @@ func (r *ClusterReconciler) mapNodeToClusters(ctx context.Context) handler.MapFu // get all the pods handled by the operator on that node err := r.List(ctx, &childPods, client.MatchingFields{".spec.nodeName": node.Name}, - client.MatchingLabels{specs.ClusterRoleLabelName: specs.ClusterRoleLabelPrimary}, - client.HasLabels{utils.ClusterLabelName}, + client.MatchingLabels{ + specs.ClusterRoleLabelName: specs.ClusterRoleLabelPrimary, + utils.PodRoleLabelName: string(utils.PodRoleInstance), + }, ) if err != nil { log.FromContext(ctx).Error(err, "while getting primary instances for node")