Remove sidecars of annotated namespaces when annotation is deleted
@@ -155,6 +155,30 @@ func (r *ReconcileNamespace) Reconcile(request reconcile.Request) (reconcile.Res
} else {
log.WithField("deployment", dep.Name).Info("No suitable Jaeger instances found to inject a sidecar")
}
+ } else {
+ // Don't need injection, may be need to remove the sidecar?
+ // If deployment don't have the annotation and has an hasAgent, this may be injected by the namespace
+ // we need to clean it.
+ hasAgent, _ := inject.HasJaegerAgent(dep)
+ _, hasDepAnnotation := dep.Annotations[inject.Annotation]
+ if hasAgent && !hasDepAnnotation {
+ 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")
+ }
+ }
+ }
}
}
