From 39420b6832185777a7f034c7e622a290a9b8bea3 Mon Sep 17 00:00:00 2001 From: ajanikow <12255597+ajanikow@users.noreply.github.com> Date: Wed, 22 Sep 2021 11:57:57 +0000 Subject: [PATCH] [Feature] SchedulerName Pod Customization --- CHANGELOG.md | 1 + pkg/apis/deployment/v1/server_group_spec.go | 2 + .../deployment/v1/zz_generated.deepcopy.go | 5 ++ pkg/apis/deployment/v2alpha1/plan.go | 4 +- .../deployment/v2alpha1/server_group_spec.go | 2 + .../v2alpha1/zz_generated.deepcopy.go | 5 ++ .../resources/pod_creator_arangod.go | 4 ++ pkg/deployment/resources/pod_creator_sync.go | 4 ++ pkg/deployment/rotation/arangod.go | 37 ++++++++++ pkg/deployment/rotation/arangod_test.go | 69 +++++++++++++++++++ pkg/deployment/rotation/compare.go | 2 +- 11 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 pkg/deployment/rotation/arangod.go create mode 100644 pkg/deployment/rotation/arangod_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cca89cf2..39ece72da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Allow runtime update of Sidecar images - Allow Agent recreation with preserved IDs - The internal metrics exporter can not be disabled +- Allow to customize SchedulerName inside Member Pod ## [1.2.2](https://github.com/arangodb/kube-arangodb/tree/1.2.2) (2021-09-09) - Update 'github.com/arangodb/arangosync-client' dependency to v0.7.0 diff --git a/pkg/apis/deployment/v1/server_group_spec.go b/pkg/apis/deployment/v1/server_group_spec.go index 3097a5221..a3cb18ea7 100644 --- a/pkg/apis/deployment/v1/server_group_spec.go +++ b/pkg/apis/deployment/v1/server_group_spec.go @@ -81,6 +81,8 @@ type ServerGroupSpec struct { Args []string `json:"args,omitempty"` // Entrypoint overrides container executable Entrypoint *string `json:"entrypoint,omitempty"` + // SchedulerName define scheduler name used for group + SchedulerName *string `json:"schedulerName,omitempty"` // StorageClassName specifies the classname for storage of the servers. StorageClassName *string `json:"storageClassName,omitempty"` // Resources holds resource requests & limits diff --git a/pkg/apis/deployment/v1/zz_generated.deepcopy.go b/pkg/apis/deployment/v1/zz_generated.deepcopy.go index c209125e2..5b855f46a 100644 --- a/pkg/apis/deployment/v1/zz_generated.deepcopy.go +++ b/pkg/apis/deployment/v1/zz_generated.deepcopy.go @@ -1505,6 +1505,11 @@ func (in *ServerGroupSpec) DeepCopyInto(out *ServerGroupSpec) { *out = new(string) **out = **in } + if in.SchedulerName != nil { + in, out := &in.SchedulerName, &out.SchedulerName + *out = new(string) + **out = **in + } if in.StorageClassName != nil { in, out := &in.StorageClassName, &out.StorageClassName *out = new(string) diff --git a/pkg/apis/deployment/v2alpha1/plan.go b/pkg/apis/deployment/v2alpha1/plan.go index 79affd7d1..4d49d0b8b 100644 --- a/pkg/apis/deployment/v2alpha1/plan.go +++ b/pkg/apis/deployment/v2alpha1/plan.go @@ -49,7 +49,7 @@ func (a ActionType) String() string { // Priority returns plan priority func (a ActionType) Priority() ActionPriority { switch a { - case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate, ActionTypeSetMemberCondition, ActionTypeBootstrapSetAgencyInfo: + case ActionTypeMemberPhaseUpdate, ActionTypeMemberRIDUpdate, ActionTypeSetMemberCondition: return ActionPriorityHigh default: return ActionPriorityNormal @@ -165,8 +165,6 @@ const ( ActionTypeArangoMemberUpdatePodSpec ActionType = "ArangoMemberUpdatePodSpec" // ActionTypeArangoMemberUpdatePodStatus updates pod spec ActionTypeArangoMemberUpdatePodStatus ActionType = "ArangoMemberUpdatePodStatus" - // ActionTypeBootstrapSetAgencyInfo set agency info into state - ActionTypeBootstrapSetAgencyInfo ActionType = "BootstrapSetAgencyInfo" // Runtime Updates // ActionTypeRuntimeContainerImageUpdate updates container image in runtime diff --git a/pkg/apis/deployment/v2alpha1/server_group_spec.go b/pkg/apis/deployment/v2alpha1/server_group_spec.go index bb855ce70..132b8ad60 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_spec.go +++ b/pkg/apis/deployment/v2alpha1/server_group_spec.go @@ -81,6 +81,8 @@ type ServerGroupSpec struct { Args []string `json:"args,omitempty"` // Entrypoint overrides container executable Entrypoint *string `json:"entrypoint,omitempty"` + // SchedulerName define scheduler name used for group + SchedulerName *string `json:"schedulerName,omitempty"` // StorageClassName specifies the classname for storage of the servers. StorageClassName *string `json:"storageClassName,omitempty"` // Resources holds resource requests & limits diff --git a/pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go b/pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go index e74e063a8..792b75964 100644 --- a/pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go @@ -1505,6 +1505,11 @@ func (in *ServerGroupSpec) DeepCopyInto(out *ServerGroupSpec) { *out = new(string) **out = **in } + if in.SchedulerName != nil { + in, out := &in.SchedulerName, &out.SchedulerName + *out = new(string) + **out = **in + } if in.StorageClassName != nil { in, out := &in.StorageClassName, &out.StorageClassName *out = new(string) diff --git a/pkg/deployment/resources/pod_creator_arangod.go b/pkg/deployment/resources/pod_creator_arangod.go index b7c552dda..68187e6e0 100644 --- a/pkg/deployment/resources/pod_creator_arangod.go +++ b/pkg/deployment/resources/pod_creator_arangod.go @@ -571,6 +571,10 @@ func (m *MemberArangoDPod) createMetricsExporterSidecarExternalExporter() *core. func (m *MemberArangoDPod) ApplyPodSpec(p *core.PodSpec) error { p.SecurityContext = m.groupSpec.SecurityContext.NewPodSecurityContext() + if s := m.groupSpec.SchedulerName; s != nil { + p.SchedulerName = *s + } + return nil } diff --git a/pkg/deployment/resources/pod_creator_sync.go b/pkg/deployment/resources/pod_creator_sync.go index 7f36d7326..2f3d985bd 100644 --- a/pkg/deployment/resources/pod_creator_sync.go +++ b/pkg/deployment/resources/pod_creator_sync.go @@ -315,6 +315,10 @@ func (m *MemberSyncPod) Validate(cachedStatus interfaces.Inspector) error { } func (m *MemberSyncPod) ApplyPodSpec(spec *core.PodSpec) error { + if s := m.groupSpec.SchedulerName; s != nil { + spec.SchedulerName = *s + } + return nil } diff --git a/pkg/deployment/rotation/arangod.go b/pkg/deployment/rotation/arangod.go new file mode 100644 index 000000000..80ebd01e8 --- /dev/null +++ b/pkg/deployment/rotation/arangod.go @@ -0,0 +1,37 @@ +// +// DISCLAIMER +// +// Copyright 2020 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 ( + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + core "k8s.io/api/core/v1" +) + +func podCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodSpec) compareFunc { + return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, err error) { + if spec.SchedulerName != status.SchedulerName { + status.SchedulerName = spec.SchedulerName + mode = mode.And(SilentRotation) + } + + return + } +} diff --git a/pkg/deployment/rotation/arangod_test.go b/pkg/deployment/rotation/arangod_test.go new file mode 100644 index 000000000..0dab7c395 --- /dev/null +++ b/pkg/deployment/rotation/arangod_test.go @@ -0,0 +1,69 @@ +// +// DISCLAIMER +// +// Copyright 2020-2021 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 +// +// Author Adam Janikowski +// + +package rotation + +import ( + "testing" + + core "k8s.io/api/core/v1" +) + +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" + }), + + expectedMode: SilentRotation, + }, + { + name: "Change SchedulerName into Empty", + spec: buildPodSpec(func(pod *core.PodTemplateSpec) { + pod.Spec.SchedulerName = "new" + }), + status: buildPodSpec(func(pod *core.PodTemplateSpec) { + pod.Spec.SchedulerName = "" + }), + + expectedMode: SilentRotation, + }, + { + name: "SchedulerName equals", + spec: buildPodSpec(func(pod *core.PodTemplateSpec) { + pod.Spec.SchedulerName = "" + }), + status: buildPodSpec(func(pod *core.PodTemplateSpec) { + pod.Spec.SchedulerName = "" + }), + + expectedMode: SkippedRotation, + }, + } + + runTestCases(t)(testCases...) +} diff --git a/pkg/deployment/rotation/compare.go b/pkg/deployment/rotation/compare.go index 036409164..2368e0272 100644 --- a/pkg/deployment/rotation/compare.go +++ b/pkg/deployment/rotation/compare.go @@ -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(containersCompare), g(initContainersCompare)); err != nil { + if m, p, err := compareFuncs(b, g(podCompare), g(containersCompare), g(initContainersCompare)); err != nil { log.Err(err).Msg("Error while getting pod diff") return SkippedRotation, nil, err } else {