Skip to content

Commit b6ebb23

Browse files
authored
[Bugfix] Fix node affinity (#609)
1 parent 137f768 commit b6ebb23

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Add Labels and Annotations to ServiceMonitor
55
- Allow to expose Exporter in HTTP with secured Deployments
66
- Change rotation by annotation order (coordinator before dbserver)
7+
- Fix NodeAffinity propagation
78

89
## [1.0.4](https://github.com/arangodb/kube-arangodb/tree/1.0.4) (2020-07-28)
910
- Add Encryption Key rotation feature for ArangoDB EE 3.7+

pkg/deployment/deployment_affinity_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,15 @@ func TestEnsurePod_ArangoDB_NodeAffinity(t *testing.T) {
673673
Subdomain: testDeploymentName + "-int",
674674
Affinity: modifyAffinity(testDeploymentName, api.ServerGroupDBServersString,
675675
false, "", func(a *core.Affinity) {
676-
n := core.NodeSelectorTerm{
677-
MatchFields: []core.NodeSelectorRequirement{
678-
{
679-
Key: "key",
680-
},
676+
f := a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0]
677+
678+
f.MatchFields = []core.NodeSelectorRequirement{
679+
{
680+
Key: "key",
681681
},
682682
}
683-
a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = append(a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, n)
683+
684+
a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0] = f
684685
}),
685686
},
686687
},

pkg/deployment/pod/affinity.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,28 @@ func MergeNodeAffinity(a, b *core.NodeAffinity) {
124124
a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution, rule)
125125
}
126126

127-
if b.RequiredDuringSchedulingIgnoredDuringExecution != nil {
128-
if a.RequiredDuringSchedulingIgnoredDuringExecution == nil {
129-
a.RequiredDuringSchedulingIgnoredDuringExecution = b.RequiredDuringSchedulingIgnoredDuringExecution.DeepCopy()
130-
} else {
131-
for _, rule := range b.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
132-
a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = append(a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, rule)
127+
var newSelectorTerms []core.NodeSelectorTerm
128+
129+
if b.RequiredDuringSchedulingIgnoredDuringExecution == nil || len(b.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms) == 0 {
130+
newSelectorTerms = a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms
131+
} else if a.RequiredDuringSchedulingIgnoredDuringExecution == nil || len(a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms) == 0 {
132+
newSelectorTerms = b.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms
133+
} else {
134+
for _, aTerms := range a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
135+
for _, bTerms := range b.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
136+
term := aTerms.DeepCopy()
137+
if len(bTerms.MatchExpressions) != 0 {
138+
term.MatchExpressions = append(term.MatchExpressions, bTerms.MatchExpressions...)
139+
}
140+
if len(bTerms.MatchFields) != 0 {
141+
term.MatchFields = append(term.MatchFields, bTerms.MatchFields...)
142+
}
143+
newSelectorTerms = append(newSelectorTerms, *term)
133144
}
134145
}
135146
}
147+
148+
a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = newSelectorTerms
136149
}
137150

138151
func ReturnPodAffinityOrNil(a core.PodAffinity) *core.PodAffinity {

0 commit comments

Comments
 (0)