Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Affinity to Redis #299

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading