From 132d7c632911274ec77b3cb9fd61ba3b00f35373 Mon Sep 17 00:00:00 2001 From: Jan Lauber Date: Mon, 15 Apr 2024 23:34:17 +0200 Subject: [PATCH] fix: reverse names Signed-off-by: Jan Lauber --- controllers/deployment.go | 12 ++++++------ controllers/ingress.go | 16 ++++++++-------- controllers/service.go | 4 ++-- controllers/volume.go | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/controllers/deployment.go b/controllers/deployment.go index ba1bfaf..e02c07a 100644 --- a/controllers/deployment.go +++ b/controllers/deployment.go @@ -189,15 +189,15 @@ func (r *RolloutReconciler) deploymentForRollout(ctx context.Context, f *oneclic var volumeMounts []corev1.VolumeMount for _, v := range f.Spec.Volumes { volumes = append(volumes, corev1.Volume{ - Name: f.Name + "-" + v.Name, + Name: v.Name + "-" + f.Name, VolumeSource: corev1.VolumeSource{ PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: f.Name + "-" + v.Name, + ClaimName: v.Name + "-" + f.Name, }, }, }) volumeMounts = append(volumeMounts, corev1.VolumeMount{ - Name: f.Name + "-" + v.Name, + Name: v.Name + "-" + f.Name, MountPath: v.MountPath, }) } @@ -320,18 +320,18 @@ func volumesMatch(currentVolumes []corev1.Volume, desiredVolumes []oneclickiov1a desiredVolumeMap := make(map[string]oneclickiov1alpha1.VolumeSpec) for _, v := range desiredVolumes { - desiredVolumeMap[f.Name+"-"+v.Name] = v + desiredVolumeMap[v.Name+"-"+f.Name] = v } for _, currentVolume := range currentVolumes { - volSpec, exists := desiredVolumeMap[f.Name+"-"+currentVolume.Name] + volSpec, exists := desiredVolumeMap[currentVolume.Name+"-"+f.Name] if !exists { // Volume is present in Deployment but not in Rollout spec return false } // Check PVC name - if currentVolume.VolumeSource.PersistentVolumeClaim.ClaimName != f.Name+"-"+volSpec.Name { + if currentVolume.VolumeSource.PersistentVolumeClaim.ClaimName != volSpec.Name+"-"+f.Name { return false } // Additional checks can be added here, such as PVC size, storage class, etc. diff --git a/controllers/ingress.go b/controllers/ingress.go index 16926e5..84c3e18 100644 --- a/controllers/ingress.go +++ b/controllers/ingress.go @@ -23,7 +23,7 @@ func (r *RolloutReconciler) reconcileIngress(ctx context.Context, f *oneclickiov for _, intf := range f.Spec.Interfaces { // Process each interface if intf.Ingress.IngressClass != "" || len(intf.Ingress.Rules) > 0 { - expectedIngresses[f.Name+"-"+intf.Name+"-ingress"] = true + expectedIngresses[intf.Name+"-"+f.Name+"-ingress"] = true ingress := r.ingressForRollout(f, intf) foundIngress := &networkingv1.Ingress{} @@ -78,10 +78,10 @@ func (r *RolloutReconciler) reconcileIngress(ctx context.Context, f *oneclickiov } } else { // No Ingress configuration for this interface, delete the Ingress if it exists - if _, exists := expectedIngresses[f.Name+"-"+intf.Name+"-ingress"]; exists { + if _, exists := expectedIngresses[intf.Name+"-"+f.Name+"-ingress"]; exists { ingress := &networkingv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ - Name: f.Name + "-" + intf.Name + "-ingress", + Name: intf.Name + "-" + f.Name + "-ingress", Namespace: f.Namespace, }, } @@ -129,7 +129,7 @@ func (r *RolloutReconciler) ingressForRollout(f *oneclickiov1alpha1.Rollout, int } ingress := &networkingv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ - Name: f.Name + "-" + intf.Name + "-ingress", // Create a unique name for the Ingress + Name: intf.Name + "-" + f.Name + "-ingress", // Create a unique name for the Ingress Namespace: f.Namespace, Labels: labels, Annotations: make(map[string]string), @@ -167,7 +167,7 @@ func (r *RolloutReconciler) ingressForRollout(f *oneclickiov1alpha1.Rollout, int }(), Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ - Name: f.Name + "-" + intf.Name + "-svc", + Name: intf.Name + "-" + f.Name + "-svc", Port: networkingv1.ServiceBackendPort{ Number: intf.Port, }, @@ -188,7 +188,7 @@ func (r *RolloutReconciler) ingressForRollout(f *oneclickiov1alpha1.Rollout, int if rule.TlsSecretName == "" { tls = networkingv1.IngressTLS{ Hosts: []string{rule.Host}, - SecretName: f.Name + "-" + intf.Name + "-tls-secret", // Name of the TLS secret + SecretName: intf.Name + "-" + f.Name + "-tls-secret", // Name of the TLS secret } } else { tls = networkingv1.IngressTLS{ @@ -221,7 +221,7 @@ func getIngressRules(f *oneclickiov1alpha1.Rollout, intf oneclickiov1alpha1.Inte }(), Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ - Name: f.Name + "-" + intf.Name + "-svc", + Name: intf.Name + "-" + f.Name + "-svc", Port: networkingv1.ServiceBackendPort{ Number: intf.Port, }, @@ -250,7 +250,7 @@ func getIngressTLS(f *oneclickiov1alpha1.Rollout, intf oneclickiov1alpha1.Interf if rule.TlsSecretName == "" { tls = networkingv1.IngressTLS{ Hosts: []string{rule.Host}, - SecretName: f.Name + "-" + intf.Name + "-tls-secret", // Name of the TLS secret + SecretName: intf.Name + "-" + f.Name + "-tls-secret", // Name of the TLS secret } } else { tls = networkingv1.IngressTLS{ diff --git a/controllers/service.go b/controllers/service.go index 9e60bbb..bdbdbb0 100644 --- a/controllers/service.go +++ b/controllers/service.go @@ -20,7 +20,7 @@ func (r *RolloutReconciler) reconcileService(ctx context.Context, f *oneclickiov expectedServices := make(map[string]bool) for _, intf := range f.Spec.Interfaces { - serviceName := f.Name + "-" + intf.Name + "-svc" + serviceName := intf.Name + "-" + f.Name + "-svc" expectedServices[serviceName] = true service := r.serviceForRollout(f, intf) @@ -72,7 +72,7 @@ func (r *RolloutReconciler) serviceForRollout(f *oneclickiov1alpha1.Rollout, int } svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: f.Name + "-" + intf.Name + "-svc", + Name: intf.Name + "-" + f.Name + "-svc", Namespace: f.Namespace, Labels: labels, }, diff --git a/controllers/volume.go b/controllers/volume.go index be756f9..f83592b 100644 --- a/controllers/volume.go +++ b/controllers/volume.go @@ -23,7 +23,7 @@ func (r *RolloutReconciler) reconcilePVCs(ctx context.Context, f *oneclickiov1al expectedPVCs := make(map[string]struct{}) for _, volSpec := range f.Spec.Volumes { - pvcName := f.Name + "-" + volSpec.Name + pvcName := volSpec.Name + "-" + f.Name expectedPVCs[pvcName] = struct{}{} desiredPVC := r.constructPVCForRollout(f, volSpec) @@ -95,7 +95,7 @@ func (r *RolloutReconciler) constructPVCForRollout(f *oneclickiov1alpha1.Rollout return &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ - Name: f.Name + "-" + volSpec.Name, + Name: volSpec.Name + "-" + f.Name, Namespace: f.Namespace, Labels: labels, OwnerReferences: []metav1.OwnerReference{