From de210c0518922ec73cbc4c23cdfe19033ce8dd6b Mon Sep 17 00:00:00 2001 From: Avihu Hanya <34632558+AvihuHenya@users.noreply.github.com> Date: Tue, 4 Feb 2025 13:35:29 +0200 Subject: [PATCH] removal of inject instrumentation label when uninstall using cli (#2341) --- cli/cmd/uninstall.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/cli/cmd/uninstall.go b/cli/cmd/uninstall.go index 5a351f86a7..ce7df17856 100644 --- a/cli/cmd/uninstall.go +++ b/cli/cmd/uninstall.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/odigos-io/odigos/api/k8sconsts" "github.com/odigos-io/odigos/common/envOverwrite" "github.com/odigos-io/odigos/k8sutils/pkg/envoverwrite" @@ -150,9 +151,11 @@ func rollbackPodChanges(ctx context.Context, client *kube.Client) error { errs = multierr.Append(errs, err) continue } - _, err = client.AppsV1().Deployments(dep.Namespace).Patch(ctx, dep.Name, types.JSONPatchType, jsonPatchPayloadBytes, metav1.PatchOptions{}) - if err != nil { - errs = multierr.Append(errs, err) + if len(jsonPatchPayloadBytes) > 0 { + _, err = client.AppsV1().Deployments(dep.Namespace).Patch(ctx, dep.Name, types.JSONPatchType, jsonPatchPayloadBytes, metav1.PatchOptions{}) + if err != nil { + errs = multierr.Append(errs, err) + } } } @@ -166,9 +169,11 @@ func rollbackPodChanges(ctx context.Context, client *kube.Client) error { errs = multierr.Append(errs, err) continue } - _, err = client.AppsV1().StatefulSets(s.Namespace).Patch(ctx, s.Name, types.JSONPatchType, jsonPatchPayloadBytes, metav1.PatchOptions{}) - if err != nil { - errs = multierr.Append(errs, err) + if len(jsonPatchPayloadBytes) > 0 { + _, err = client.AppsV1().StatefulSets(s.Namespace).Patch(ctx, s.Name, types.JSONPatchType, jsonPatchPayloadBytes, metav1.PatchOptions{}) + if err != nil { + errs = multierr.Append(errs, err) + } } } @@ -182,9 +187,11 @@ func rollbackPodChanges(ctx context.Context, client *kube.Client) error { errs = multierr.Append(errs, err) continue } - _, err = client.AppsV1().DaemonSets(d.Namespace).Patch(ctx, d.Name, types.JSONPatchType, jsonPatchPayloadBytes, metav1.PatchOptions{}) - if err != nil { - errs = multierr.Append(errs, err) + if len(jsonPatchPayloadBytes) > 0 { + _, err = client.AppsV1().DaemonSets(d.Namespace).Patch(ctx, d.Name, types.JSONPatchType, jsonPatchPayloadBytes, metav1.PatchOptions{}) + if err != nil { + errs = multierr.Append(errs, err) + } } } @@ -209,6 +216,12 @@ func getWorkloadRolloutJsonPatch(obj kube.Object, pts *v1.PodTemplateSpec) ([]by }) } } + if _, found := pts.ObjectMeta.Labels[k8sconsts.OdigosInjectInstrumentationLabel]; found { + patchOperations = append(patchOperations, map[string]interface{}{ + "op": "remove", + "path": "/spec/template/metadata/labels/" + jsonPatchEscapeKey(k8sconsts.OdigosInjectInstrumentationLabel), + }) + } // remove odigos reported name annotation if obj.GetAnnotations() != nil {