max-rocket-internet / k8s-event-logger

Watches k8s cluster events and logs them to stdout in JSON
GNU General Public License v3.0
211 stars 28 forks source link

Better kubernetes configuration detection based on k8s libraries #30

Closed nathanmcgarvey-modopayments closed 1 year ago

nathanmcgarvey-modopayments commented 1 year ago

Please test this locally (go run ./main.go) and in a k8s cluster both with a .kube/config with no KUBECONFIG env variable set and one with a KUBECONFIG env variable set before merging. It works for me, but I want to ensure it doesn't break anyone.

Instead of doing our own user home directory detection for .kube/config, use the k8s.io/cmdclient built-in methods which support KUBECONFIG env variable, $HOME/.kube/config, and KUBERNETES_SERVICE env variables automatically.

Also print out a sanitized representation of the config at startup in case of misconfiguration.

nathanmcgarvey-modopayments commented 1 year ago

Now that I'm looking at it, why are these variables being set in the helm chart?

-  KUBERNETES_API_URL: https://172.20.0.1:443
-  CA_FILE: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt

Those should get picked up by default (I haven't tested, but it should)

Edit: at least in my local cluster, those variables are not necessary at all. Removed in the next commit.

max-rocket-internet commented 1 year ago

Those should get picked up by default (I haven't tested, but it should)

When that code was written about 4 years ago this was not the case but a lot has changed since 😅

max-rocket-internet commented 1 year ago

Edit: at least in my local cluster, those variables are not necessary at all. Removed in the next commit.

Give me a couple days and I'll test it.