Skip to content

Commit

Permalink
Issue 192: add toleration support for bookie pods (#193)
Browse files Browse the repository at this point in the history
* add toleration support for bookie pods

Signed-off-by: Alfred Landrum <[email protected]>

* run controller-gen

Signed-off-by: Alfred Landrum <[email protected]>
  • Loading branch information
alfred-landrum authored May 13, 2022
1 parent 874e8d1 commit f746eca
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 18 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/bookkeepercluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 7 additions & 16 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"))
})
})
})
40 changes: 40 additions & 0 deletions config/crd/bases/bookkeeper.pravega.io_bookkeeperclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <key,value,effect> using the matching
operator <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
Expand Down
5 changes: 3 additions & 2 deletions controllers/bookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
15 changes: 15 additions & 0 deletions controllers/bookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ var _ = Describe("Bookie", func() {
},
},
RunAsPrivilegedUser: &boolFalse,
Tolerations: []corev1.Toleration{
{
Key: "bookie",
Operator: "Equal",
Value: "val1",
Effect: "NoSchedule",
},
},
}
bk.WithDefaults()
})
Expand Down Expand Up @@ -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")))
})
})
})

Expand Down

0 comments on commit f746eca

Please sign in to comment.