diff --git a/instrumentor/controllers/deleteinstrumentedapplication/common.go b/instrumentor/controllers/deleteinstrumentedapplication/common.go index 0063e5fa6..5095a1550 100644 --- a/instrumentor/controllers/deleteinstrumentedapplication/common.go +++ b/instrumentor/controllers/deleteinstrumentedapplication/common.go @@ -44,7 +44,7 @@ func deleteWorkloadInstrumentedApplication(ctx context.Context, kubeClient clien ns := workloadObject.GetNamespace() name := workloadObject.GetName() - kind := workloadObject.GetObjectKind().GroupVersionKind().Kind + kind := workload.GetWorkloadKind(workloadObject) instrumentedApplicationName := workload.GetRuntimeObjectName(name, kind) err := kubeClient.Delete(ctx, &odigosv1.InstrumentedApplication{ diff --git a/k8sutils/pkg/workload/workload.go b/k8sutils/pkg/workload/workload.go index f5a4acfb6..801e69754 100644 --- a/k8sutils/pkg/workload/workload.go +++ b/k8sutils/pkg/workload/workload.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/odigos-io/odigos/common/consts" - "k8s.io/api/apps/v1" + v1 "k8s.io/api/apps/v1" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -56,7 +56,6 @@ func ObjectToWorkload(obj client.Object) (Workload, error) { } } - // runtime name is a way to store workload specific CRs with odigos // and give the k8s object a name which is unique and can be used to extract the workload name and kind func GetRuntimeObjectName(name string, kind string) string { @@ -104,3 +103,16 @@ func IsObjectLabeledForInstrumentation(obj client.Object) bool { return val == consts.InstrumentationEnabled } + +func GetWorkloadKind(w client.Object) string { + switch w.(type) { + case *v1.Deployment: + return "Deployment" + case *v1.DaemonSet: + return "Daemonset" + case *v1.StatefulSet: + return "Statefulset" + default: + return "Unknown" + } +}