add basic affinity setup

This commit is contained in:
Sergey Dudoladov 2019-04-05 12:08:52 +02:00
parent 9ad38d5520
commit daf4e3acc0
1 changed files with 20 additions and 0 deletions

View File

@ -1279,6 +1279,25 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1beta1.CronJob, error) {
[]v1.VolumeMount{},
)
labels := map[string]string{
"version": c.Name,
"spilo-role": "replica",
}
podAffinityTerm := v1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels,
},
TopologyKey: "kubernetes.io/hostname",
}
podAffinity := v1.Affinity{
PodAffinity: &v1.PodAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{{
Weight: 1,
PodAffinityTerm: podAffinityTerm,
},
},
}}
if podTemplate, err = generatePodTemplate(
c.Namespace,
c.labelsSet(true),
@ -1300,6 +1319,7 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1beta1.CronJob, error) {
// pods of k8s jobs support only "OnFailure" or "Never"
// but the default is "Always"
podTemplate.Spec.RestartPolicy = "OnFailure"
podTemplate.Spec.Affinity = &podAffinity
jobSpec := batchv1.JobSpec{Template: *podTemplate}