diff --git a/.travis.yml b/.travis.yml index 1a9ae4e7a..75fb22296 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ go: go_import_path: github.com/spotahome/redis-operator before_install: - - curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ + - curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.25.2/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ - curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.4/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ env: diff --git a/Makefile b/Makefile index 2d6d29642..2f85803c9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 0.2.2 +VERSION := 0.2.3 # Name of this service/application SERVICE_NAME := redis-operator diff --git a/api/redisfailover/v1alpha2/types.go b/api/redisfailover/v1alpha2/types.go index 431efeacd..061ec6781 100644 --- a/api/redisfailover/v1alpha2/types.go +++ b/api/redisfailover/v1alpha2/types.go @@ -1,6 +1,7 @@ package v1alpha2 import ( + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -26,6 +27,10 @@ type RedisFailoverSpec struct { // HardAntiAffinity defines if the PodAntiAffinity on the deployments and // statefulsets has to be hard (it's soft by default) HardAntiAffinity bool `json:"hardAntiAffinity,omitempty"` + + // NodeAffinity defines the rules for scheduling the Redis and Sentinel + // nodes + NodeAffinity *corev1.NodeAffinity `json:"nodeAffinity,omitempty"` } // RedisSettings defines the specification of the redis cluster diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 3b277c692..afdf075bc 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -147,7 +147,10 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma Labels: labels, }, Spec: corev1.PodSpec{ - Affinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels), + Affinity: &corev1.Affinity{ + NodeAffinity: rf.Spec.NodeAffinity, + PodAntiAffinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels), + }, Containers: []corev1.Container{ { Name: "redis", @@ -250,7 +253,10 @@ func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels Labels: labels, }, Spec: corev1.PodSpec{ - Affinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels), + Affinity: &corev1.Affinity{ + NodeAffinity: rf.Spec.NodeAffinity, + PodAntiAffinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels), + }, InitContainers: []corev1.Container{ { Name: "sentinel-config-copy", @@ -417,12 +423,11 @@ func createRedisExporterContainer() corev1.Container { Env: []corev1.EnvVar{ { Name: "REDIS_ALIAS", - ValueFrom: - &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - FieldPath: "metadata.name", - }, + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + FieldPath: "metadata.name", }, + }, }, }, Ports: []corev1.ContainerPort{ @@ -464,17 +469,15 @@ func createRedisExporterContainer() corev1.Container { } } -func createPodAntiAffinity(hard bool, labels map[string]string) *corev1.Affinity { +func createPodAntiAffinity(hard bool, labels map[string]string) *corev1.PodAntiAffinity { if hard { // Return a HARD anti-affinity (no same pods on one node) - return &corev1.Affinity{ - PodAntiAffinity: &corev1.PodAntiAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{ - { - TopologyKey: hostnameTopologyKey, - LabelSelector: &metav1.LabelSelector{ - MatchLabels: labels, - }, + return &corev1.PodAntiAffinity{ + RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{ + { + TopologyKey: hostnameTopologyKey, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: labels, }, }, }, @@ -482,16 +485,14 @@ func createPodAntiAffinity(hard bool, labels map[string]string) *corev1.Affinity } // Return a SOFT anti-affinity - return &corev1.Affinity{ - PodAntiAffinity: &corev1.PodAntiAffinity{ - PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ - { - Weight: 100, - PodAffinityTerm: corev1.PodAffinityTerm{ - TopologyKey: hostnameTopologyKey, - LabelSelector: &metav1.LabelSelector{ - MatchLabels: labels, - }, + return &corev1.PodAntiAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ + { + Weight: 100, + PodAffinityTerm: corev1.PodAffinityTerm{ + TopologyKey: hostnameTopologyKey, + LabelSelector: &metav1.LabelSelector{ + MatchLabels: labels, }, }, }, diff --git a/scripts/integration-tests.sh b/scripts/integration-tests.sh index ab06d3fc4..6faa82a80 100755 --- a/scripts/integration-tests.sh +++ b/scripts/integration-tests.sh @@ -15,7 +15,7 @@ function cleanup { trap cleanup EXIT echo "=> Preparing minikube for running integration tests" -$SUDO minikube start --vm-driver=none +$SUDO minikube start --vm-driver=none --kubernetes-version=v1.9.4 echo "=> Waiting for minikube to start" sleep 30