Skip to content

Commit

Permalink
Fix env vars uninstall (#1372)
Browse files Browse the repository at this point in the history
  • Loading branch information
edeNFed authored Jul 21, 2024
1 parent 5b1a7c4 commit 7bd1521
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
27 changes: 15 additions & 12 deletions instrumentor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ func main() {
newDep := &appsv1.Deployment{
TypeMeta: deployment.TypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: deployment.Name,
Namespace: deployment.Namespace,
Labels: deployment.Labels,
UID: deployment.UID,
Name: deployment.Name,
Namespace: deployment.Namespace,
Labels: deployment.Labels,
Annotations: deployment.Annotations,
UID: deployment.UID,
},
Status: deployment.Status,
}
Expand All @@ -134,10 +135,11 @@ func main() {
newSs := &appsv1.StatefulSet{
TypeMeta: ss.TypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: ss.Name,
Namespace: ss.Namespace,
Labels: ss.Labels,
UID: ss.UID,
Name: ss.Name,
Namespace: ss.Namespace,
Labels: ss.Labels,
Annotations: ss.Annotations,
UID: ss.UID,
},
Status: ss.Status,
}
Expand All @@ -152,10 +154,11 @@ func main() {
newDs := &appsv1.DaemonSet{
TypeMeta: ds.TypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: ds.Name,
Namespace: ds.Namespace,
Labels: ds.Labels,
UID: ds.UID,
Name: ds.Name,
Namespace: ds.Namespace,
Labels: ds.Labels,
Annotations: ds.Annotations,
UID: ds.UID,
},
Status: ds.Status,
}
Expand Down
4 changes: 4 additions & 0 deletions odiglet/pkg/kube/instrumentation_ebpf/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (p *PodsReconciler) getPodWorkloadObject(ctx context.Context, pod *corev1.P
for _, owner := range pod.OwnerReferences {
name, kind, err := kubeutils.GetWorkloadNameFromOwnerReference(owner)
if err != nil {
if kubeutils.IsErrorKindNotSupported(err) {
return nil, nil
}

return nil, err
}

Expand Down
6 changes: 4 additions & 2 deletions odiglet/pkg/kube/runtime_details/inspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ func runtimeInspection(pods []corev1.Pod, ignoredContainers []string) ([]odigosv
if inspectProc == nil {
log.Logger.V(0).Info("unable to detect language for any process", "pod", pod.Name, "container", container.Name, "namespace", pod.Namespace)
lang = common.UnknownProgrammingLanguage
} else if len(processes) > 1 {
log.Logger.V(0).Info("multiple processes found in pod container, only taking the first one with detected language into account", "pod", pod.Name, "container", container.Name, "namespace", pod.Namespace)
} else {
if len(processes) > 1 {
log.Logger.V(0).Info("multiple processes found in pod container, only taking the first one with detected language into account", "pod", pod.Name, "container", container.Name, "namespace", pod.Namespace)
}
// Convert map to slice for k8s format
envs = make([]odigosv1.EnvVar, 0, len(inspectProc.Envs))
for envName, envValue := range inspectProc.Envs {
Expand Down
4 changes: 4 additions & 0 deletions odiglet/pkg/kube/runtime_details/instconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (i *InstrumentationConfigReconciler) Reconcile(ctx context.Context, request
}

workload, labels, err := getWorkloadAndLabelsfromOwner(ctx, i.Client, instConfig.Namespace, instConfig.OwnerReferences[0])
if err != nil {
logger.Error(err, "Failed to get workload and labels from owner")
return reconcile.Result{}, err
}
err = inspectRuntimesOfRunningPods(ctx, &logger, labels, i.Client, i.Scheme, workload)
if err != nil {
return reconcile.Result{}, ignoreNoPodsFoundError(err)
Expand Down
9 changes: 7 additions & 2 deletions odiglet/pkg/kube/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"context"
"errors"
"fmt"
"strings"

odigosclientset "github.com/odigos-io/odigos/api/generated/odigos/clientset/versioned"
Expand All @@ -17,6 +16,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

var errKindNotSupported = errors.New("kind not supported")

func IsErrorKindNotSupported(err error) bool {
return err == errKindNotSupported
}

func IsPodInCurrentNode(pod *corev1.Pod) bool {
return pod.Spec.NodeName == env.Current.NodeName
}
Expand Down Expand Up @@ -81,5 +86,5 @@ func GetWorkloadNameFromOwnerReference(ownerReference metav1.OwnerReference) (st
} else if kind == "DaemonSet" || kind == "Deployment" || kind == "StatefulSet" {
return name, kind, nil
}
return "", "", fmt.Errorf("kind %s not supported", kind)
return "", "", errKindNotSupported
}

0 comments on commit 7bd1521

Please sign in to comment.