From 4714ab47a51bf3894528f084a9849c7d60e88944 Mon Sep 17 00:00:00 2001 From: yaroslavborbat Date: Mon, 2 Dec 2024 20:53:53 +0300 Subject: [PATCH 1/2] fix Signed-off-by: yaroslavborbat --- .../pkg/controller/kvbuilder/kvvm.go | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm.go b/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm.go index 9f2482e77..e3a77b909 100644 --- a/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm.go +++ b/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm.go @@ -158,18 +158,8 @@ func (b *KVVM) SetNodeSelector(vmNodeSelector, classNodeSelector map[string]stri } func (b *KVVM) SetTolerations(vmTolerations, classTolerations []corev1.Toleration) { - tolerationsMap := make(map[string]corev1.Toleration) - for _, toleration := range classTolerations { - tolerationsMap[toleration.Key] = toleration - } - for _, toleration := range vmTolerations { - tolerationsMap[toleration.Key] = toleration - } - resultTolerations := make([]corev1.Toleration, 0, len(tolerationsMap)) - for _, toleration := range tolerationsMap { - resultTolerations = append(resultTolerations, toleration) - } - b.Resource.Spec.Template.Spec.Tolerations = resultTolerations + b.Resource.Spec.Template.Spec.Tolerations = append(b.Resource.Spec.Template.Spec.Tolerations, classTolerations...) + b.Resource.Spec.Template.Spec.Tolerations = append(b.Resource.Spec.Template.Spec.Tolerations, vmTolerations...) } func (b *KVVM) SetPriorityClassName(priorityClassName string) { @@ -193,11 +183,16 @@ func (b *KVVM) SetAffinity(vmAffinity *corev1.Affinity, classMatchExpressions [] if vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms == nil { vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = []corev1.NodeSelectorTerm{} } - - vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = append( - vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, - corev1.NodeSelectorTerm{MatchExpressions: classMatchExpressions}, - ) + if len(vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms) == 0 { + vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = append( + vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, + corev1.NodeSelectorTerm{MatchExpressions: classMatchExpressions}) + } else { + for i := range vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms { + vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[i].MatchExpressions = append( + vmAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[i].MatchExpressions, classMatchExpressions...) + } + } b.Resource.Spec.Template.Spec.Affinity = vmAffinity } From b75fbce403cc5f6497e7161e8ded23cbdcbb0062 Mon Sep 17 00:00:00 2001 From: yaroslavborbat Date: Tue, 3 Dec 2024 10:08:13 +0300 Subject: [PATCH 2/2] fix Signed-off-by: yaroslavborbat --- .../pkg/controller/kvbuilder/kvvm_test.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_test.go b/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_test.go index 3bd3c5049..4b0cd7ddd 100644 --- a/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_test.go +++ b/images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_test.go @@ -81,16 +81,11 @@ func TestSetAffinity(t *testing.T) { RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{ NodeSelectorTerms: []corev1.NodeSelectorTerm{ { - MatchExpressions: getDefaultMatchExpressions(), - }, - { - MatchExpressions: []corev1.NodeSelectorRequirement{ - { - Key: "node-role.kubernetes.io/master", - Operator: corev1.NodeSelectorOpIn, - Values: []string{""}, - }, - }, + MatchExpressions: append(getDefaultMatchExpressions(), corev1.NodeSelectorRequirement{ + Key: "node-role.kubernetes.io/master", + Operator: corev1.NodeSelectorOpIn, + Values: []string{""}, + }), }, }, },