From 39dbb08a870d9a3559010569a066953b9840f94c Mon Sep 17 00:00:00 2001 From: Alexey Papushin Date: Tue, 19 Feb 2019 14:35:50 +0300 Subject: [PATCH 1/6] Tolerations support added --- api/redisfailover/v1alpha2/types.go | 1 + api/redisfailover/v1alpha2/zz_generated.deepcopy.go | 9 ++++++++- client/k8s/clientset/versioned/clientset.go | 2 +- client/k8s/clientset/versioned/doc.go | 2 +- .../k8s/clientset/versioned/fake/clientset_generated.go | 2 +- client/k8s/clientset/versioned/fake/doc.go | 2 +- client/k8s/clientset/versioned/fake/register.go | 2 +- client/k8s/clientset/versioned/scheme/doc.go | 2 +- client/k8s/clientset/versioned/scheme/register.go | 2 +- .../versioned/typed/redisfailover/v1alpha2/doc.go | 2 +- .../versioned/typed/redisfailover/v1alpha2/fake/doc.go | 2 +- .../redisfailover/v1alpha2/fake/fake_redisfailover.go | 2 +- .../v1alpha2/fake/fake_redisfailover_client.go | 2 +- .../typed/redisfailover/v1alpha2/generated_expansion.go | 2 +- .../typed/redisfailover/v1alpha2/redisfailover.go | 2 +- .../typed/redisfailover/v1alpha2/redisfailover_client.go | 2 +- operator/redisfailover/service/generator.go | 2 ++ 17 files changed, 25 insertions(+), 15 deletions(-) diff --git a/api/redisfailover/v1alpha2/types.go b/api/redisfailover/v1alpha2/types.go index f0f2dfa28..02a5fb8c8 100644 --- a/api/redisfailover/v1alpha2/types.go +++ b/api/redisfailover/v1alpha2/types.go @@ -31,6 +31,7 @@ type RedisFailoverSpec struct { // NodeAffinity defines the rules for scheduling the Redis and Sentinel // nodes NodeAffinity *corev1.NodeAffinity `json:"nodeAffinity,omitempty"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` } // RedisSettings defines the specification of the redis cluster diff --git a/api/redisfailover/v1alpha2/zz_generated.deepcopy.go b/api/redisfailover/v1alpha2/zz_generated.deepcopy.go index 92824b5fe..32e6d666a 100644 --- a/api/redisfailover/v1alpha2/zz_generated.deepcopy.go +++ b/api/redisfailover/v1alpha2/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -150,6 +150,13 @@ func (in *RedisFailoverSpec) DeepCopyInto(out *RedisFailoverSpec) { (*in).DeepCopyInto(*out) } } + 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]) + } + } return } diff --git a/client/k8s/clientset/versioned/clientset.go b/client/k8s/clientset/versioned/clientset.go index 6719ab78b..bb2309b5e 100644 --- a/client/k8s/clientset/versioned/clientset.go +++ b/client/k8s/clientset/versioned/clientset.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/doc.go b/client/k8s/clientset/versioned/doc.go index 006b79214..dc992b90b 100644 --- a/client/k8s/clientset/versioned/doc.go +++ b/client/k8s/clientset/versioned/doc.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/fake/clientset_generated.go b/client/k8s/clientset/versioned/fake/clientset_generated.go index ffedf3807..5204aacc1 100644 --- a/client/k8s/clientset/versioned/fake/clientset_generated.go +++ b/client/k8s/clientset/versioned/fake/clientset_generated.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/fake/doc.go b/client/k8s/clientset/versioned/fake/doc.go index 0bc260bca..acfa6173b 100644 --- a/client/k8s/clientset/versioned/fake/doc.go +++ b/client/k8s/clientset/versioned/fake/doc.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/fake/register.go b/client/k8s/clientset/versioned/fake/register.go index 16fefffa0..beb1344d8 100644 --- a/client/k8s/clientset/versioned/fake/register.go +++ b/client/k8s/clientset/versioned/fake/register.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/scheme/doc.go b/client/k8s/clientset/versioned/scheme/doc.go index 5c5c8debb..7f61dc1f9 100644 --- a/client/k8s/clientset/versioned/scheme/doc.go +++ b/client/k8s/clientset/versioned/scheme/doc.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/scheme/register.go b/client/k8s/clientset/versioned/scheme/register.go index 1da7216a7..6662b27d6 100644 --- a/client/k8s/clientset/versioned/scheme/register.go +++ b/client/k8s/clientset/versioned/scheme/register.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/doc.go b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/doc.go index 01dd46de8..e4cda4fe2 100644 --- a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/doc.go +++ b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/doc.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/doc.go b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/doc.go index 87a1873ed..ab4fd43ad 100644 --- a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/doc.go +++ b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/doc.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/fake_redisfailover.go b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/fake_redisfailover.go index d7953c4fb..855e86d51 100644 --- a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/fake_redisfailover.go +++ b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/fake_redisfailover.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/fake_redisfailover_client.go b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/fake_redisfailover_client.go index 484152e0d..f61dcee83 100644 --- a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/fake_redisfailover_client.go +++ b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/fake/fake_redisfailover_client.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/generated_expansion.go b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/generated_expansion.go index 4c8a5c22d..450523d83 100644 --- a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/generated_expansion.go +++ b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/generated_expansion.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/redisfailover.go b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/redisfailover.go index 57872488a..56267d808 100644 --- a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/redisfailover.go +++ b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/redisfailover.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/redisfailover_client.go b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/redisfailover_client.go index cf0a5dcbf..d45c230d6 100644 --- a/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/redisfailover_client.go +++ b/client/k8s/clientset/versioned/typed/redisfailover/v1alpha2/redisfailover_client.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 078878923..d9593ca81 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -186,6 +186,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma NodeAffinity: rf.Spec.NodeAffinity, PodAntiAffinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels), }, + Tolerations: rf.Spec.Tolerations, Containers: []corev1.Container{ { Name: "redis", @@ -294,6 +295,7 @@ func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels NodeAffinity: rf.Spec.NodeAffinity, PodAntiAffinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels), }, + Tolerations: rf.Spec.Tolerations, InitContainers: []corev1.Container{ { Name: "sentinel-config-copy", From 65549ea9d043aa06289e80d2c87d7834c3a54a9d Mon Sep 17 00:00:00 2001 From: wowsel Date: Fri, 22 Feb 2019 09:10:17 +0300 Subject: [PATCH 2/6] Update README.md --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 20c61abaa..a72adcfeb 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,42 @@ redis: - "hz 50" ``` +You can use NodeAffinity and Tolerations for deploy redis to isolation nodes, like production. + +Example: +``` +apiVersion: v1 +items: +- apiVersion: storage.spotahome.com/v1alpha2 + kind: RedisFailover + metadata: + name: redis + spec: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kops.k8s.io/instancegroup + operator: In + values: + - productionnodes + hardAntiAffinity: false + redis: null + sentinel: + replicas: 3 + resources: + limits: + memory: 100Mi + requests: + cpu: 100m + tolerations: + - effect: NoExecute + key: dedicated + operator: Equal + value: production +kind: List +``` + **Important*: this options will be set via `config set` or `sentinel set mymaster`. In the Sentinel options, there are some "conversions" to be made. - Configuration on the `sentinel.conf`: `sentinel down-after-milliseconds mymaster 2000` From f278912950b502606742e1d1611e85ee12530b65 Mon Sep 17 00:00:00 2001 From: wowsel Date: Fri, 22 Feb 2019 09:12:04 +0300 Subject: [PATCH 3/6] Update README.md --- README.md | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a72adcfeb..81a0a8e9d 100644 --- a/README.md +++ b/README.md @@ -59,25 +59,11 @@ In order to have persistance, a PersistentVolumeClaim usage is allowed. The full **IMPORTANT**: By default, the persistent volume claims will be deleted when the Redis Failover is. If this is not the expected usage, a `keepAfterDeletion` flag can be added under the `storage` section of Redis. [An example is given](example/redisfailover/persistant-storage-no-pvc-deletion.yaml). -### Custom configurations -It is possible to configure both Redis and Sentinel. This is done with the `customConfig` option inside their spec. It is a list of configurations and their values. - -Example: -```yaml -sentinel: - customConfig: - - "down-after-milliseconds 2000" - - "failover-timeout 3000" -redis: - customConfig: - - "maxclients 100" - - "hz 50" -``` - +### NodeAffinity and Tolerations You can use NodeAffinity and Tolerations for deploy redis to isolation nodes, like production. Example: -``` +```yaml apiVersion: v1 items: - apiVersion: storage.spotahome.com/v1alpha2 @@ -110,6 +96,21 @@ items: kind: List ``` +### Custom configurations +It is possible to configure both Redis and Sentinel. This is done with the `customConfig` option inside their spec. It is a list of configurations and their values. + +Example: +```yaml +sentinel: + customConfig: + - "down-after-milliseconds 2000" + - "failover-timeout 3000" +redis: + customConfig: + - "maxclients 100" + - "hz 50" +``` + **Important*: this options will be set via `config set` or `sentinel set mymaster`. In the Sentinel options, there are some "conversions" to be made. - Configuration on the `sentinel.conf`: `sentinel down-after-milliseconds mymaster 2000` From cce72d356807c30dc0ec96b0603cc78008cc8b7b Mon Sep 17 00:00:00 2001 From: wowsel Date: Fri, 22 Feb 2019 13:30:24 +0300 Subject: [PATCH 4/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81a0a8e9d..ad4bcf247 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ In order to have persistance, a PersistentVolumeClaim usage is allowed. The full **IMPORTANT**: By default, the persistent volume claims will be deleted when the Redis Failover is. If this is not the expected usage, a `keepAfterDeletion` flag can be added under the `storage` section of Redis. [An example is given](example/redisfailover/persistant-storage-no-pvc-deletion.yaml). ### NodeAffinity and Tolerations -You can use NodeAffinity and Tolerations for deploy redis to isolation nodes, like production. +You can use NodeAffinity and Tolerations to deploy Pods to isolated groups of Nodes Example: ```yaml From 2e825515523cb8c7636625eebf2b662371f8c52d Mon Sep 17 00:00:00 2001 From: Alexey Papushin Date: Tue, 26 Feb 2019 17:20:24 +0300 Subject: [PATCH 5/6] API documentation --- api/redisfailover/v1alpha2/types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/redisfailover/v1alpha2/types.go b/api/redisfailover/v1alpha2/types.go index 02a5fb8c8..ff1a6dc04 100644 --- a/api/redisfailover/v1alpha2/types.go +++ b/api/redisfailover/v1alpha2/types.go @@ -31,6 +31,8 @@ type RedisFailoverSpec struct { // NodeAffinity defines the rules for scheduling the Redis and Sentinel // nodes NodeAffinity *corev1.NodeAffinity `json:"nodeAffinity,omitempty"` + + //Tolerations provides a way to schedule Pods on Tainted Nodes Tolerations []corev1.Toleration `json:"tolerations,omitempty"` } From d62cd3652bda41821b7791b817200a1c5601bc63 Mon Sep 17 00:00:00 2001 From: Alexey Papushin Date: Tue, 26 Feb 2019 17:24:00 +0300 Subject: [PATCH 6/6] delete tab --- api/redisfailover/v1alpha2/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/redisfailover/v1alpha2/types.go b/api/redisfailover/v1alpha2/types.go index ff1a6dc04..a797e5d5c 100644 --- a/api/redisfailover/v1alpha2/types.go +++ b/api/redisfailover/v1alpha2/types.go @@ -31,7 +31,7 @@ type RedisFailoverSpec struct { // NodeAffinity defines the rules for scheduling the Redis and Sentinel // nodes NodeAffinity *corev1.NodeAffinity `json:"nodeAffinity,omitempty"` - + //Tolerations provides a way to schedule Pods on Tainted Nodes Tolerations []corev1.Toleration `json:"tolerations,omitempty"` }