-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: migrate ebpf manager from device to distro name env #2401
Changes from all commits
b2e7b97
7ab0839
4d07f64
b7bba94
f6597c5
e8632bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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{}{} | ||
} |
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, | ||
}, | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,34 @@ var ( | |
ErrContainerNotInPodSpec = errors.New("container not found in pod spec") | ||
) | ||
|
||
func LanguageAndSdk(pod *v1.Pod, containerName string, distroName string) (common.ProgrammingLanguage, common.OtelSdk, error) { | ||
if distroName != "" { | ||
// TODO: so we can remove the device slowly while having backward compatibility, | ||
// we map here the distroNames one by one. | ||
// this is temporary, and should be refactored once device is removed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aside from removing the device fallback, is there another refactor needed here in the future? I assume the plan is to not have language and sdk in the futrure just use the distro name, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes exactly |
||
switch distroName { | ||
case "golang-community": | ||
return common.GoProgrammingLanguage, common.OtelSdkEbpfCommunity, nil | ||
case "golang-enterprise": | ||
return common.GoProgrammingLanguage, common.OtelSdkEbpfEnterprise, nil | ||
case "java-enterprise": | ||
return common.JavaProgrammingLanguage, common.OtelSdkNativeEnterprise, nil | ||
case "java-ebpf-instrumentations": | ||
return common.JavaProgrammingLanguage, common.OtelSdkEbpfEnterprise, nil | ||
case "python-enterprise": | ||
return common.PythonProgrammingLanguage, common.OtelSdkEbpfEnterprise, nil | ||
case "nodejs-enterprise": | ||
return common.JavascriptProgrammingLanguage, common.OtelSdkEbpfEnterprise, nil | ||
case "mysql-enterprise": | ||
return common.MySQLProgrammingLanguage, common.OtelSdkEbpfEnterprise, nil | ||
} | ||
} | ||
|
||
// TODO: this is fallback for migration from device (so that we can handle pods that have not been updated yet) | ||
// remove this once device is removed | ||
return LanguageSdkFromPodContainer(pod, containerName) | ||
} | ||
|
||
func LanguageSdkFromPodContainer(pod *v1.Pod, containerName string) (common.ProgrammingLanguage, common.OtelSdk, error) { | ||
for i := range pod.Spec.Containers { | ||
container := pod.Spec.Containers[i] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have `instrumentor/internal/webhook_env_injector"
I agree that they operate on different kinds of env vars, but I think those logics should be in the same package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I refactor this part, I intend to move the functions to the controller, similar to how it's done in the rollout directory