Skip to content

Commit

Permalink
Merge pull request #36 from spotahome/devops-738-make-sentinelconf-wr…
Browse files Browse the repository at this point in the history
…itable

[Devops-738] Make sentinel.conf writable
  • Loading branch information
jchanam authored Mar 28, 2018
2 parents 82bd0b1 + 502a75c commit 74ac2c3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 0.2.0
VERSION := 0.2.1

# Name of this service/application
SERVICE_NAME := redis-operator
Expand Down
42 changes: 21 additions & 21 deletions operator/redisfailover/service/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestCheckAllSlavesFromMasterGetSlaveOfError(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "",
},
Expand All @@ -196,7 +196,7 @@ func TestCheckAllSlavesFromMasterDifferentMaster(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand All @@ -222,7 +222,7 @@ func TestCheckAllSlavesFromMaster(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestCheckSentinelNumberInMemoryGetNumberSentinelInMemoryError(t *testing.T)

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand All @@ -289,7 +289,7 @@ func TestCheckSentinelNumberInMemoryNumberMismatch(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand All @@ -315,7 +315,7 @@ func TestCheckSentinelNumberInMemory(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestCheckSentinelSlavesNumberInMemoryGetNumberSentinelSlavesInMemoryError(t

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand All @@ -382,7 +382,7 @@ func TestCheckSentinelSlavesNumberInMemoryReplicasMismatch(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand All @@ -408,7 +408,7 @@ func TestCheckSentinelSlavesNumberInMemory(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand Down Expand Up @@ -488,7 +488,7 @@ func TestGetMasterIPIsMasterError(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand All @@ -514,12 +514,12 @@ func TestGetMasterIPMultipleMastersError(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
},
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "1.1.1.1",
},
Expand All @@ -546,12 +546,12 @@ func TestGetMasterIP(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
},
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "1.1.1.1",
},
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestGetNumberMastersIsMasterError(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
Expand All @@ -620,12 +620,12 @@ func TestGetNumberMasters(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
},
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "1.1.1.1",
},
Expand Down Expand Up @@ -653,12 +653,12 @@ func TestGetNumberMastersTwo(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "0.0.0.0",
},
},
corev1.Pod{
{
Status: corev1.PodStatus{
PodIP: "1.1.1.1",
},
Expand Down Expand Up @@ -705,14 +705,14 @@ func TestGetMinimumRedisPodTime(t *testing.T) {

pods := &corev1.PodList{
Items: []corev1.Pod{
corev1.Pod{
{
Status: corev1.PodStatus{
StartTime: &metav1.Time{
Time: oneHour,
},
},
},
corev1.Pod{
{
Status: corev1.PodStatus{
StartTime: &metav1.Time{
Time: oneMinute,
Expand Down
66 changes: 52 additions & 14 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func generateSentinelService(rf *redisfailoverv1alpha2.RedisFailover, labels map
Spec: corev1.ServiceSpec{
Selector: labels,
Ports: []corev1.ServicePort{
corev1.ServicePort{
{
Name: "sentinel",
Port: 26379,
TargetPort: sentinelTargetPort,
Expand Down Expand Up @@ -59,7 +59,7 @@ func generateRedisService(rf *redisfailoverv1alpha2.RedisFailover, labels map[st
Type: corev1.ServiceTypeClusterIP,
ClusterIP: corev1.ClusterIPNone,
Ports: []corev1.ServicePort{
corev1.ServicePort{
{
Port: exporterPort,
Protocol: corev1.ProtocolTCP,
Name: exporterPortName,
Expand Down Expand Up @@ -144,19 +144,19 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma
Spec: corev1.PodSpec{
Affinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels),
Containers: []corev1.Container{
corev1.Container{
{
Name: "redis",
Image: redisImage,
ImagePullPolicy: "Always",
Ports: []corev1.ContainerPort{
corev1.ContainerPort{
{
Name: "redis",
ContainerPort: 6379,
Protocol: corev1.ProtocolTCP,
},
},
VolumeMounts: []corev1.VolumeMount{
corev1.VolumeMount{
{
Name: "redis-config",
MountPath: "/redis",
},
Expand Down Expand Up @@ -195,7 +195,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma
},
},
Volumes: []corev1.Volume{
corev1.Volume{
{
Name: "redis-config",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
Expand Down Expand Up @@ -246,21 +246,53 @@ func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels
},
Spec: corev1.PodSpec{
Affinity: createPodAntiAffinity(rf.Spec.HardAntiAffinity, labels),
InitContainers: []corev1.Container{
{
Name: "sentinel-config-copy",
Image: "alpine",
ImagePullPolicy: "IfNotPresent",
VolumeMounts: []corev1.VolumeMount{
{
Name: "sentinel-config",
MountPath: "/redis",
},
{
Name: "sentinel-config-writable",
MountPath: "/redis-writable",
},
},
Command: []string{
"cp",
fmt.Sprintf("/redis/%s", sentinelConfigFileName),
fmt.Sprintf("/redis-writable/%s", sentinelConfigFileName),
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("10m"),
corev1.ResourceMemory: resource.MustParse("10Mi"),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("10m"),
corev1.ResourceMemory: resource.MustParse("10Mi"),
},
},
},
},
Containers: []corev1.Container{
corev1.Container{
{
Name: "sentinel",
Image: redisImage,
ImagePullPolicy: "Always",
Ports: []corev1.ContainerPort{
corev1.ContainerPort{
{
Name: "sentinel",
ContainerPort: 26379,
Protocol: corev1.ProtocolTCP,
},
},
VolumeMounts: []corev1.VolumeMount{
corev1.VolumeMount{
Name: "sentinel-config",
{
Name: "sentinel-config-writable",
MountPath: "/redis",
},
},
Expand Down Expand Up @@ -299,7 +331,7 @@ func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels
},
},
Volumes: []corev1.Volume{
corev1.Volume{
{
Name: "sentinel-config",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
Expand All @@ -309,6 +341,12 @@ func generateSentinelDeployment(rf *redisfailoverv1alpha2.RedisFailover, labels
},
},
},
{
Name: "sentinel-config-writable",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
},
},
},
Expand Down Expand Up @@ -372,7 +410,7 @@ func createRedisExporterContainer() corev1.Container {
Image: exporterImage,
ImagePullPolicy: "Always",
Ports: []corev1.ContainerPort{
corev1.ContainerPort{
{
Name: "metrics",
ContainerPort: exporterPort,
Protocol: corev1.ProtocolTCP,
Expand Down Expand Up @@ -416,7 +454,7 @@ func createPodAntiAffinity(hard bool, labels map[string]string) *corev1.Affinity
return &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
corev1.PodAffinityTerm{
{
TopologyKey: hostnameTopologyKey,
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels,
Expand All @@ -431,7 +469,7 @@ func createPodAntiAffinity(hard bool, labels map[string]string) *corev1.Affinity
return &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
corev1.WeightedPodAffinityTerm{
{
Weight: 100,
PodAffinityTerm: corev1.PodAffinityTerm{
TopologyKey: hostnameTopologyKey,
Expand Down
Loading

0 comments on commit 74ac2c3

Please sign in to comment.