Skip to content

Commit

Permalink
add podselector labels
Browse files Browse the repository at this point in the history
  • Loading branch information
rurkss committed Feb 8, 2024
1 parent 01ae991 commit 0c2091e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 8 additions & 1 deletion operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
),
},
Expand All @@ -516,6 +518,11 @@ func generateSentinelNetworkPolicy(rf *redisfailoverv1.RedisFailover, labels map
},
},
},
np.NetworkPolicyPeer{
PodSelector: &metav1.LabelSelector{
MatchLabels: redisfailoverLabels,
},
},
},
},
},
Expand Down
21 changes: 21 additions & 0 deletions operator/redisfailover/service/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,13 @@ func TestSentinelNetworkPolicy(t *testing.T) {
},
},
},
networkingv1.NetworkPolicyPeer{
PodSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"redisfailovers.databases.spotahome.com/name": name,
},
},
},
},
},
},
Expand Down Expand Up @@ -1557,6 +1564,13 @@ func TestSentinelNetworkPolicy(t *testing.T) {
},
},
},
networkingv1.NetworkPolicyPeer{
PodSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"redisfailovers.databases.spotahome.com/name": name,
},
},
},
},
},
},
Expand Down Expand Up @@ -1636,6 +1650,13 @@ func TestSentinelNetworkPolicy(t *testing.T) {
},
},
},
networkingv1.NetworkPolicyPeer{
PodSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"redisfailovers.databases.spotahome.com/name": name,
},
},
},
},
},
},
Expand Down

0 comments on commit 0c2091e

Please sign in to comment.