Skip to content

Commit

Permalink
Merge pull request k0sproject#388 from makhov/k0smotron-pod-affinity
Browse files Browse the repository at this point in the history
K0smotron pod affinities
  • Loading branch information
makhov authored Jan 2, 2024
2 parents 80f59e8 + ffbb961 commit 22d0b8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
22 changes: 22 additions & 0 deletions internal/controller/k0smotron.io/k0smotroncluster_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ func (r *ClusterReconciler) generateStatefulSet(kmc *km.Cluster) (apps.StatefulS
Labels: labels,
},
Spec: v1.PodSpec{
Affinity: &v1.Affinity{PodAntiAffinity: &v1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{
{
Weight: 100,
PodAffinityTerm: v1.PodAffinityTerm{
TopologyKey: "topology.kubernetes.io/zone",
LabelSelector: &metav1.LabelSelector{
MatchLabels: defaultClusterLabels(kmc),
},
},
},
{
Weight: 50,
PodAffinityTerm: v1.PodAffinityTerm{
TopologyKey: "kubernetes.io/hostname",
LabelSelector: &metav1.LabelSelector{
MatchLabels: defaultClusterLabels(kmc),
},
},
},
},
}},
Volumes: []v1.Volume{{
Name: kmc.GetEntrypointConfigMapName(),
VolumeSource: v1.VolumeSource{
Expand Down
9 changes: 8 additions & 1 deletion internal/controller/k0smotron.io/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ package k0smotronio

import km "github.com/k0sproject/k0smotron/api/k0smotron.io/v1beta1"

func defaultClusterLabels(kmc *km.Cluster) map[string]string {
return map[string]string{
"app": "k0smotron",
"cluster": kmc.Name,
}
}

func labelsForCluster(kmc *km.Cluster) map[string]string {
labels := map[string]string{"app": "k0smotron", "cluster": kmc.Name}
labels := defaultClusterLabels(kmc)
for k, v := range kmc.Labels {
labels[k] = v
}
Expand Down

0 comments on commit 22d0b8f

Please sign in to comment.