From 6009cd36fc6319da6114c1c868e04210b4eb6a17 Mon Sep 17 00:00:00 2001 From: Luca Miccini Date: Thu, 24 Oct 2024 14:33:20 +0200 Subject: [PATCH] Add Affinity to Redis --- pkg/redis/statefulset.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/redis/statefulset.go b/pkg/redis/statefulset.go index f87263c0..85615cb4 100644 --- a/pkg/redis/statefulset.go +++ b/pkg/redis/statefulset.go @@ -5,6 +5,7 @@ import ( redisv1 "github.com/openstack-k8s-operators/infra-operator/apis/redis/v1beta1" common "github.com/openstack-k8s-operators/lib-common/modules/common" + "github.com/openstack-k8s-operators/lib-common/modules/common/affinity" labels "github.com/openstack-k8s-operators/lib-common/modules/common/labels" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -141,6 +142,16 @@ func StatefulSet( }, } + // If possible two pods of the same service should not + // run on the same worker node. If this is not possible + // the get still created on the same worker node. + sts.Spec.Template.Spec.Affinity = affinity.DistributePods( + common.AppSelector, + []string{ + r.Name, + }, + corev1.LabelHostname, + ) if r.Spec.NodeSelector != nil { sts.Spec.Template.Spec.NodeSelector = *r.Spec.NodeSelector }