From 20ecdb949b79139e17bc8e68385649cd3de939be Mon Sep 17 00:00:00 2001 From: Zane Williamson Date: Tue, 14 Apr 2020 11:53:06 -0700 Subject: [PATCH] bug: adding missing inputs for zk tolerations and node selector support Signed-off-by: Zane Williamson --- api/v1beta1/solrcloud_types.go | 11 ++++- api/v1beta1/zz_generated.deepcopy.go | 14 ++++++ .../bases/solr.bloomberg.com_solrclouds.yaml | 49 +++++++++++++++++++ controllers/util/zk_util.go | 22 +++++++++ .../test_solrcloud_toleration_example.yaml | 8 +++ helm/solr-operator/crds/crds.yaml | 49 +++++++++++++++++++ 6 files changed, 152 insertions(+), 1 deletion(-) diff --git a/api/v1beta1/solrcloud_types.go b/api/v1beta1/solrcloud_types.go index 61bc3002..94490be2 100644 --- a/api/v1beta1/solrcloud_types.go +++ b/api/v1beta1/solrcloud_types.go @@ -18,11 +18,12 @@ package v1beta1 import ( "fmt" + "strings" + zk "github.com/pravega/zookeeper-operator/pkg/apis/zookeeper/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "strings" ) const ( @@ -353,6 +354,14 @@ type ZookeeperPodPolicy struct { // +optional Affinity *corev1.Affinity `json:"affinity,omitempty"` + // Node Selector to be added on pods. + // +optional + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + + // Tolerations to be added on pods. + // +optional + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + // Resources is the resource requirements for the container. // This field cannot be updated once the cluster is created. // +optional diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 71cafb0e..df79e33d 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -1301,6 +1301,20 @@ func (in *ZookeeperPodPolicy) DeepCopyInto(out *ZookeeperPodPolicy) { *out = new(v1.Affinity) (*in).DeepCopyInto(*out) } + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + 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]) + } + } in.Resources.DeepCopyInto(&out.Resources) } diff --git a/config/crd/bases/solr.bloomberg.com_solrclouds.yaml b/config/crd/bases/solr.bloomberg.com_solrclouds.yaml index 404bdffc..743d2342 100644 --- a/config/crd/bases/solr.bloomberg.com_solrclouds.yaml +++ b/config/crd/bases/solr.bloomberg.com_solrclouds.yaml @@ -7053,6 +7053,11 @@ spec: type: array type: object type: object + nodeSelector: + additionalProperties: + type: string + description: Node Selector to be added on pods. + type: object resources: description: Resources is the resource requirements for the container. This field cannot be updated once @@ -7074,6 +7079,50 @@ spec: an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/' type: object type: object + tolerations: + description: Tolerations to be added on 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 type: object type: object type: object diff --git a/controllers/util/zk_util.go b/controllers/util/zk_util.go index 92e5c17a..24ccdcd7 100644 --- a/controllers/util/zk_util.go +++ b/controllers/util/zk_util.go @@ -83,6 +83,14 @@ func GenerateZookeeperCluster(solrCloud *solr.SolrCloud, zkSpec solr.ZookeeperSp zkCluster.Spec.Pod.Resources = zkSpec.ZookeeperPod.Resources } + if zkSpec.ZookeeperPod.Tolerations != nil { + zkCluster.Spec.Pod.Tolerations = zkSpec.ZookeeperPod.Tolerations + } + + if zkSpec.ZookeeperPod.NodeSelector != nil { + zkCluster.Spec.Pod.NodeSelector = zkSpec.ZookeeperPod.NodeSelector + } + return zkCluster } @@ -153,6 +161,20 @@ func CopyZookeeperClusterFields(from, to *zk.ZookeeperCluster) bool { } to.Spec.Pod.Resources = from.Spec.Pod.Resources + if !DeepEqualWithNils(to.Spec.Pod.Tolerations, from.Spec.Pod.Tolerations) { + log.Info("Updating Zk tolerations") + log.Info("Update required because:", "Spec.Pod.Tolerations canged from", to.Spec.Pod.Tolerations, "To:", from.Spec.Pod.Tolerations) + requireUpdate = true + to.Spec.Pod.Tolerations = from.Spec.Pod.Tolerations + } + + if !DeepEqualWithNils(to.Spec.Pod.NodeSelector, from.Spec.Pod.NodeSelector) { + log.Info("Updating Zk nodeSelector") + log.Info("Update required because:", "Spec.Pod.NodeSelector canged from", to.Spec.Pod.NodeSelector, "To:", from.Spec.Pod.NodeSelector) + requireUpdate = true + to.Spec.Pod.NodeSelector = from.Spec.Pod.NodeSelector + } + if from.Spec.Pod.Affinity != nil { if !DeepEqualWithNils(to.Spec.Pod.Affinity.NodeAffinity, from.Spec.Pod.Affinity.NodeAffinity) { log.Info("Updating Zk pod node affinity") diff --git a/example/test_solrcloud_toleration_example.yaml b/example/test_solrcloud_toleration_example.yaml index 91de0d1e..2f334810 100644 --- a/example/test_solrcloud_toleration_example.yaml +++ b/example/test_solrcloud_toleration_example.yaml @@ -38,6 +38,14 @@ spec: storage: "5Gi" replicas: 1 zookeeperPodPolicy: + nodeSelector: + beta.kubernetes.io/os: linux + beta.kubernetes.io/arch: amd64 + tolerations: + - effect: NoSchedule + key: node-restriction.kubernetes.io/workloads + operator: Equal + value: zookeeper resources: limits: memory: "1G" diff --git a/helm/solr-operator/crds/crds.yaml b/helm/solr-operator/crds/crds.yaml index e8b5ad37..9377f0fe 100644 --- a/helm/solr-operator/crds/crds.yaml +++ b/helm/solr-operator/crds/crds.yaml @@ -8531,6 +8531,11 @@ spec: type: array type: object type: object + nodeSelector: + additionalProperties: + type: string + description: Node Selector to be added on pods. + type: object resources: description: Resources is the resource requirements for the container. This field cannot be updated once @@ -8552,6 +8557,50 @@ spec: an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/' type: object type: object + tolerations: + description: Tolerations to be added on 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 type: object type: object type: object