From 0f5a7d2db5f9e0f04e52e648fe3c6e9d04ebff72 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Wed, 4 Oct 2023 18:19:05 -0500 Subject: [PATCH] feat: Attempt to place job pod on same node as database --- internal/util/cmd_setup.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/util/cmd_setup.go b/internal/util/cmd_setup.go index fae38273..ec81fc39 100644 --- a/internal/util/cmd_setup.go +++ b/internal/util/cmd_setup.go @@ -207,6 +207,21 @@ func createJob(cmd *cobra.Command, conf *config.Global, actionName string) error Spec: corev1.PodSpec{ RestartPolicy: corev1.RestartPolicyOnFailure, TerminationGracePeriodSeconds: ptr.To(int64(0)), + Affinity: &corev1.Affinity{ + PodAffinity: &corev1.PodAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ + { + Weight: 100, + PodAffinityTerm: corev1.PodAffinityTerm{ + TopologyKey: "kubernetes.io/hostname", + LabelSelector: &metav1.LabelSelector{ + MatchLabels: conf.Pod.ObjectMeta.Labels, + }, + }, + }, + }, + }, + }, Containers: []corev1.Container{ { Name: "kubedb",