Skip to content

Commit

Permalink
Add Affinity to Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiccini committed Nov 21, 2024
1 parent b225194 commit 6009cd3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/redis/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6009cd3

Please sign in to comment.