Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Refactor PodAffinityTerm #155

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions pkg/controller/cassandracluster/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,31 +461,26 @@ 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},
}
}

// Return a SOFT anti-affinity
return &v1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{
v1.WeightedPodAffinityTerm{
Weight: 100,
PodAffinityTerm: v1.PodAffinityTerm{
TopologyKey: hostnameTopologyKey,
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels,
},
},
Weight: 100,
PodAffinityTerm: podAffinityTerm,
},
},
}
Expand Down