Skip to content

Commit

Permalink
first approach for removing sidecar when deploy annotation is set to …
Browse files Browse the repository at this point in the history
…false

Signed-off-by: marcofz <[email protected]>
  • Loading branch information
mfz85 committed Jul 10, 2021
1 parent 391f398 commit eaa204d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/controller/deployment/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deployment

import (
"context"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
Expand Down Expand Up @@ -165,6 +166,27 @@ func (r *ReconcileDeployment) Reconcile(request reconcile.Request) (reconcile.Re
msg := "no suitable Jaeger instances found to inject a sidecar"
span.AddEvent(msg)
logger.Debug(msg)
hasAgent, _ := inject.HasJaegerAgent(dep)
annotationValue, hasDepAnnotation := dep.Annotations[inject.Annotation]
// If deployment has the annotation with false value and has an hasAgent, we need to clean it.
if hasAgent && hasDepAnnotation && strings.EqualFold(annotationValue, "false") {
jaegerInstance, hasLabel := dep.Labels[inject.Label]
if hasLabel {
log.WithFields(log.Fields{
"deployment": dep.Name,
"namespace": dep.Namespace,
"jaeger": jaegerInstance,
}).Info("Removing Jaeger Agent sidecar")
patch := client.MergeFrom(dep.DeepCopy())
inject.CleanSidecar(jaegerInstance, dep)
if err := r.client.Patch(ctx, dep, patch); err != nil {
log.WithFields(log.Fields{
"deploymentName": dep.Name,
"deploymentNamespace": dep.Namespace,
}).WithError(err).Error("error cleaning orphaned deployment")
}
}
}
}

return reconcile.Result{}, nil
Expand Down

0 comments on commit eaa204d

Please sign in to comment.