func sidecarContainerPresent()

in pkg/webhook/sidecar_spec.go [265:299]


func sidecarContainerPresent(containerName string, containers []corev1.Container, volumeMounts []corev1.VolumeMount) bool {
	containerInjected := false
	volumeMountMap := map[string]string{}
	for _, vm := range volumeMounts {
		volumeMountMap[vm.Name] = vm.MountPath
	}

	for _, c := range containers {
		if c.Name == containerName {
			if c.SecurityContext != nil &&
				c.SecurityContext.RunAsUser != nil &&
				c.SecurityContext.RunAsGroup != nil &&
				*c.SecurityContext.RunAsUser == NobodyUID &&
				*c.SecurityContext.RunAsGroup == NobodyGID {
				containerInjected = true
			}
			// Delete volumeMounts present from map.
			for _, vm := range c.VolumeMounts {
				if mountPath, exists := volumeMountMap[vm.Name]; exists {
					if vm.MountPath == mountPath {
						delete(volumeMountMap, vm.Name)
					}
				}
			}

			break
		}
	}

	if containerInjected && len(volumeMountMap) == 0 {
		return true
	}

	return false
}