Fix sidecar injection when pod annotations is nil. (#250)

When a pod does not have any annotations the injector will fail. This
change adds a test for the case and also fixes the issue.

Fixes #246

Signed-off-by: Philip Laine <philip.laine@gmail.com>
This commit is contained in:
Philip Laine
2026-05-13 12:54:52 +02:00
committed by GitHub
parent 227618aabf
commit c56f8de162
2 changed files with 60 additions and 55 deletions
+3
View File
@@ -172,6 +172,9 @@ func (d *PodNetbirdInjector) Default(ctx context.Context, pod *corev1.Pod) error
return fmt.Errorf("unknown injection mode %s", sidecarProfile.Spec.InjectionMode)
}
if pod.Annotations == nil {
pod.Annotations = map[string]string{}
}
pod.Annotations[SidecarProfileAnnotation] = sidecarProfile.Name
return nil