Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.14] OCPBUGS-29187: node spread anti-affinity for HA HCP #3541

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 29 additions & 8 deletions support/config/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,42 @@ func (c *DeploymentConfig) setMultizoneSpread(labels map[string]string) {
if labels == nil {
return
}
if c.Scheduling.Affinity == nil {
c.Scheduling.Affinity = &corev1.Affinity{}
}
if c.Scheduling.Affinity.PodAntiAffinity == nil {
c.Scheduling.Affinity.PodAntiAffinity = &corev1.PodAntiAffinity{}
}
c.Scheduling.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution = append(c.Scheduling.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution,
corev1.PodAffinityTerm{
TopologyKey: corev1.LabelTopologyZone,
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels,
},
},
)
}

// setNodeSpread sets PodAntiAffinity with corev1.LabelHostname as the topology key for a given set of labels.
// This is useful to e.g ensure pods are spread across nodes.
func (c *DeploymentConfig) setNodeSpread(labels map[string]string) {
if labels == nil {
return
}
if c.Scheduling.Affinity == nil {
c.Scheduling.Affinity = &corev1.Affinity{}
}
if c.Scheduling.Affinity.PodAntiAffinity == nil {
c.Scheduling.Affinity.PodAntiAffinity = &corev1.PodAntiAffinity{}
}
c.Scheduling.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution =
[]corev1.PodAffinityTerm{
{
TopologyKey: corev1.LabelTopologyZone,
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels,
},
c.Scheduling.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution = append(c.Scheduling.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution,
corev1.PodAffinityTerm{
TopologyKey: corev1.LabelHostname,
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels,
},
}
},
)
}

// setColocation sets labels and PodAffinity rules for this deployment so that pods
Expand Down Expand Up @@ -314,6 +334,7 @@ func (c *DeploymentConfig) setLocation(hcp *hyperv1.HostedControlPlane, multiZon
// TODO (alberto): pass labels with deployment hash and set this unconditionally so we don't skew setup.
if c.Replicas > 1 {
c.setMultizoneSpread(multiZoneSpreadLabels)
c.setNodeSpread(multiZoneSpreadLabels)
}
}

Expand Down
6 changes: 6 additions & 0 deletions support/config/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ func TestSetLocation(t *testing.T) {
MatchLabels: labels,
},
},
{
TopologyKey: corev1.LabelHostname,
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels,
},
},
},
}
g.Expect(expected.Scheduling.Affinity.PodAntiAffinity).To(BeEquivalentTo(cfg.Scheduling.Affinity.PodAntiAffinity))
Expand Down