Skip to content

Commit 1b3366e

Browse files
authored
Support affinity in connection pooler deployments (zalando#1464)
1 parent f0815fc commit 1b3366e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/cluster/connection_pooler.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) (
285285
},
286286
}
287287

288+
tolerationsSpec := tolerations(&spec.Tolerations, c.OpConfig.PodToleration)
289+
288290
podTemplate := &v1.PodTemplateSpec{
289291
ObjectMeta: metav1.ObjectMeta{
290292
Labels: c.connectionPoolerLabels(role, true).MatchLabels,
@@ -294,12 +296,18 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) (
294296
Spec: v1.PodSpec{
295297
TerminationGracePeriodSeconds: &gracePeriod,
296298
Containers: []v1.Container{poolerContainer},
297-
// TODO: add tolerations to scheduler pooler on the same node
298-
// as database
299-
//Tolerations: *tolerationsSpec,
299+
Tolerations: tolerationsSpec,
300300
},
301301
}
302302

303+
nodeAffinity := nodeAffinity(c.OpConfig.NodeReadinessLabel, spec.NodeAffinity)
304+
if c.OpConfig.EnablePodAntiAffinity {
305+
labelsSet := labels.Set(c.connectionPoolerLabels(role, false).MatchLabels)
306+
podTemplate.Spec.Affinity = generatePodAffinity(labelsSet, c.OpConfig.PodAntiAffinityTopologyKey, nodeAffinity)
307+
} else if nodeAffinity != nil {
308+
podTemplate.Spec.Affinity = nodeAffinity
309+
}
310+
303311
return podTemplate, nil
304312
}
305313

0 commit comments

Comments
 (0)