Find the way to add ingress annotations to nginx logs

Good day!

We have a large multi-tenant cluster with more than 200 namespaces in it.
We collect logs using a filebeat, which has recently supported receiving annotations from a namespace. This allows us to split the logs by teams.
However, this mechanism does not work for logs from the ingress controller.

The idea is to use a “simple” trick with mutating webhook to transfer annotations from ns to ingress and then from ingress to controller logs.

Tell me, is there a way to have these annotations from ingress in the logs of the ingress controller without rewriting the controller?

Ok, I’ll answer it myself.

  1. Edit the nginx template so that the annotation from ingress gets to the log.
  2. Write a mutation webhook that copies the annotation from the namespace to ingress.