Skip to content

Commit 0aaeba2

Browse files
authored
Adding missing inputs for zk tolerations and node selector support (#108)
1 parent 3442918 commit 0aaeba2

File tree

6 files changed

+152
-1
lines changed

6 files changed

+152
-1
lines changed

api/v1beta1/solrcloud_types.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ package v1beta1
1818

1919
import (
2020
"fmt"
21+
"strings"
22+
2123
zk "github.com/pravega/zookeeper-operator/pkg/apis/zookeeper/v1beta1"
2224
corev1 "k8s.io/api/core/v1"
2325
"k8s.io/apimachinery/pkg/api/resource"
2426
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
"strings"
2627
)
2728

2829
const (
@@ -353,6 +354,14 @@ type ZookeeperPodPolicy struct {
353354
// +optional
354355
Affinity *corev1.Affinity `json:"affinity,omitempty"`
355356

357+
// Node Selector to be added on pods.
358+
// +optional
359+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
360+
361+
// Tolerations to be added on pods.
362+
// +optional
363+
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
364+
356365
// Resources is the resource requirements for the container.
357366
// This field cannot be updated once the cluster is created.
358367
// +optional

api/v1beta1/zz_generated.deepcopy.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/solr.bloomberg.com_solrclouds.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -7053,6 +7053,11 @@ spec:
70537053
type: array
70547054
type: object
70557055
type: object
7056+
nodeSelector:
7057+
additionalProperties:
7058+
type: string
7059+
description: Node Selector to be added on pods.
7060+
type: object
70567061
resources:
70577062
description: Resources is the resource requirements
70587063
for the container. This field cannot be updated once
@@ -7074,6 +7079,50 @@ spec:
70747079
an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
70757080
type: object
70767081
type: object
7082+
tolerations:
7083+
description: Tolerations to be added on pods.
7084+
items:
7085+
description: The pod this Toleration is attached to
7086+
tolerates any taint that matches the triple <key,value,effect>
7087+
using the matching operator <operator>.
7088+
properties:
7089+
effect:
7090+
description: Effect indicates the taint effect
7091+
to match. Empty means match all taint effects.
7092+
When specified, allowed values are NoSchedule,
7093+
PreferNoSchedule and NoExecute.
7094+
type: string
7095+
key:
7096+
description: Key is the taint key that the toleration
7097+
applies to. Empty means match all taint keys.
7098+
If the key is empty, operator must be Exists;
7099+
this combination means to match all values and
7100+
all keys.
7101+
type: string
7102+
operator:
7103+
description: Operator represents a key's relationship
7104+
to the value. Valid operators are Exists and
7105+
Equal. Defaults to Equal. Exists is equivalent
7106+
to wildcard for value, so that a pod can tolerate
7107+
all taints of a particular category.
7108+
type: string
7109+
tolerationSeconds:
7110+
description: TolerationSeconds represents the
7111+
period of time the toleration (which must be
7112+
of effect NoExecute, otherwise this field is
7113+
ignored) tolerates the taint. By default, it
7114+
is not set, which means tolerate the taint forever
7115+
(do not evict). Zero and negative values will
7116+
be treated as 0 (evict immediately) by the system.
7117+
format: int64
7118+
type: integer
7119+
value:
7120+
description: Value is the taint value the toleration
7121+
matches to. If the operator is Exists, the value
7122+
should be empty, otherwise just a regular string.
7123+
type: string
7124+
type: object
7125+
type: array
70777126
type: object
70787127
type: object
70797128
type: object

controllers/util/zk_util.go

+22
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ func GenerateZookeeperCluster(solrCloud *solr.SolrCloud, zkSpec solr.ZookeeperSp
8383
zkCluster.Spec.Pod.Resources = zkSpec.ZookeeperPod.Resources
8484
}
8585

86+
if zkSpec.ZookeeperPod.Tolerations != nil {
87+
zkCluster.Spec.Pod.Tolerations = zkSpec.ZookeeperPod.Tolerations
88+
}
89+
90+
if zkSpec.ZookeeperPod.NodeSelector != nil {
91+
zkCluster.Spec.Pod.NodeSelector = zkSpec.ZookeeperPod.NodeSelector
92+
}
93+
8694
return zkCluster
8795
}
8896

@@ -153,6 +161,20 @@ func CopyZookeeperClusterFields(from, to *zk.ZookeeperCluster) bool {
153161
}
154162
to.Spec.Pod.Resources = from.Spec.Pod.Resources
155163

164+
if !DeepEqualWithNils(to.Spec.Pod.Tolerations, from.Spec.Pod.Tolerations) {
165+
log.Info("Updating Zk tolerations")
166+
log.Info("Update required because:", "Spec.Pod.Tolerations canged from", to.Spec.Pod.Tolerations, "To:", from.Spec.Pod.Tolerations)
167+
requireUpdate = true
168+
to.Spec.Pod.Tolerations = from.Spec.Pod.Tolerations
169+
}
170+
171+
if !DeepEqualWithNils(to.Spec.Pod.NodeSelector, from.Spec.Pod.NodeSelector) {
172+
log.Info("Updating Zk nodeSelector")
173+
log.Info("Update required because:", "Spec.Pod.NodeSelector canged from", to.Spec.Pod.NodeSelector, "To:", from.Spec.Pod.NodeSelector)
174+
requireUpdate = true
175+
to.Spec.Pod.NodeSelector = from.Spec.Pod.NodeSelector
176+
}
177+
156178
if from.Spec.Pod.Affinity != nil {
157179
if !DeepEqualWithNils(to.Spec.Pod.Affinity.NodeAffinity, from.Spec.Pod.Affinity.NodeAffinity) {
158180
log.Info("Updating Zk pod node affinity")

example/test_solrcloud_toleration_example.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ spec:
3838
storage: "5Gi"
3939
replicas: 1
4040
zookeeperPodPolicy:
41+
nodeSelector:
42+
beta.kubernetes.io/os: linux
43+
beta.kubernetes.io/arch: amd64
44+
tolerations:
45+
- effect: NoSchedule
46+
key: node-restriction.kubernetes.io/workloads
47+
operator: Equal
48+
value: zookeeper
4149
resources:
4250
limits:
4351
memory: "1G"

helm/solr-operator/crds/crds.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -8531,6 +8531,11 @@ spec:
85318531
type: array
85328532
type: object
85338533
type: object
8534+
nodeSelector:
8535+
additionalProperties:
8536+
type: string
8537+
description: Node Selector to be added on pods.
8538+
type: object
85348539
resources:
85358540
description: Resources is the resource requirements
85368541
for the container. This field cannot be updated once
@@ -8552,6 +8557,50 @@ spec:
85528557
an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
85538558
type: object
85548559
type: object
8560+
tolerations:
8561+
description: Tolerations to be added on pods.
8562+
items:
8563+
description: The pod this Toleration is attached to
8564+
tolerates any taint that matches the triple <key,value,effect>
8565+
using the matching operator <operator>.
8566+
properties:
8567+
effect:
8568+
description: Effect indicates the taint effect
8569+
to match. Empty means match all taint effects.
8570+
When specified, allowed values are NoSchedule,
8571+
PreferNoSchedule and NoExecute.
8572+
type: string
8573+
key:
8574+
description: Key is the taint key that the toleration
8575+
applies to. Empty means match all taint keys.
8576+
If the key is empty, operator must be Exists;
8577+
this combination means to match all values and
8578+
all keys.
8579+
type: string
8580+
operator:
8581+
description: Operator represents a key's relationship
8582+
to the value. Valid operators are Exists and
8583+
Equal. Defaults to Equal. Exists is equivalent
8584+
to wildcard for value, so that a pod can tolerate
8585+
all taints of a particular category.
8586+
type: string
8587+
tolerationSeconds:
8588+
description: TolerationSeconds represents the
8589+
period of time the toleration (which must be
8590+
of effect NoExecute, otherwise this field is
8591+
ignored) tolerates the taint. By default, it
8592+
is not set, which means tolerate the taint forever
8593+
(do not evict). Zero and negative values will
8594+
be treated as 0 (evict immediately) by the system.
8595+
format: int64
8596+
type: integer
8597+
value:
8598+
description: Value is the taint value the toleration
8599+
matches to. If the operator is Exists, the value
8600+
should be empty, otherwise just a regular string.
8601+
type: string
8602+
type: object
8603+
type: array
85558604
type: object
85568605
type: object
85578606
type: object

0 commit comments

Comments
 (0)