Skip to content

Commit

Permalink
set pod anti-affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolik committed Aug 1, 2024
1 parent 896ec78 commit 3a59b85
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions internal/controller/valkey_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (r *ValkeyReconciler) upsertServiceAccount(ctx context.Context, valkey *hyp

func getMasterNodes(valkey *hyperv1.Valkey) string {
var nodes []string
for i := 0; i < int(valkey.Spec.MasterNodes); i++ {
for i := 0; i < int(valkey.Spec.MasterNodes)*(int(valkey.Spec.Replicas)+1); i++ {
nodes = append(nodes, valkey.Name+"-"+fmt.Sprint(i)+"."+valkey.Name+"-headless")
}
return strings.Join(nodes, " ")
Expand Down Expand Up @@ -433,6 +433,21 @@ func (r *ValkeyReconciler) upsertStatefulSet(ctx context.Context, valkey *hyperv
Sysctls: []corev1.Sysctl{},
},
AutomountServiceAccountToken: func(b bool) *bool { return &b }(false),
Affinity: &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
{
Weight: 1,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels(valkey),
},
TopologyKey: "kubernetes.io/hostname",
},
},
},
},
},
Containers: []corev1.Container{
{
Image: valkey.Spec.Image,
Expand Down Expand Up @@ -460,7 +475,7 @@ func (r *ValkeyReconciler) upsertStatefulSet(ctx context.Context, valkey *hyperv
"-c",
},
Args: []string{
`# Backwards compatibility change
fmt.Sprintf(`# Backwards compatibility change
if ! [[ -f /opt/bitnami/valkey/etc/valkey.conf ]]; then
echo COPYING FILE
cp /opt/bitnami/valkey/etc/valkey-default.conf /opt/bitnami/valkey/etc/valkey.conf
Expand All @@ -469,9 +484,9 @@ pod_index=($(echo "$POD_NAME" | tr "-" "\n"))
pod_index="${pod_index[-1]}"
if [[ "$pod_index" == "0" ]]; then
export VALKEY_CLUSTER_CREATOR="yes"
export VALKEY_CLUSTER_REPLICAS="0"
export VALKEY_CLUSTER_REPLICAS="%d"
fi
/opt/bitnami/scripts/valkey-cluster/entrypoint.sh /opt/bitnami/scripts/valkey-cluster/run.sh`,
/opt/bitnami/scripts/valkey-cluster/entrypoint.sh /opt/bitnami/scripts/valkey-cluster/run.sh`, valkey.Spec.Replicas),
},
Env: []corev1.EnvVar{
{
Expand Down

0 comments on commit 3a59b85

Please sign in to comment.