-
Notifications
You must be signed in to change notification settings - Fork 207
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
base: main
Are you sure you want to change the base?
feat: webhook to set agent injection env var with odigos additions #2107
Conversation
@@ -52,6 +53,15 @@ type InstrumentationConfigStatus struct { | |||
RuntimeDetailsByContainer []RuntimeDetailsByContainer `json:"runtimeDetailsByContainer,omitempty"` | |||
} | |||
|
|||
func (in *InstrumentationConfigStatus) GetRuntimeDetailsForContainer(container v1.Container) *RuntimeDetailsByContainer { |
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 usually host these sort of functions in k8sutils
. WDYT?
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 we discussed let's discuss on this with @RonFed and take decision here
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.
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 { |
instrumentor/internal/webhook_env_injector/webhook_env_injector.go
Outdated
Show resolved
Hide resolved
instrumentor/internal/webhook_env_injector/webhook_env_injector.go
Outdated
Show resolved
Hide resolved
instrumentor/internal/webhook_env_injector/webhook_env_injector.go
Outdated
Show resolved
Hide resolved
instrumentor/internal/webhook_env_injector/webhook_env_injector.go
Outdated
Show resolved
Hide resolved
instrumentor/internal/webhook_env_injector/webhook_env_injector.go
Outdated
Show resolved
Hide resolved
instrumentor/internal/webhook_env_injector/webhook_env_injector.go
Outdated
Show resolved
Hide resolved
instrumentor/internal/webhook_env_injector/webhook_env_injector.go
Outdated
Show resolved
Hide resolved
67512da
to
d5924cc
Compare
@@ -52,6 +53,15 @@ type InstrumentationConfigStatus struct { | |||
RuntimeDetailsByContainer []RuntimeDetailsByContainer `json:"runtimeDetailsByContainer,omitempty"` | |||
} | |||
|
|||
func (in *InstrumentationConfigStatus) GetRuntimeDetailsForContainer(container v1.Container) *RuntimeDetailsByContainer { |
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.
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 { |
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.
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 { |
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 | ||
} | ||
} |
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.
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
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.