Skip to content

Commit 53cd15d

Browse files
authored
[Feature] Change NodeAffinity arch label (#798)
1 parent 497832d commit 53cd15d

File tree

8 files changed

+148
-5
lines changed

8 files changed

+148
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
4+
- Replace `beta.kubernetes.io/arch` Pod label with `kubernetes.io/arch` using Silent Rotation
45

56
## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
67
- Update UBI Image to 8.4

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ EXCLUDE_DIRS := tests vendor .gobuild deps tools
129129
SOURCES_QUERY := find ./ -type f -name '*.go' $(foreach EXCLUDE_DIR,$(EXCLUDE_DIRS), ! -path "./$(EXCLUDE_DIR)/*")
130130
SOURCES := $(shell $(SOURCES_QUERY))
131131
DASHBOARDSOURCES := $(shell find $(DASHBOARDDIR)/src -name '*.js') $(DASHBOARDDIR)/package.json
132+
LINT_EXCLUDES:=
133+
ifeq ($(RELEASE_MODE),enterprise)
134+
LINT_EXCLUDES+=.*\.community\.go$$
135+
else
136+
LINT_EXCLUDES+=.*\.enterprise\.go$$
137+
endif
138+
132139

133140
.DEFAULT_GOAL := all
134141
.PHONY: all
@@ -173,7 +180,9 @@ fmt-verify: license-verify
173180
linter:
174181
$(GOPATH)/bin/golangci-lint run --build-tags "$(RELEASE_MODE)" --no-config --issues-exit-code=1 --deadline=30m --exclude-use-default=false \
175182
--disable-all $(foreach EXCLUDE_DIR,$(EXCLUDE_DIRS),--skip-dirs $(EXCLUDE_DIR)) \
176-
$(foreach MODE,$(GOLANGCI_ENABLED),--enable $(MODE)) ./...
183+
$(foreach MODE,$(GOLANGCI_ENABLED),--enable $(MODE)) \
184+
$(foreach LINT_EXCLUDE,$(LINT_EXCLUDES),--exclude '$(LINT_EXCLUDE)') \
185+
./...
177186

178187
.PHONY: build
179188
build: docker manifests

pkg/deployment/pod/affinity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func AppendNodeSelector(a *core.NodeAffinity) {
5959
a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = append(a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, core.NodeSelectorTerm{
6060
MatchExpressions: []core.NodeSelectorRequirement{
6161
{
62-
Key: "beta.kubernetes.io/arch",
62+
Key: k8sutil.NodeArchAffinityLabel,
6363
Operator: "In",
6464
Values: []string{"amd64"},
6565
},

pkg/deployment/rotation/arangod.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package rotation
2222

2323
import (
2424
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
25+
"github.com/arangodb/kube-arangodb/pkg/util"
2526
core "k8s.io/api/core/v1"
2627
)
2728

@@ -35,3 +36,23 @@ func podCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodS
3536
return
3637
}
3738
}
39+
40+
func affinityCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodSpec) compareFunc {
41+
return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, e error) {
42+
if specC, err := util.SHA256FromJSON(spec.Affinity); err != nil {
43+
e = err
44+
return
45+
} else {
46+
if statusC, err := util.SHA256FromJSON(status.Affinity); err != nil {
47+
e = err
48+
return
49+
} else if specC != statusC {
50+
status.Affinity = spec.Affinity.DeepCopy()
51+
mode = mode.And(SilentRotation)
52+
return
53+
} else {
54+
return
55+
}
56+
}
57+
}
58+
}

pkg/deployment/rotation/arangod_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,113 @@ func Test_ArangoD_SchedulerName(t *testing.T) {
6767

6868
runTestCases(t)(testCases...)
6969
}
70+
71+
func Test_ArangoD_Affinity(t *testing.T) {
72+
testCases := []TestCase{
73+
{
74+
name: "Remove affinity",
75+
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
76+
pod.Spec.Affinity = &core.Affinity{
77+
NodeAffinity: &core.NodeAffinity{
78+
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
79+
NodeSelectorTerms: []core.NodeSelectorTerm{
80+
{
81+
MatchExpressions: []core.NodeSelectorRequirement{
82+
{
83+
Key: "beta.kubernetes.io/arch",
84+
Operator: core.NodeSelectorOpIn,
85+
Values: []string{
86+
"amd64",
87+
},
88+
},
89+
},
90+
},
91+
},
92+
},
93+
},
94+
}
95+
}),
96+
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
97+
}),
98+
99+
expectedMode: SilentRotation,
100+
},
101+
{
102+
name: "Add affinity",
103+
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
104+
}),
105+
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
106+
pod.Spec.Affinity = &core.Affinity{
107+
NodeAffinity: &core.NodeAffinity{
108+
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
109+
NodeSelectorTerms: []core.NodeSelectorTerm{
110+
{
111+
MatchExpressions: []core.NodeSelectorRequirement{
112+
{
113+
Key: "beta.kubernetes.io/arch",
114+
Operator: core.NodeSelectorOpIn,
115+
Values: []string{
116+
"amd64",
117+
},
118+
},
119+
},
120+
},
121+
},
122+
},
123+
},
124+
}
125+
}),
126+
127+
expectedMode: SilentRotation,
128+
},
129+
{
130+
name: "Change affinity",
131+
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
132+
pod.Spec.Affinity = &core.Affinity{
133+
NodeAffinity: &core.NodeAffinity{
134+
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
135+
NodeSelectorTerms: []core.NodeSelectorTerm{
136+
{
137+
MatchExpressions: []core.NodeSelectorRequirement{
138+
{
139+
Key: "beta.kubernetes.io/arch",
140+
Operator: core.NodeSelectorOpIn,
141+
Values: []string{
142+
"amd64",
143+
},
144+
},
145+
},
146+
},
147+
},
148+
},
149+
},
150+
}
151+
}),
152+
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
153+
pod.Spec.Affinity = &core.Affinity{
154+
NodeAffinity: &core.NodeAffinity{
155+
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
156+
NodeSelectorTerms: []core.NodeSelectorTerm{
157+
{
158+
MatchExpressions: []core.NodeSelectorRequirement{
159+
{
160+
Key: "kubernetes.io/arch",
161+
Operator: core.NodeSelectorOpIn,
162+
Values: []string{
163+
"amd64",
164+
},
165+
},
166+
},
167+
},
168+
},
169+
},
170+
},
171+
}
172+
}),
173+
174+
expectedMode: SilentRotation,
175+
},
176+
}
177+
178+
runTestCases(t)(testCases...)
179+
}

