Fix injection check for existing sidecars

This commit is contained in:
Alejandro Pedraza 2024-04-17 11:50:28 -05:00
parent 44e9625e0d
commit a8ebe76e3f
No known key found for this signature in database
2 changed files with 12 additions and 1 deletions

View File

@ -10,7 +10,8 @@ import (
// HasExistingSidecars returns true if the pod spec already has the proxy init
// and sidecar containers injected. Otherwise, it returns false.
func HasExistingSidecars(podSpec *corev1.PodSpec) bool {
for _, container := range podSpec.Containers {
containers := append(podSpec.InitContainers, podSpec.Containers...)
for _, container := range containers {
if strings.HasPrefix(container.Image, "cr.l5d.io/linkerd/proxy:") ||
strings.HasPrefix(container.Image, "gcr.io/istio-release/proxyv2:") ||
container.Name == k8s.ProxyContainerName ||

View File

@ -44,6 +44,16 @@ func TestHasExistingSidecars(t *testing.T) {
},
expected: true,
},
{
podSpec: &corev1.PodSpec{
InitContainers: []corev1.Container{
{
Name: k8s.ProxyContainerName,
},
},
},
expected: true,
},
{
podSpec: &corev1.PodSpec{
Containers: []corev1.Container{