Add nodeSelector and tolerations

Change-Id: I4e50f21add4f56b08fa6f3b5df6d5508d52b960c
This commit is contained in:
Mohammed Naser 2020-03-20 18:29:14 -04:00
parent 98eb3813c1
commit d03a182dbc
9 changed files with 216 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package v1alpha1 package v1alpha1
import ( import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
@ -11,8 +12,10 @@ type McrouterPoolSpec struct {
// McrouterSpec defines the desired state of Mcrouter // McrouterSpec defines the desired state of Mcrouter
type McrouterSpec struct { type McrouterSpec struct {
Pools map[string]McrouterPoolSpec `json:"pools"` Pools map[string]McrouterPoolSpec `json:"pools"`
Route string `json:"route"` Route string `json:"route"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
} }
// McrouterStatus defines the observed state of Mcrouter // McrouterStatus defines the observed state of Mcrouter

View File

@ -1,6 +1,7 @@
package v1alpha1 package v1alpha1
import ( import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
@ -8,7 +9,9 @@ import (
type MemcachedSpec struct { type MemcachedSpec struct {
// +kubebuilder:validation:Required // +kubebuilder:validation:Required
// +kubebuilder:validation:Default=64 // +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 // MemcachedStatus defines the observed state of Memcached

View File

@ -21,6 +21,7 @@ limitations under the License.
package v1alpha1 package v1alpha1
import ( import (
"k8s.io/api/core/v1"
runtime "k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
) )
@ -113,6 +114,20 @@ func (in *McrouterSpec) DeepCopyInto(out *McrouterSpec) {
(*out)[key] = *val.DeepCopy() (*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. // 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 = *in
out.TypeMeta = in.TypeMeta out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec in.Spec.DeepCopyInto(&out.Spec)
out.Status = in.Status 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. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MemcachedSpec) DeepCopyInto(out *MemcachedSpec) { func (in *MemcachedSpec) DeepCopyInto(out *MemcachedSpec) {
*out = *in *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. // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemcachedSpec.

View File

@ -34,6 +34,10 @@ spec:
spec: spec:
description: McrouterSpec defines the desired state of Mcrouter description: McrouterSpec defines the desired state of Mcrouter
properties: properties:
nodeSelector:
additionalProperties:
type: string
type: object
pools: pools:
additionalProperties: additionalProperties:
description: McrouterPoolSpec defines the desired state of an Mcrouter description: McrouterPoolSpec defines the desired state of an Mcrouter
@ -49,6 +53,45 @@ spec:
type: object type: object
route: route:
type: string type: string
tolerations:
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
required: required:
- pools - pools
- route - route

View File

@ -36,6 +36,49 @@ spec:
properties: properties:
megabytes: megabytes:
type: integer 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 <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
required: required:
- megabytes - megabytes
type: object type: object

View File

@ -34,6 +34,10 @@ spec:
spec: spec:
description: McrouterSpec defines the desired state of Mcrouter description: McrouterSpec defines the desired state of Mcrouter
properties: properties:
nodeSelector:
additionalProperties:
type: string
type: object
pools: pools:
additionalProperties: additionalProperties:
description: McrouterPoolSpec defines the desired state of an Mcrouter description: McrouterPoolSpec defines the desired state of an Mcrouter
@ -49,6 +53,45 @@ spec:
type: object type: object
route: route:
type: string type: string
tolerations:
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
required: required:
- pools - pools
- route - route

View File

@ -36,6 +36,49 @@ spec:
properties: properties:
megabytes: megabytes:
type: integer 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 <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
required: required:
- megabytes - megabytes
type: object type: object

View File

@ -203,6 +203,8 @@ func (r *McrouterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
}, },
}, },
}, },
NodeSelector: mcrouter.Spec.NodeSelector,
Tolerations: mcrouter.Spec.Tolerations,
}, },
} }

View File

@ -220,6 +220,9 @@ func (r *MemcachedReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
}, },
} }
op, err = controllerutil.CreateOrUpdate(ctx, r, mcrouter, func() 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.Route = "PoolRoute|default"
mcrouter.Spec.Pools = map[string]infrastructurev1alpha1.McrouterPoolSpec{ mcrouter.Spec.Pools = map[string]infrastructurev1alpha1.McrouterPoolSpec{
"default": infrastructurev1alpha1.McrouterPoolSpec{ "default": infrastructurev1alpha1.McrouterPoolSpec{