pkg/deployment/rotation/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func compare(log zerolog.Logger, deploymentSpec api.DeploymentSpec, member api.M
6767

6868
g := generator(deploymentSpec, group, &spec.PodSpec.Spec, &podStatus.Spec)
6969

70-
if m, p, err := compareFuncs(b, g(podCompare), g(containersCompare), g(initContainersCompare)); err != nil {
70+
if m, p, err := compareFuncs(b, g(podCompare), g(affinityCompare), g(containersCompare), g(initContainersCompare)); err != nil {
7171
log.Err(err).Msg("Error while getting pod diff")
7272
return SkippedRotation, nil, err
7373
} else {

pkg/util/k8sutil/affinity.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
)
2929

30+
const NodeArchAffinityLabel = "kubernetes.io/arch"
31+
3032
// CreateAffinity creates pod anti-affinity for the given role.
3133
// role contains the name of the role to configure any-affinity with.
3234
// affinityWithRole contains the role to configure affinity with.
@@ -38,7 +40,7 @@ func CreateAffinity(deploymentName, role string, required bool, affinityWithRole
3840
{
3941
MatchExpressions: []v1.NodeSelectorRequirement{
4042
{
41-
Key: "beta.kubernetes.io/arch",
43+
Key: NodeArchAffinityLabel,
4244
Operator: "In",
4345
Values: []string{"amd64"},
4446
},

pkg/util/k8sutil/affinity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestCreateAffinity(t *testing.T) {
3838
{
3939
MatchExpressions: []v1.NodeSelectorRequirement{
4040
{
41-
Key: "beta.kubernetes.io/arch",
41+
Key: NodeArchAffinityLabel,
4242
Operator: "In",
4343
Values: []string{"amd64"},
4444
},

0 commit comments

Comments
 (0)