Skip to content

Commit

Permalink
hotfix: missing replica.conf and improved volumeClaimTemplate labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
tomp21 committed Dec 26, 2024
1 parent 8bd2b00 commit b9ffe80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 5 additions & 0 deletions internal/controller/reconcilers/configmaps/conf/replica.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dir /data
# User-supplied replica configuration:
rename-command FLUSHDB ""
rename-command FLUSHALL ""
# End of replica configuration
21 changes: 10 additions & 11 deletions internal/controller/reconcilers/statefulset_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func getResources() corev1.ResourceRequirements {
func generateReplicaStatefulSet(ss appsv1.StatefulSet, redis *cachev1alpha1.Redis) appsv1.StatefulSet {
imageFullName := fmt.Sprintf("%s:%s", redisImage, redis.Spec.Version)
labels := util.GetLabels(redis, util.ReplicaLabels)
defaultCMMode := int32(0755)
ss.ObjectMeta.SetName(fmt.Sprintf("%s-replica", redis.Name))
ss.ObjectMeta.SetNamespace(redis.Namespace)
ss.ObjectMeta.SetLabels(labels)
Expand All @@ -147,16 +146,15 @@ func generateReplicaStatefulSet(ss appsv1.StatefulSet, redis *cachev1alpha1.Redi
}
ss.Spec.Template.ObjectMeta.SetLabels(labels)
ss.Spec.Template.Spec.Containers = getReplicaContainers(redis.Name, imageFullName)
ss.Spec.Template.Spec.Volumes = getVolumes(defaultCMMode)
ss.Spec.VolumeClaimTemplates = getVolumeClaimTemplates(redis)
ss.Spec.Template.Spec.Volumes = getVolumes()
ss.Spec.VolumeClaimTemplates = getVolumeClaimTemplates(redis, util.GetLabels(redis, nil))
return ss
}

func generateMasterStatefulSet(ss appsv1.StatefulSet, redis *cachev1alpha1.Redis) appsv1.StatefulSet {
imageFullName := fmt.Sprintf("%s:%s", redisImage, redis.Spec.Version)
labels := util.GetLabels(redis, util.MasterLabels)
masterReplicas := int32(1)
defaultCMMode := int32(0755)
ss.ObjectMeta.SetName(fmt.Sprintf("%s-master", redis.Name))
ss.ObjectMeta.SetNamespace(redis.Namespace)
ss.ObjectMeta.SetLabels(labels)
Expand All @@ -166,8 +164,8 @@ func generateMasterStatefulSet(ss appsv1.StatefulSet, redis *cachev1alpha1.Redis
}
ss.Spec.Template.ObjectMeta.SetLabels(labels)
ss.Spec.Template.Spec.Containers = getMasterContainers(redis.Name, imageFullName)
ss.Spec.Template.Spec.Volumes = getVolumes(defaultCMMode)
ss.Spec.VolumeClaimTemplates = getVolumeClaimTemplates(redis)
ss.Spec.Template.Spec.Volumes = getVolumes()
ss.Spec.VolumeClaimTemplates = getVolumeClaimTemplates(redis, util.GetLabels(redis, nil))
return ss
}

Expand Down Expand Up @@ -283,7 +281,7 @@ func getReplicaContainers(name, image string) []corev1.Container {
}
}

func getVolumeClaimTemplates(redis *cachev1alpha1.Redis) []corev1.PersistentVolumeClaim {
func getVolumeClaimTemplates(redis *cachev1alpha1.Redis, labels map[string]string) []corev1.PersistentVolumeClaim {
return []corev1.PersistentVolumeClaim{
{
TypeMeta: metav1.TypeMeta{
Expand All @@ -292,7 +290,7 @@ func getVolumeClaimTemplates(redis *cachev1alpha1.Redis) []corev1.PersistentVolu
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-data", redis.Name),
Labels: util.GetLabels(redis, nil),
Labels: labels,
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{
Expand All @@ -308,7 +306,8 @@ func getVolumeClaimTemplates(redis *cachev1alpha1.Redis) []corev1.PersistentVolu
}
}

func getVolumes(defaultCMMode int32) []corev1.Volume {
func getVolumes() []corev1.Volume {
defaultMode := int32(0755)
return []corev1.Volume{
{
Name: "start-scripts",
Expand All @@ -317,7 +316,7 @@ func getVolumes(defaultCMMode int32) []corev1.Volume {
LocalObjectReference: corev1.LocalObjectReference{
Name: "start-scripts",
},
DefaultMode: &defaultCMMode,
DefaultMode: &defaultMode,
},
},
}, {
Expand All @@ -327,7 +326,7 @@ func getVolumes(defaultCMMode int32) []corev1.Volume {
LocalObjectReference: corev1.LocalObjectReference{
Name: "redis-conf",
},
DefaultMode: &defaultCMMode,
DefaultMode: &defaultMode,
},
},
},
Expand Down

0 comments on commit b9ffe80

Please sign in to comment.