From ace5331d618bf237b5b84305fca48e08798ecc3f Mon Sep 17 00:00:00 2001 From: Cyril Scetbon Date: Thu, 12 Dec 2019 23:45:08 -0500 Subject: [PATCH] anti-affinity - Refactor PodAffinityTerm --- pkg/controller/cassandracluster/generator.go | 25 ++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pkg/controller/cassandracluster/generator.go b/pkg/controller/cassandracluster/generator.go index b7fec9983..45d941069 100644 --- a/pkg/controller/cassandracluster/generator.go +++ b/pkg/controller/cassandracluster/generator.go @@ -461,17 +461,17 @@ func createNodeAffinity(labels map[string]string) *v1.NodeAffinity { } func createPodAntiAffinity(hard bool, labels map[string]string) *v1.PodAntiAffinity { + podAffinityTerm := v1.PodAffinityTerm{ + TopologyKey: hostnameTopologyKey, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: labels, + }, + } + if hard { // Return a HARD anti-affinity (no same pods on one node) return &v1.PodAntiAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ - v1.PodAffinityTerm{ - TopologyKey: hostnameTopologyKey, - LabelSelector: &metav1.LabelSelector{ - MatchLabels: labels, - }, - }, - }, + RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{podAffinityTerm}, } } @@ -479,13 +479,8 @@ func createPodAntiAffinity(hard bool, labels map[string]string) *v1.PodAntiAffin return &v1.PodAntiAffinity{ PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{ v1.WeightedPodAffinityTerm{ - Weight: 100, - PodAffinityTerm: v1.PodAffinityTerm{ - TopologyKey: hostnameTopologyKey, - LabelSelector: &metav1.LabelSelector{ - MatchLabels: labels, - }, - }, + Weight: 100, + PodAffinityTerm: podAffinityTerm, }, }, }