From d03a182dbcf9c8abecfd69da1ff017c3ec77bd87 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Fri, 20 Mar 2020 18:29:14 -0400 Subject: [PATCH] Add nodeSelector and tolerations Change-Id: I4e50f21add4f56b08fa6f3b5df6d5508d52b960c --- api/v1alpha1/mcrouter_types.go | 7 ++- api/v1alpha1/memcached_types.go | 5 ++- api/v1alpha1/zz_generated.deepcopy.go | 31 ++++++++++++- ...frastructure.vexxhost.cloud_mcrouters.yaml | 43 +++++++++++++++++++ ...rastructure.vexxhost.cloud_memcacheds.yaml | 43 +++++++++++++++++++ ...frastructure.vexxhost.cloud_mcrouters.yaml | 43 +++++++++++++++++++ ...rastructure.vexxhost.cloud_memcacheds.yaml | 43 +++++++++++++++++++ controllers/mcrouter_controller.go | 2 + controllers/memcached_controller.go | 3 ++ 9 files changed, 216 insertions(+), 4 deletions(-) diff --git a/api/v1alpha1/mcrouter_types.go b/api/v1alpha1/mcrouter_types.go index 70ac9476..bed530ae 100644 --- a/api/v1alpha1/mcrouter_types.go +++ b/api/v1alpha1/mcrouter_types.go @@ -1,6 +1,7 @@ package v1alpha1 import ( + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -11,8 +12,10 @@ type McrouterPoolSpec struct { // McrouterSpec defines the desired state of Mcrouter type McrouterSpec struct { - Pools map[string]McrouterPoolSpec `json:"pools"` - Route string `json:"route"` + Pools map[string]McrouterPoolSpec `json:"pools"` + Route string `json:"route"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + Tolerations []v1.Toleration `json:"tolerations,omitempty"` } // McrouterStatus defines the observed state of Mcrouter diff --git a/api/v1alpha1/memcached_types.go b/api/v1alpha1/memcached_types.go index 10c6e577..56daa6f8 100644 --- a/api/v1alpha1/memcached_types.go +++ b/api/v1alpha1/memcached_types.go @@ -1,6 +1,7 @@ package v1alpha1 import ( + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -8,7 +9,9 @@ import ( type MemcachedSpec struct { // +kubebuilder:validation:Required // +kubebuilder:validation:Default=64 - Megabytes int `json:"megabytes"` + Megabytes int `json:"megabytes"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + Tolerations []v1.Toleration `json:"tolerations,omitempty"` } // MemcachedStatus defines the observed state of Memcached diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 79b637d7..503622ec 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -21,6 +21,7 @@ limitations under the License. package v1alpha1 import ( + "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -113,6 +114,20 @@ func (in *McrouterSpec) DeepCopyInto(out *McrouterSpec) { (*out)[key] = *val.DeepCopy() } } + 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]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new McrouterSpec. @@ -145,7 +160,7 @@ func (in *Memcached) DeepCopyInto(out *Memcached) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) out.Status = in.Status } @@ -202,6 +217,20 @@ func (in *MemcachedList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MemcachedSpec) DeepCopyInto(out *MemcachedSpec) { *out = *in + 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]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedSpec. diff --git a/chart/crds/infrastructure.vexxhost.cloud_mcrouters.yaml b/chart/crds/infrastructure.vexxhost.cloud_mcrouters.yaml index 4bcb67b5..673522d1 100644 --- a/chart/crds/infrastructure.vexxhost.cloud_mcrouters.yaml +++ b/chart/crds/infrastructure.vexxhost.cloud_mcrouters.yaml @@ -34,6 +34,10 @@ spec: spec: description: McrouterSpec defines the desired state of Mcrouter properties: + nodeSelector: + additionalProperties: + type: string + type: object pools: additionalProperties: description: McrouterPoolSpec defines the desired state of an Mcrouter @@ -49,6 +53,45 @@ spec: type: object route: type: string + tolerations: + 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 required: - pools - route diff --git a/chart/crds/infrastructure.vexxhost.cloud_memcacheds.yaml b/chart/crds/infrastructure.vexxhost.cloud_memcacheds.yaml index 60670218..6ec17f8c 100644 --- a/chart/crds/infrastructure.vexxhost.cloud_memcacheds.yaml +++ b/chart/crds/infrastructure.vexxhost.cloud_memcacheds.yaml @@ -36,6 +36,49 @@ spec: properties: megabytes: type: integer + nodeSelector: + additionalProperties: + type: string + type: object + tolerations: + 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 required: - megabytes type: object diff --git a/config/crd/bases/infrastructure.vexxhost.cloud_mcrouters.yaml b/config/crd/bases/infrastructure.vexxhost.cloud_mcrouters.yaml index 4bcb67b5..673522d1 100644 --- a/config/crd/bases/infrastructure.vexxhost.cloud_mcrouters.yaml +++ b/config/crd/bases/infrastructure.vexxhost.cloud_mcrouters.yaml @@ -34,6 +34,10 @@ spec: spec: description: McrouterSpec defines the desired state of Mcrouter properties: + nodeSelector: + additionalProperties: + type: string + type: object pools: additionalProperties: description: McrouterPoolSpec defines the desired state of an Mcrouter @@ -49,6 +53,45 @@ spec: type: object route: type: string + tolerations: + 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 required: - pools - route diff --git a/config/crd/bases/infrastructure.vexxhost.cloud_memcacheds.yaml b/config/crd/bases/infrastructure.vexxhost.cloud_memcacheds.yaml index 60670218..6ec17f8c 100644 --- a/config/crd/bases/infrastructure.vexxhost.cloud_memcacheds.yaml +++ b/config/crd/bases/infrastructure.vexxhost.cloud_memcacheds.yaml @@ -36,6 +36,49 @@ spec: properties: megabytes: type: integer + nodeSelector: + additionalProperties: + type: string + type: object + tolerations: + 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 required: - megabytes type: object diff --git a/controllers/mcrouter_controller.go b/controllers/mcrouter_controller.go index 5b755f3c..0c0acabc 100755 --- a/controllers/mcrouter_controller.go +++ b/controllers/mcrouter_controller.go @@ -203,6 +203,8 @@ func (r *McrouterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { }, }, }, + NodeSelector: mcrouter.Spec.NodeSelector, + Tolerations: mcrouter.Spec.Tolerations, }, } diff --git a/controllers/memcached_controller.go b/controllers/memcached_controller.go index ab1e280d..eed45cb2 100755 --- a/controllers/memcached_controller.go +++ b/controllers/memcached_controller.go @@ -220,6 +220,9 @@ func (r *MemcachedReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { }, } op, err = controllerutil.CreateOrUpdate(ctx, r, mcrouter, func() error { + mcrouter.Spec.NodeSelector = memcached.Spec.NodeSelector + mcrouter.Spec.Tolerations = memcached.Spec.Tolerations + mcrouter.Spec.Route = "PoolRoute|default" mcrouter.Spec.Pools = map[string]infrastructurev1alpha1.McrouterPoolSpec{ "default": infrastructurev1alpha1.McrouterPoolSpec{