fix potential panic when acessing empty list (#88)

while fixing #87, noticed a couple lines down that if the containers
spec has more than 1 container, the code probably intends to set
Spec.Containers to a list with a single container, but is instead
setting it to an empty list. The very next lines are trying to access
the 1st element of this empty list, which will result in a panic
This commit is contained in:
Tomás Mota
2025-12-29 21:56:37 +01:00
committed by GitHub
parent 54c3139ee2
commit 54403eb901
@@ -242,7 +242,7 @@ func (r *NBRoutingPeerReconciler) handleDeployment(ctx context.Context, req ctrl
updatedDeployment.Spec.Template.ObjectMeta.Labels = podLabels
updatedDeployment.Spec.Template.Spec.Volumes = nbrp.Spec.Volumes
if len(updatedDeployment.Spec.Template.Spec.Containers) != 1 {
updatedDeployment.Spec.Template.Spec.Containers = []corev1.Container{}
updatedDeployment.Spec.Template.Spec.Containers = []corev1.Container{{}}
}
updatedDeployment.Spec.Template.Spec.Containers[0].Name = "netbird"
updatedDeployment.Spec.Template.Spec.Containers[0].Image = r.ClientImage