Skip to content

Commit f1c0454

Browse files
authored
[Bugfix] Improve Profile Tolerations Merge (#1877)
1 parent e9bee97 commit f1c0454

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- (Feature) Promote RestartPolicy Always Feature
1414
- (Maintenance) Update Dependencies
1515
- (Feature) Backup Retry Until and BackupPolicy Until Propagation feature
16+
- (Bugfix) Improve Profile Tolerations Merge
1617

1718
## [1.2.47](https://github.com/arangodb/kube-arangodb/tree/1.2.47) (2025-03-28)
1819
- (Bugfix) Use Profile Annotations

pkg/apis/scheduler/v1beta1/pod/resources/scheduling.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -74,9 +74,9 @@ func (s *Scheduling) Apply(template *core.PodTemplateSpec) error {
7474
}
7575
}
7676

77-
template.Spec.Tolerations = tolerations.AddTolerationsIfNotFound(nil, s.Tolerations.DeepCopy()...)
77+
template.Spec.Tolerations = tolerations.AddTolerationsIfNotFound(template.Spec.Tolerations, s.Tolerations.DeepCopy()...)
7878

79-
template.Spec.SchedulerName = util.WithDefault(s.SchedulerName)
79+
template.Spec.SchedulerName = util.TypeOrDefault(s.SchedulerName, template.Spec.SchedulerName)
8080

8181
return nil
8282
}
@@ -134,7 +134,11 @@ func (s *Scheduling) With(other *Scheduling) *Scheduling {
134134
current.NodeSelector = new.NodeSelector
135135
} else if len(new.NodeSelector) > 0 {
136136
for k, v := range new.NodeSelector {
137-
current.NodeSelector[k] = v
137+
if v == "-" {
138+
delete(current.NodeSelector, k)
139+
} else {
140+
current.NodeSelector[k] = v
141+
}
138142
}
139143
}
140144

@@ -144,7 +148,7 @@ func (s *Scheduling) With(other *Scheduling) *Scheduling {
144148
}
145149

146150
// Tolerations
147-
current.Tolerations = tolerations.AddTolerationsIfNotFound(new.Tolerations, other.Tolerations...)
151+
current.Tolerations = tolerations.AddTolerationsIfNotFound(current.Tolerations, new.Tolerations...)
148152

149153
// Affinity
150154
current.Affinity = kresources.Merge(current.Affinity, new.Affinity)

pkg/apis/scheduler/v1beta1/pod/resources/scheduling_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -720,6 +720,31 @@ func Test_Scheduling_Tolerations(t *testing.T) {
720720
require.EqualValues(t, 5, *pod.Spec.Tolerations[0].TolerationSeconds)
721721
})
722722
})
723+
t.Run("Multi - Join", func(t *testing.T) {
724+
applyScheduling(t, nil, &Scheduling{
725+
Tolerations: Tolerations{
726+
{
727+
Key: "A",
728+
Operator: core.TolerationOpExists,
729+
},
730+
},
731+
}, &Scheduling{
732+
Tolerations: Tolerations{
733+
{
734+
Key: "B",
735+
Operator: core.TolerationOpExists,
736+
},
737+
},
738+
})(func(t *testing.T, pod *core.PodTemplateSpec) {
739+
require.Len(t, pod.Spec.Tolerations, 2)
740+
741+
require.EqualValues(t, core.TolerationOpExists, pod.Spec.Tolerations[0].Operator)
742+
require.EqualValues(t, "A", pod.Spec.Tolerations[0].Key)
743+
744+
require.EqualValues(t, core.TolerationOpExists, pod.Spec.Tolerations[1].Operator)
745+
require.EqualValues(t, "B", pod.Spec.Tolerations[1].Key)
746+
})
747+
})
723748
t.Run("Multi - Update", func(t *testing.T) {
724749
applyScheduling(t, nil, &Scheduling{
725750
Tolerations: Tolerations{
@@ -806,6 +831,23 @@ func Test_Scheduling_NodeSelector(t *testing.T) {
806831
require.Contains(t, pod.Spec.NodeSelector, "1")
807832
require.EqualValues(t, pod.Spec.NodeSelector["1"], "2")
808833

834+
require.Contains(t, pod.Spec.NodeSelector, "2")
835+
require.EqualValues(t, pod.Spec.NodeSelector["2"], "1")
836+
})
837+
})
838+
t.Run("Remove", func(t *testing.T) {
839+
applyScheduling(t, nil, &Scheduling{
840+
NodeSelector: map[string]string{
841+
"1": "1",
842+
},
843+
}, &Scheduling{
844+
NodeSelector: map[string]string{
845+
"2": "1",
846+
"1": "-",
847+
},
848+
})(func(t *testing.T, pod *core.PodTemplateSpec) {
849+
require.Len(t, pod.Spec.NodeSelector, 1)
850+
809851
require.Contains(t, pod.Spec.NodeSelector, "2")
810852
require.EqualValues(t, pod.Spec.NodeSelector["2"], "1")
811853
})

0 commit comments

Comments
 (0)