1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-15 17:51:03 +00:00
kube-arangodb/pkg/deployment/rotation/arangod_test.go

499 lines
12 KiB
Go
Raw Normal View History

//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package rotation
import (
"testing"
core "k8s.io/api/core/v1"
2021-11-15 20:48:35 +00:00
"github.com/arangodb/kube-arangodb/pkg/deployment/topology"
"github.com/arangodb/kube-arangodb/pkg/util"
2023-11-13 19:18:58 +00:00
compare2 "github.com/arangodb/kube-arangodb/pkg/util/compare"
)
func Test_ArangoD_SchedulerName(t *testing.T) {
testCases := []TestCase{
{
name: "Change SchedulerName from Empty",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.SchedulerName = ""
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.SchedulerName = "new"
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
{
name: "Change SchedulerName into Empty",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.SchedulerName = "new"
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.SchedulerName = ""
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
{
name: "SchedulerName equals",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.SchedulerName = ""
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.SchedulerName = ""
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SkippedRotation,
2022-08-18 07:13:03 +00:00
},
},
}
runTestCases(t)(testCases...)
}
func Test_ArangoD_TerminationGracePeriodSeconds(t *testing.T) {
testCases := []TestCase{
{
name: "Add",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.TerminationGracePeriodSeconds = nil
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.TerminationGracePeriodSeconds = util.NewType[int64](30)
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
{
name: "Remove",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.TerminationGracePeriodSeconds = util.NewType[int64](30)
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.TerminationGracePeriodSeconds = nil
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
{
name: "Update",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.TerminationGracePeriodSeconds = util.NewType[int64](33)
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Spec.TerminationGracePeriodSeconds = util.NewType[int64](30)
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
}
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) {
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
{
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",
},
},
},
},
},
},
},
}
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
{
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",
},
},
},
},
},
},
},
}
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
{
name: "Change affinity archs",
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{
"arm64",
},
},
},
},
},
},
},
}
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
{
name: "Change affinity archs - swap arch order",
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", "arm64",
},
},
},
},
},
},
},
}
}),
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{
"arm64", "amd64",
},
},
},
},
},
},
},
}
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
},
}
runTestCases(t)(testCases...)
}
2021-11-15 20:48:35 +00:00
func Test_ArangoD_Labels(t *testing.T) {
testCases := []TestCase{
{
name: "Add label",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Labels = map[string]string{}
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Labels = map[string]string{
"A": "B",
}
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SkippedRotation,
2022-08-18 07:13:03 +00:00
},
2021-11-15 20:48:35 +00:00
},
{
name: "Remove label",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Labels = map[string]string{
"A": "B",
}
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Labels = map[string]string{}
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SkippedRotation,
2022-08-18 07:13:03 +00:00
},
2021-11-15 20:48:35 +00:00
},
{
name: "Change label",
spec: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Labels = map[string]string{
"A": "A",
}
}),
status: buildPodSpec(func(pod *core.PodTemplateSpec) {
pod.Labels = map[string]string{
"A": "B",
}
}),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SkippedRotation,
2022-08-18 07:13:03 +00:00
},
2021-11-15 20:48:35 +00:00
},
}
runTestCases(t)(testCases...)
}
func Test_ArangoD_Envs_Zone(t *testing.T) {
testCases := []TestCase{
{
name: "Add Zone env",
spec: buildPodSpec(addContainer("server", func(c *core.Container) {
c.Env = []core.EnvVar{}
})),
status: buildPodSpec(addContainer("server", func(c *core.Container) {
c.Env = []core.EnvVar{
{
Name: topology.ArangoDBZone,
Value: "A",
},
}
})),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
2021-11-15 20:48:35 +00:00
},
{
name: "Remove Zone env",
spec: buildPodSpec(addContainer("server", func(c *core.Container) {
c.Env = []core.EnvVar{
{
Name: topology.ArangoDBZone,
Value: "A",
},
}
})),
status: buildPodSpec(addContainer("server", func(c *core.Container) {
c.Env = []core.EnvVar{}
})),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
2021-11-15 20:48:35 +00:00
},
{
name: "Update Zone env",
spec: buildPodSpec(addContainer("server", func(c *core.Container) {
c.Env = []core.EnvVar{
{
Name: topology.ArangoDBZone,
Value: "A",
},
}
})),
status: buildPodSpec(addContainer("server", func(c *core.Container) {
c.Env = []core.EnvVar{
{
Name: topology.ArangoDBZone,
Value: "B",
},
}
})),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.SilentRotation,
2022-08-18 07:13:03 +00:00
},
2021-11-15 20:48:35 +00:00
},
{
name: "Update other env",
spec: buildPodSpec(addContainer("server", func(c *core.Container) {
c.Env = []core.EnvVar{
{
Name: "Q",
Value: "A",
},
{
Name: topology.ArangoDBZone,
Value: "A",
},
}
})),
status: buildPodSpec(addContainer("server", func(c *core.Container) {
c.Env = []core.EnvVar{
{
Name: topology.ArangoDBZone,
Value: "A",
},
}
})),
2022-08-18 07:13:03 +00:00
TestCaseOverride: TestCaseOverride{
2023-11-13 19:18:58 +00:00
expectedMode: compare2.GracefulRotation,
2022-08-18 07:13:03 +00:00
},
2021-11-15 20:48:35 +00:00
},
}
runTestCases(t)(testCases...)
}