From f746eca6ad72ceee49c83e3152ef7aeac53d5b8f Mon Sep 17 00:00:00 2001 From: Alfred Landrum Date: Fri, 13 May 2022 10:26:29 -0700 Subject: [PATCH] Issue 192: add toleration support for bookie pods (#193) * add toleration support for bookie pods Signed-off-by: Alfred Landrum * run controller-gen Signed-off-by: Alfred Landrum --- api/v1alpha1/bookkeepercluster_types.go | 3 ++ api/v1alpha1/zz_generated.deepcopy.go | 23 ++++------- api/v1alpha1/zz_generated.deepcopy_test.go | 11 +++++ ...kkeeper.pravega.io_bookkeeperclusters.yaml | 40 +++++++++++++++++++ controllers/bookie.go | 5 ++- controllers/bookie_test.go | 15 +++++++ 6 files changed, 79 insertions(+), 18 deletions(-) diff --git a/api/v1alpha1/bookkeepercluster_types.go b/api/v1alpha1/bookkeepercluster_types.go index 2eb2a1b9..1b3879ba 100644 --- a/api/v1alpha1/bookkeepercluster_types.go +++ b/api/v1alpha1/bookkeepercluster_types.go @@ -256,6 +256,9 @@ type BookkeeperClusterSpec struct { //This is set to run the container as root user RunAsPrivilegedUser *bool `json:"runAsPrivilegedUser,omitempty"` + + // Tolerations for the bookie pods. + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` } // BookkeeperImageSpec defines the fields needed for a BookKeeper Docker image diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 71d50cee..833eac13 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1,22 +1,6 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -/* -Copyright 2022. - -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. -*/ - // Code generated by controller-gen. DO NOT EDIT. package v1alpha1 @@ -161,6 +145,13 @@ func (in *BookkeeperClusterSpec) DeepCopyInto(out *BookkeeperClusterSpec) { *out = new(bool) **out = **in } + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]v1.Toleration, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BookkeeperClusterSpec. diff --git a/api/v1alpha1/zz_generated.deepcopy_test.go b/api/v1alpha1/zz_generated.deepcopy_test.go index 38e4ca58..0bb0e67a 100644 --- a/api/v1alpha1/zz_generated.deepcopy_test.go +++ b/api/v1alpha1/zz_generated.deepcopy_test.go @@ -58,6 +58,14 @@ var _ = Describe("DeepCopy", func() { }, } bk1.Spec.InitContainers = initContainer + bk1.Spec.Tolerations = []v1.Toleration{ + { + Key: "bookie", + Operator: "Equal", + Value: "val1", + Effect: "NoSchedule", + }, + } bk1.Spec.JVMOptions.MemoryOpts = []string{"1g"} bk2.Spec.JVMOptions = bk1.Spec.JVMOptions.DeepCopy() bk2.Spec.Storage = bk1.Spec.Storage.DeepCopy() @@ -202,5 +210,8 @@ var _ = Describe("DeepCopy", func() { bk := bk2.DeepCopyObject() Ω(bk.GetObjectKind().GroupVersionKind().Version).To(Equal("")) }) + It("checking pod tolerations", func() { + Ω(bk2.Spec.Tolerations[0].Key).To(Equal("bookie")) + }) }) }) diff --git a/config/crd/bases/bookkeeper.pravega.io_bookkeeperclusters.yaml b/config/crd/bases/bookkeeper.pravega.io_bookkeeperclusters.yaml index 4ad1ca6a..a3f15606 100644 --- a/config/crd/bases/bookkeeper.pravega.io_bookkeeperclusters.yaml +++ b/config/crd/bases/bookkeeper.pravega.io_bookkeeperclusters.yaml @@ -2785,6 +2785,46 @@ spec: type: string type: object type: object + tolerations: + description: Tolerations for the bookie pods. + items: + description: The pod this Toleration is attached to tolerates any + taint that matches the triple using the matching + operator . + properties: + effect: + description: Effect indicates the taint effect to match. Empty + means match all taint effects. When specified, allowed values + are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: Key is the taint key that the toleration applies + to. Empty means match all taint keys. If the key is empty, + operator must be Exists; this combination means to match all + values and all keys. + type: string + operator: + description: Operator represents a key's relationship to the + value. Valid operators are Exists and Equal. Defaults to Equal. + Exists is equivalent to wildcard for value, so that a pod + can tolerate all taints of a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the period of time + the toleration (which must be of effect NoExecute, otherwise + this field is ignored) tolerates the taint. By default, it + is not set, which means tolerate the taint forever (do not + evict). Zero and negative values will be treated as 0 (evict + immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration matches + to. If the operator is Exists, the value should be empty, + otherwise just a regular string. + type: string + type: object + type: array version: description: "Version is the expected version of the Bookkeeper cluster. The bookkeeper-operator will eventually make the Bookkeeper cluster diff --git a/controllers/bookie.go b/controllers/bookie.go index d7b6b43a..050356b8 100644 --- a/controllers/bookie.go +++ b/controllers/bookie.go @@ -277,8 +277,9 @@ func makeBookiePodSpec(bk *v1alpha1.BookkeeperCluster) *corev1.PodSpec { }, }, }, - Affinity: bk.Spec.Affinity, - Volumes: volumes, + Affinity: bk.Spec.Affinity, + Volumes: volumes, + Tolerations: bk.Spec.Tolerations, } if bk.Spec.ServiceAccountName != "" { diff --git a/controllers/bookie_test.go b/controllers/bookie_test.go index 1678a705..e3e34638 100644 --- a/controllers/bookie_test.go +++ b/controllers/bookie_test.go @@ -105,6 +105,14 @@ var _ = Describe("Bookie", func() { }, }, RunAsPrivilegedUser: &boolFalse, + Tolerations: []corev1.Toleration{ + { + Key: "bookie", + Operator: "Equal", + Value: "val1", + Effect: "NoSchedule", + }, + }, } bk.WithDefaults() }) @@ -228,6 +236,13 @@ var _ = Describe("Bookie", func() { Ω(fmt.Sprintf("%v", *podTemplate.Spec.SecurityContext.RunAsGroup)).To(Equal("1000")) Ω(fmt.Sprintf("%v", *podTemplate.Spec.SecurityContext.FSGroup)).To(Equal("1000")) }) + It("should have pod tolerations", func() { + podTemplate := bookkeepercluster.MakeBookiePodTemplate(bk) + Ω(podTemplate.Spec.Tolerations[0].Key).Should(Equal("bookie")) + Ω(podTemplate.Spec.Tolerations[0].Operator).Should(Equal(corev1.TolerationOperator("Equal"))) + Ω(podTemplate.Spec.Tolerations[0].Value).Should(Equal("val1")) + Ω(podTemplate.Spec.Tolerations[0].Effect).Should(Equal(corev1.TaintEffect("NoSchedule"))) + }) }) })