linkerd2 icon indicating copy to clipboard operation
linkerd2 copied to clipboard

Configure CNI plugin to log to a file

Open mateiidavid opened this issue 3 years ago • 0 comments

Our CNI plugin currently only logs to stderr:

https://github.com/linkerd/linkerd2/blob/d76c42010cae62863e6228d022971b98bb48a385/cni-plugin/main.go#L94-L95

CNI plugins run directly on the host, which makes it hard to access log -- and impossible to do through kubectl logs -- and operators would have to rely on reading through the kubelet log which contains a lot of verbosity.

We should dump the logs into a file (either by default or through an option) to make it easier for people to collect logs when something goes wrong. We should be consistent with other CNI implementations, such as Calico, and save logs to /var/log/linkerd-cni.

As an implementation idea, I'd consider something like:

-       logrus.SetOutput(os.Stderr)
+       f, err := os.OpenFile("/var/log/linkerd-cni", os.O_WRONLY|os.O_CREATE, 0755)
+       if err != nil {
+               panic("failed to create file")
+       }
+       logw := io.MultiWriter(os.Stderr, f)
+       logrus.SetOutput(logw)

mateiidavid avatar Jul 14 '22 17:07 mateiidavid