Skip to content

Commit

Permalink
fix: reverse names
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Lauber <jan.lauber@protonmail.ch>
  • Loading branch information
janlauber committed Apr 15, 2024
1 parent a7431e4 commit 132d7c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions controllers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions controllers/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
},
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
},
Expand All @@ -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{
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions controllers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions controllers/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 132d7c6

Please sign in to comment.