Skip to content
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

feat: webhook to set agent injection env var with odigos additions #2107

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

tamirdavid1
Copy link
Collaborator

@tamirdavid1 tamirdavid1 commented Dec 31, 2024

This is the initial phase of enabling the webhook to set agent injection-related environment variables (e.g., PYTHONPATH). The plan is to merge this after the migration and the new runtime inspection have been running for a while.

Once enough time has passed, I will merge this change to handle simpler cases where the envOverwriter is not involved. After this phase runs for a sufficient period, we can fully remove the envOverwriter and rely solely on this logic.

Finally, we can clean up the remaining code related to the envOverwriter.

@@ -52,6 +53,15 @@ type InstrumentationConfigStatus struct {
RuntimeDetailsByContainer []RuntimeDetailsByContainer `json:"runtimeDetailsByContainer,omitempty"`
}

func (in *InstrumentationConfigStatus) GetRuntimeDetailsForContainer(container v1.Container) *RuntimeDetailsByContainer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually host these sort of functions in k8sutils. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed let's discuss on this with @RonFed and take decision here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with both options as long we don't have duplicated functions in more than one place.
It feels like we have a lot of functions like this in

func getLanguageOfContainer(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) common.ProgrammingLanguage {

func getContainerOtherAgents(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) *odigosv1.OtherAgent {

func getLibCTypeOfContainer(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) *common.LibCType {

k8sutils/pkg/container/container.go Outdated Show resolved Hide resolved
@tamirdavid1 tamirdavid1 force-pushed the inject-env-new-runtime-logic branch from 67512da to d5924cc Compare January 1, 2025 15:59
@@ -52,6 +53,15 @@ type InstrumentationConfigStatus struct {
RuntimeDetailsByContainer []RuntimeDetailsByContainer `json:"runtimeDetailsByContainer,omitempty"`
}

func (in *InstrumentationConfigStatus) GetRuntimeDetailsForContainer(container v1.Container) *RuntimeDetailsByContainer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with both options as long we don't have duplicated functions in more than one place.
It feels like we have a lot of functions like this in

func getLanguageOfContainer(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) common.ProgrammingLanguage {

func getContainerOtherAgents(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) *odigosv1.OtherAgent {

func getLibCTypeOfContainer(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) *common.LibCType {


// Return true if further processing should be skipped, either because it was already handled or due to a potential error (e.g., missing possible values)
// Return false if the env was not processed using the manifest value and requires further handling by other methods.
func handleManifestEnvVar(container *corev1.Container, envVarName string, otelsdk common.OtelSdk, logger logr.Logger) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func handleManifestEnvVar(container *corev1.Container, envVarName string, otelsdk common.OtelSdk, logger logr.Logger) bool {
func ShouldIgnoreInjection(container *corev1.Container, envVarName string, otelsdk common.OtelSdk, logger logr.Logger) bool {

Comment on lines +128 to +143
func appendOdigosAdditionsToEnvVar(envName string, observedValue string, desiredOdigosAddition string) *string {
envValues, ok := envOverwrite.EnvValuesMap[envName]
if !ok {
// Odigos does not manipulate this environment variable, so ignore it
return nil
}

// In case observedValue is exists but empty, we just need to set the desiredOdigosAddition without delim before
if strings.TrimSpace(observedValue) == "" {
return &desiredOdigosAddition
} else {
// In case observedValue is not empty, we need to append the desiredOdigosAddition with the delim
mergedEnvValue := observedValue + envValues.Delim + desiredOdigosAddition
return &mergedEnvValue
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this function should be under the overwriter.go?
That way we won't need to export the Delim and we could use that module in the future from the vm-agent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants