Skip to content

Commit

Permalink
console plugin/proxy: Change AntiAffinity rule to 'Preferred' instead…
Browse files Browse the repository at this point in the history
… of 'Required' (#3051)

Due to the (default setting of) rollingUpdate of the 'kubevirt-console-plugin' and 'kubevirt-apiserver-proxy' Deployments, when there is a change, a 3rd pod is being scheduled as a replacement.
If there is a nodeSelector placement config alongside the anti-affinity rules, the replacement pod won't get scheduled if there are less than 3 nodes labeled with the node selector label.
We'll use 'PreferredDuringSchedulingIgnoredDuringExecution' instead of 'RequiredDuringSchedulingIgnoredDuringExecution' to soften the affinity rule so no pod will get stuck at Pending.

Signed-off-by: Oren Cohen <ocohen@redhat.com>
  • Loading branch information
orenc1 authored Aug 14, 2024
1 parent 8bec93e commit d6d5036
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
19 changes: 11 additions & 8 deletions controllers/operands/kubevirtConsolePlugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,21 @@ func getPodAntiAffinity(componentLabel string, infrastructureHighlyAvailable boo
if infrastructureHighlyAvailable {
return &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: hcoutil.AppLabelComponent,
Operator: metav1.LabelSelectorOpIn,
Values: []string{componentLabel},
Weight: 90,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: hcoutil.AppLabelComponent,
Operator: metav1.LabelSelectorOpIn,
Values: []string{componentLabel},
},
},
},
TopologyKey: corev1.LabelHostname,
},
TopologyKey: corev1.LabelHostname,
},
},
},
Expand Down
19 changes: 11 additions & 8 deletions controllers/operands/kubevirtConsolePlugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,18 +889,21 @@ var _ = Describe("Kubevirt Console Plugin", func() {
func expectedPodAntiAffinity(appComponent hcoutil.AppComponent) *v1.Affinity {
return &v1.Affinity{
PodAntiAffinity: &v1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: hcoutil.AppLabelComponent,
Operator: metav1.LabelSelectorOpIn,
Values: []string{string(appComponent)},
Weight: 90,
PodAffinityTerm: v1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: hcoutil.AppLabelComponent,
Operator: metav1.LabelSelectorOpIn,
Values: []string{string(appComponent)},
},
},
},
TopologyKey: v1.LabelHostname,
},
TopologyKey: v1.LabelHostname,
},
},
},
Expand Down

0 comments on commit d6d5036

Please sign in to comment.