func updateContainerEnv()

in appconfigmgrv2/api/webhooks/builtins/pod_webhook.go [203:244]


func updateContainerEnv(container *corev1.Container, containerName string, envName string, mountPath string) {
	log.V(1).Info("updateContainerEnv",
		"containerName", containerName,
		"envName", envName,
		"mountPath", mountPath,
	)
	found := false
	index := -1
	for i, element := range container.Env {
		if element.Name == envName {
			found = true
			index = i
			log.V(1).Info("updateContainerEnv:found",
				"containerName", containerName,
				"envName", envName,
				"mountPath", mountPath,
			)
		}
	}
	element := &corev1.EnvVar{
		Name:  envName,
		Value: mountPath,
	}

	if !found {
		// Append The Mount
		log.V(1).Info("updateContainerEnv:addMount",
			"containerName", containerName,
			"envName", envName,
			"mountPath", mountPath,
		)
		index = len(container.Env)
		container.Env = append(container.Env, *element)
	} else {
		container.Env[index] = *element
	}

	log.V(1).Info("updateContainerEnv:exit",
		"containerInfo", container,
	)

}