Skip to content

Commit

Permalink
Improve migration n new runtimeinspection (#2222)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirdavid1 authored Jan 14, 2025
1 parent e67e5d6 commit cef91ec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
30 changes: 24 additions & 6 deletions instrumentor/runtimemigration/runtimemigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func (m *MigrationRunnable) fetchAndProcessStatefulSets(ctx context.Context, kub
}

workloadInstrumentationConfigReference := workloadNames[sts.Name]
if workloadInstrumentationConfigReference == nil {
m.Logger.Error(err, "Failed to get InstrumentationConfig reference")
continue
}

// Fetching the latest state of the InstrumentationConfig resource from the Kubernetes API.
// This is necessary to ensure we work with the most up-to-date version of the resource, as it may
Expand Down Expand Up @@ -206,9 +210,6 @@ func (m *MigrationRunnable) fetchAndProcessStatefulSets(ctx context.Context, kub
}
}

// Update runtimeDetailsByContainer in workloadInstrumentationConfigReference
workloadInstrumentationConfigReference.Status.RuntimeDetailsByContainer = runtimeDetailsByContainer

// Update the InstrumentationConfig status
err = kubeClient.Status().Update(
ctx,
Expand Down Expand Up @@ -242,6 +243,10 @@ func (m *MigrationRunnable) fetchAndProcessDaemonSets(ctx context.Context, kubeC
continue
}
workloadInstrumentationConfigReference := workloadNames[ds.Name]
if workloadInstrumentationConfigReference == nil {
m.Logger.Error(err, "Failed to get InstrumentationConfig reference")
continue
}

// Fetching the latest state of the InstrumentationConfig resource from the Kubernetes API.
// This is necessary to ensure we work with the most up-to-date version of the resource, as it may
Expand Down Expand Up @@ -269,9 +274,6 @@ func (m *MigrationRunnable) fetchAndProcessDaemonSets(ctx context.Context, kubeC
}
}

// Update runtimeDetailsByContainer in workloadInstrumentationConfigReference
workloadInstrumentationConfigReference.Status.RuntimeDetailsByContainer = runtimeDetailsByContainer

// Update the InstrumentationConfig status
err = kubeClient.Status().Update(
ctx,
Expand Down Expand Up @@ -300,6 +302,22 @@ func handleContainerRuntimeDetailsUpdate(
}
// Skip if the container has already been processed
if containerRuntimeDetails.RuntimeUpdateState != nil {

// Determine if cleanup of Odigos values is needed in EnvFromContainerRuntime.
// This addresses a bug in the runtime inspection for environment variables originating from the device.
if *containerRuntimeDetails.RuntimeUpdateState == v1alpha1.ProcessingStateSucceeded {
filteredEnvVars := []v1alpha1.EnvVar{}

for _, envVar := range containerRuntimeDetails.EnvFromContainerRuntime {
if strings.Contains(envVar.Value, "/var/odigos") {
// Skip the entry
continue
}
// Keep the entry
filteredEnvVars = append(filteredEnvVars, envVar)
}
containerRuntimeDetails.EnvFromContainerRuntime = filteredEnvVars
}
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions k8sutils/pkg/cri/criwrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ func (rc *CriClient) GetContainerEnvVarsList(ctx context.Context, envVarKeys []s
result := make([]odigosv1.EnvVar, 0, len(envVarKeys))
for _, key := range envVarKeys {
if value, exists := envVars[key]; exists {
// If the environment variable originates from the device, it will still be observed in the CRI.
// In this case, it should not be set as envFromContainerRuntime.
// We can be certain that it is not coming from the manifest, as CRI is only queried when the variable is not found in the manifest.
if strings.Contains(value, "/var/odigos") {
continue
}
result = append(result, odigosv1.EnvVar{Name: key, Value: value})
}
}
Expand Down

0 comments on commit cef91ec

Please sign in to comment.