mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] Change NodeAffinity arch label (#798)
This commit is contained in:
parent
497832d1c3
commit
53cd15d318
8 changed files with 148 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
# Change Log
|
||||
|
||||
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
||||
- Replace `beta.kubernetes.io/arch` Pod label with `kubernetes.io/arch` using Silent Rotation
|
||||
|
||||
## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
|
||||
- Update UBI Image to 8.4
|
||||
|
|
11
Makefile
11
Makefile
|
@ -129,6 +129,13 @@ EXCLUDE_DIRS := tests vendor .gobuild deps tools
|
|||
SOURCES_QUERY := find ./ -type f -name '*.go' $(foreach EXCLUDE_DIR,$(EXCLUDE_DIRS), ! -path "./$(EXCLUDE_DIR)/*")
|
||||
SOURCES := $(shell $(SOURCES_QUERY))
|
||||
DASHBOARDSOURCES := $(shell find $(DASHBOARDDIR)/src -name '*.js') $(DASHBOARDDIR)/package.json
|
||||
LINT_EXCLUDES:=
|
||||
ifeq ($(RELEASE_MODE),enterprise)
|
||||
LINT_EXCLUDES+=.*\.community\.go$$
|
||||
else
|
||||
LINT_EXCLUDES+=.*\.enterprise\.go$$
|
||||
endif
|
||||
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
.PHONY: all
|
||||
|
@ -173,7 +180,9 @@ fmt-verify: license-verify
|
|||
linter:
|
||||
$(GOPATH)/bin/golangci-lint run --build-tags "$(RELEASE_MODE)" --no-config --issues-exit-code=1 --deadline=30m --exclude-use-default=false \
|
||||
--disable-all $(foreach EXCLUDE_DIR,$(EXCLUDE_DIRS),--skip-dirs $(EXCLUDE_DIR)) \
|
||||
$(foreach MODE,$(GOLANGCI_ENABLED),--enable $(MODE)) ./...
|
||||
$(foreach MODE,$(GOLANGCI_ENABLED),--enable $(MODE)) \
|
||||
$(foreach LINT_EXCLUDE,$(LINT_EXCLUDES),--exclude '$(LINT_EXCLUDE)') \
|
||||
./...
|
||||
|
||||
.PHONY: build
|
||||
build: docker manifests
|
||||
|
|
|
@ -59,7 +59,7 @@ func AppendNodeSelector(a *core.NodeAffinity) {
|
|||
a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = append(a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, core.NodeSelectorTerm{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "beta.kubernetes.io/arch",
|
||||
Key: k8sutil.NodeArchAffinityLabel,
|
||||
Operator: "In",
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
|
|
|
@ -22,6 +22,7 @@ package rotation
|
|||
|
||||
import (
|
||||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util"
|
||||
core "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
|
@ -35,3 +36,23 @@ func podCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodS
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func affinityCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodSpec) compareFunc {
|
||||
return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, e error) {
|
||||
if specC, err := util.SHA256FromJSON(spec.Affinity); err != nil {
|
||||
e = err
|
||||
return
|
||||
} else {
|
||||
if statusC, err := util.SHA256FromJSON(status.Affinity); err != nil {
|
||||
e = err
|
||||
return
|
||||
} else if specC != statusC {
|
||||
status.Affinity = spec.Affinity.DeepCopy()
|
||||
mode = mode.And(SilentRotation)
|
||||
return
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,3 +67,113 @@ func Test_ArangoD_SchedulerName(t *testing.T) {
|
|||
|
||||
runTestCases(t)(testCases...)
|
||||
}
|
||||
|
||||
func Test_ArangoD_Affinity(t *testing.T) {
|
||||
testCases := []TestCase{
|
||||
{
|
||||
name: "Remove affinity",
|
||||
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
|
||||
pod.Spec.Affinity = &core.Affinity{
|
||||
NodeAffinity: &core.NodeAffinity{
|
||||
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{
|
||||
{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "beta.kubernetes.io/arch",
|
||||
Operator: core.NodeSelectorOpIn,
|
||||
Values: []string{
|
||||
"amd64",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
|
||||
}),
|
||||
|
||||
expectedMode: SilentRotation,
|
||||
},
|
||||
{
|
||||
name: "Add affinity",
|
||||
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
|
||||
}),
|
||||
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
|
||||
pod.Spec.Affinity = &core.Affinity{
|
||||
NodeAffinity: &core.NodeAffinity{
|
||||
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{
|
||||
{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "beta.kubernetes.io/arch",
|
||||
Operator: core.NodeSelectorOpIn,
|
||||
Values: []string{
|
||||
"amd64",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
|
||||
expectedMode: SilentRotation,
|
||||
},
|
||||
{
|
||||
name: "Change affinity",
|
||||
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
|
||||
pod.Spec.Affinity = &core.Affinity{
|
||||
NodeAffinity: &core.NodeAffinity{
|
||||
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{
|
||||
{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "beta.kubernetes.io/arch",
|
||||
Operator: core.NodeSelectorOpIn,
|
||||
Values: []string{
|
||||
"amd64",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
|
||||
pod.Spec.Affinity = &core.Affinity{
|
||||
NodeAffinity: &core.NodeAffinity{
|
||||
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{
|
||||
{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "kubernetes.io/arch",
|
||||
Operator: core.NodeSelectorOpIn,
|
||||
Values: []string{
|
||||
"amd64",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
|
||||
expectedMode: SilentRotation,
|
||||
},
|
||||
}
|
||||
|
||||
runTestCases(t)(testCases...)
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func compare(log zerolog.Logger, deploymentSpec api.DeploymentSpec, member api.M
|
|||
|
||||
g := generator(deploymentSpec, group, &spec.PodSpec.Spec, &podStatus.Spec)
|
||||
|
||||
if m, p, err := compareFuncs(b, g(podCompare), g(containersCompare), g(initContainersCompare)); err != nil {
|
||||
if m, p, err := compareFuncs(b, g(podCompare), g(affinityCompare), g(containersCompare), g(initContainersCompare)); err != nil {
|
||||
log.Err(err).Msg("Error while getting pod diff")
|
||||
return SkippedRotation, nil, err
|
||||
} else {
|
||||
|
|
|
@ -27,6 +27,8 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const NodeArchAffinityLabel = "kubernetes.io/arch"
|
||||
|
||||
// CreateAffinity creates pod anti-affinity for the given role.
|
||||
// role contains the name of the role to configure any-affinity with.
|
||||
// affinityWithRole contains the role to configure affinity with.
|
||||
|
@ -38,7 +40,7 @@ func CreateAffinity(deploymentName, role string, required bool, affinityWithRole
|
|||
{
|
||||
MatchExpressions: []v1.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "beta.kubernetes.io/arch",
|
||||
Key: NodeArchAffinityLabel,
|
||||
Operator: "In",
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
|
|
|
@ -38,7 +38,7 @@ func TestCreateAffinity(t *testing.T) {
|
|||
{
|
||||
MatchExpressions: []v1.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "beta.kubernetes.io/arch",
|
||||
Key: NodeArchAffinityLabel,
|
||||
Operator: "In",
|
||||
Values: []string{"amd64"},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue