-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate ebpf manager from device to distro name env (#2401)
As part of the effort to remove instrumentation device, this PR: - add environment variable to containers, `ODIGOS_DISTRO_NAME` to describe the name of the distro injected to the pod. - migrate ebpf manager to match distribution based on the new environment variable with fallback to device so not to break existing users. - fix missing agent directory needed in python - remove device from 4 distros that do not inject any env variables - only need the `/var/odigos` mount, or not.
- Loading branch information
Showing
10 changed files
with
147 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package podswebhook | ||
|
||
import ( | ||
"github.com/odigos-io/odigos/api/k8sconsts" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func InjectOdigosK8sEnvVars(container *corev1.Container, distroName string, ns string) { | ||
|
||
// check for existing env vars so we don't introduce them again | ||
existingEnvNames := make(map[string]struct{}) | ||
for _, envVar := range container.Env { | ||
existingEnvNames[envVar.Name] = struct{}{} | ||
} | ||
|
||
injectEnvVarToPodContainer(&existingEnvNames, container, k8sconsts.OdigosEnvVarContainerName, container.Name) | ||
injectEnvVarToPodContainer(&existingEnvNames, container, k8sconsts.OdigosEnvVarDistroName, distroName) | ||
injectEnvVarObjectFieldRefToPodContainer(&existingEnvNames, container, k8sconsts.OdigosEnvVarPodName, "metadata.name") | ||
injectEnvVarToPodContainer(&existingEnvNames, container, k8sconsts.OdigosEnvVarNamespace, ns) | ||
} | ||
|
||
func injectEnvVarObjectFieldRefToPodContainer(existingEnvNames *map[string]struct{}, container *corev1.Container, envVarName, envVarRef string) { | ||
if _, exists := (*existingEnvNames)[envVarName]; exists { | ||
return | ||
} | ||
|
||
container.Env = append(container.Env, corev1.EnvVar{ | ||
Name: envVarName, | ||
ValueFrom: &corev1.EnvVarSource{ | ||
FieldRef: &corev1.ObjectFieldSelector{ | ||
FieldPath: envVarRef, | ||
}, | ||
}, | ||
}) | ||
|
||
(*existingEnvNames)[envVarName] = struct{}{} | ||
} | ||
|
||
func injectEnvVarToPodContainer(existingEnvNames *map[string]struct{}, container *corev1.Container, envVarName, envVarValue string) { | ||
if _, exists := (*existingEnvNames)[envVarName]; exists { | ||
return | ||
} | ||
|
||
container.Env = append(container.Env, corev1.EnvVar{ | ||
Name: envVarName, | ||
Value: envVarValue, | ||
}) | ||
|
||
(*existingEnvNames)[envVarName] = struct{}{} | ||
} |
33 changes: 33 additions & 0 deletions
33
instrumentor/controllers/agentenabled/podswebhook/mount.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package podswebhook | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/odigos-io/odigos/api/k8sconsts" | ||
"github.com/odigos-io/odigos/distros/distro" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func MountDirectory(containerSpec *corev1.Container, dir string) { | ||
// TODO: assuming the directory always starts with {{ODIGOS_AGENTS_DIR}}. This should be validated. | ||
// Should we return errors here to validate static values? | ||
relativePath := strings.TrimPrefix(dir, distro.AgentPlaceholderDirectory+"/") | ||
absolutePath := strings.ReplaceAll(dir, distro.AgentPlaceholderDirectory, k8sconsts.OdigosAgentsDirectory) | ||
containerSpec.VolumeMounts = append(containerSpec.VolumeMounts, corev1.VolumeMount{ | ||
Name: k8sconsts.OdigosAgentMountVolumeName, | ||
SubPath: relativePath, | ||
MountPath: absolutePath, | ||
ReadOnly: true, | ||
}) | ||
} | ||
|
||
func MountPodVolume(pod *corev1.Pod) { | ||
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{ | ||
Name: k8sconsts.OdigosAgentMountVolumeName, | ||
VolumeSource: corev1.VolumeSource{ | ||
HostPath: &corev1.HostPathVolumeSource{ | ||
Path: k8sconsts.OdigosAgentsDirectory, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters