From 0c2091e7d974b9e5866b58b87c9749e79e636304 Mon Sep 17 00:00:00 2001 From: Artur Zheludkov Date: Thu, 8 Feb 2024 09:59:01 -0500 Subject: [PATCH] add podselector labels --- operator/redisfailover/service/generator.go | 9 +++++++- .../redisfailover/service/generator_test.go | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 23c2a5a52..5798f28fe 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -486,6 +486,8 @@ func generateSentinelNetworkPolicy(rf *redisfailoverv1.RedisFailover, labels map Port: &sentinelTargetPort, }) + redisfailoverLabels := map[string]string{"redisfailovers.databases.spotahome.com/name": rf.Name} + return &np.NetworkPolicy{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -496,7 +498,7 @@ func generateSentinelNetworkPolicy(rf *redisfailoverv1.RedisFailover, labels map Spec: np.NetworkPolicySpec{ PodSelector: metav1.LabelSelector{ MatchLabels: util.MergeLabels( - map[string]string{"redisfailovers.databases.spotahome.com/name": rf.Name}, + redisfailoverLabels, generateComponentLabel("sentinel"), ), }, @@ -516,6 +518,11 @@ func generateSentinelNetworkPolicy(rf *redisfailoverv1.RedisFailover, labels map }, }, }, + np.NetworkPolicyPeer{ + PodSelector: &metav1.LabelSelector{ + MatchLabels: redisfailoverLabels, + }, + }, }, }, }, diff --git a/operator/redisfailover/service/generator_test.go b/operator/redisfailover/service/generator_test.go index e8f04bd5e..b439fffab 100644 --- a/operator/redisfailover/service/generator_test.go +++ b/operator/redisfailover/service/generator_test.go @@ -1488,6 +1488,13 @@ func TestSentinelNetworkPolicy(t *testing.T) { }, }, }, + networkingv1.NetworkPolicyPeer{ + PodSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "redisfailovers.databases.spotahome.com/name": name, + }, + }, + }, }, }, }, @@ -1557,6 +1564,13 @@ func TestSentinelNetworkPolicy(t *testing.T) { }, }, }, + networkingv1.NetworkPolicyPeer{ + PodSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "redisfailovers.databases.spotahome.com/name": name, + }, + }, + }, }, }, }, @@ -1636,6 +1650,13 @@ func TestSentinelNetworkPolicy(t *testing.T) { }, }, }, + networkingv1.NetworkPolicyPeer{ + PodSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "redisfailovers.databases.spotahome.com/name": name, + }, + }, + }, }, }, },