Skip to content

Commit

Permalink
[DEVOPS-738] Add init container to copy sentinel.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Chana committed Mar 28, 2018
1 parent 82bd0b1 commit 8a6034e
Showing 1 changed file with 52 additions and 14 deletions.
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

0 comments on commit 8a6034e

Please sign in to comment.