Skip to content

Commit

Permalink
fix: overwrite in case odigos update values
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirdavid1 committed Dec 22, 2024
1 parent 41a0d4e commit 36757f0
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,25 @@ func handleContainerRuntimeDetailsUpdate(
annotationEnvVarsForContainer := originalWorkloadEnvVar.GetContainerStoredEnvs(containerObject.Name)
for envKey, envValue := range annotationEnvVarsForContainer {
isEnvVarAlreadyExists := isEnvVarPresent(containerRuntimeDetails.EnvVarsFromDockerFile, envKey)
// The runtimeDetails might already contain the environment variable if Odiglet started before the migration was executed and modified the env vars.
// In this case, we want to overwrite the value set by Odiglet with a new one.
if isEnvVarAlreadyExists {
continue
containerRuntimeDetails.EnvVarsFromDockerFile = removeEnvVar(containerRuntimeDetails.EnvVarsFromDockerFile, envKey)
}

// Handle runtime-originated environment variables
if envValue == nil {
containerEnvFromManifestValue := k8scontainer.GetContainerEnvVarValue(&containerObject, envKey)
if containerEnvFromManifestValue != nil {
workloadEnvVarWithoutOdigosAdditions := cleanUpManifestValueFromOdigosAdditions(envKey, *containerEnvFromManifestValue)
envVarWithoutOdigosAddition := v1alpha1.EnvVar{Name: envKey, Value: workloadEnvVarWithoutOdigosAdditions}
containerRuntimeDetails.EnvVarsFromDockerFile = append(containerRuntimeDetails.EnvVarsFromDockerFile, envVarWithoutOdigosAddition)
state := v1alpha1.ProcessingStateSucceeded
containerRuntimeDetails.RuntimeUpdateState = &state

if workloadEnvVarWithoutOdigosAdditions != "" {
envVarWithoutOdigosAddition := v1alpha1.EnvVar{Name: envKey, Value: workloadEnvVarWithoutOdigosAdditions}
containerRuntimeDetails.EnvVarsFromDockerFile = append(containerRuntimeDetails.EnvVarsFromDockerFile, envVarWithoutOdigosAddition)
state := v1alpha1.ProcessingStateSucceeded
containerRuntimeDetails.RuntimeUpdateState = &state
}

}
}
}
Expand Down Expand Up @@ -294,3 +300,13 @@ func isEnvVarPresent(envVars []v1alpha1.EnvVar, envVarName string) bool {
}
return false
}

func removeEnvVar(envVars []v1alpha1.EnvVar, key string) []v1alpha1.EnvVar {
filteredEnvVars := []v1alpha1.EnvVar{}
for _, envVar := range envVars {
if envVar.Name != key {
filteredEnvVars = append(filteredEnvVars, envVar)
}
}
return filteredEnvVars
}

0 comments on commit 36757f0

Please sign in to comment.