Skip to content

Commit

Permalink
Merge pull request #8 from tomp21/fix/cm_names
Browse files Browse the repository at this point in the history
modify configmap names to include instance identifier and avoid collisions
  • Loading branch information
tomp21 authored Dec 26, 2024
2 parents b58d7ab + 2bf125f commit ff7daa9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: ghcr.io/tomp21/yazio-challenge
newTag: main
newName: controller
newTag: local
8 changes: 5 additions & 3 deletions internal/controller/reconcilers/configmap_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package reconcilers

import (
_ "embed"
"fmt"

"context"

cachev1alpha1 "github.com/tomp21/yazio-challenge/api/v1alpha1"
"github.com/tomp21/yazio-challenge/internal/util"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -77,7 +79,7 @@ func (r *ConfigMapReconciler) Reconcile(ctx context.Context, redis *cachev1alpha
func (r *ConfigMapReconciler) ReconcileStartScripts(ctx context.Context, redis *cachev1alpha1.Redis) error {
cmStartScripts := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "start-scripts",
Name: fmt.Sprintf("%s-start-scripts", redis.Name),
Namespace: redis.Namespace,
Labels: util.GetLabels(redis, nil),
},
Expand All @@ -96,7 +98,7 @@ func (r *ConfigMapReconciler) ReconcileStartScripts(ctx context.Context, redis *
func (r *ConfigMapReconciler) ReconcileConfigs(ctx context.Context, redis *cachev1alpha1.Redis) error {
cmConfig := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "redis-conf",
Name: fmt.Sprintf("%s-conf", redis.Name),
Namespace: redis.Namespace,
Labels: util.GetLabels(redis, nil),
},
Expand All @@ -116,7 +118,7 @@ func (r *ConfigMapReconciler) ReconcileConfigs(ctx context.Context, redis *cache
func (r *ConfigMapReconciler) ReconcileHealthScripts(ctx context.Context, redis *cachev1alpha1.Redis) error {
cmHealth := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "redis-health",
Name: fmt.Sprintf("%s-health", redis.Name),
Namespace: redis.Namespace,
Labels: util.GetLabels(redis, nil),
},
Expand Down
12 changes: 6 additions & 6 deletions internal/controller/reconcilers/statefulset_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ 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()
ss.Spec.Template.Spec.Volumes = getVolumes(redis.Name)
ss.Spec.VolumeClaimTemplates = getVolumeClaimTemplates(redis, util.GetLabels(redis, nil))
return ss
}
Expand All @@ -164,7 +164,7 @@ 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()
ss.Spec.Template.Spec.Volumes = getVolumes(redis.Name)
ss.Spec.VolumeClaimTemplates = getVolumeClaimTemplates(redis, util.GetLabels(redis, nil))
return ss
}
Expand Down Expand Up @@ -377,15 +377,15 @@ func getVolumeClaimTemplates(redis *cachev1alpha1.Redis, labels map[string]strin
}
}

func getVolumes() []corev1.Volume {
func getVolumes(instanceName string) []corev1.Volume {
defaultMode := int32(0755)
return []corev1.Volume{
{
Name: "start-scripts",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "start-scripts",
Name: fmt.Sprintf("%s-start-scripts", instanceName),
},
DefaultMode: &defaultMode,
},
Expand All @@ -395,7 +395,7 @@ func getVolumes() []corev1.Volume {
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "redis-conf",
Name: fmt.Sprintf("%s-conf", instanceName),
},
DefaultMode: &defaultMode,
},
Expand All @@ -405,7 +405,7 @@ func getVolumes() []corev1.Volume {
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "redis-health",
Name: fmt.Sprintf("%s-health", instanceName),
},
DefaultMode: &defaultMode,
},
Expand Down

0 comments on commit ff7daa9

Please sign in to comment.