kiwigrid / k8s-sidecar

This is a docker container intended to run inside a kubernetes cluster to collect config maps with a specified label and store the included files in a local folder.
MIT License
612 stars 183 forks source link

UnboundLocalError: cannot access local variable 'dest_folder' #254

Closed whiskeysierra closed 1 year ago

whiskeysierra commented 1 year ago

We've been experiencing this issue with Grafana which uses the k8s-sidecar:1.22.2:

│ grafana-sc-notifiers Traceback (most recent call last):                                                                                                                                                  │
│ grafana-sc-notifiers   File "/app/sidecar.py", line 155, in <module>                                                                                                                                     │
│ grafana-sc-notifiers     main()                                                                                                                                                                          │
│ grafana-sc-notifiers   File "/app/sidecar.py", line 113, in main                                                                                                                                         │
│ grafana-sc-notifiers     list_resources(label, label_value, target_folder, request_url, request_method, request_payload,                                                                                 │
│ grafana-sc-notifiers   File "/app/resources.py", line 128, in list_resources                                                                                                                             │
│ grafana-sc-notifiers     files_changed |= _process_config_map(dest_folder, item, resource, unique_filenames, enable_5xx, True)                                                                           │
│ grafana-sc-notifiers                                          ^^^^^^^^^^^                                                                                                                                │
│ grafana-sc-notifiers UnboundLocalError: cannot access local variable 'dest_folder' where it is not associated with a value

I traced it back to this chunk of code:

https://github.com/kiwigrid/k8s-sidecar/blob/af576118a23292302d727948ba4e546e9b92adad/src/resources.py#L99-L130

The scond loop uses a local variable dest_folder which is only set in the first loop. I guess there is some kind of situation where the first loop isn't being executed at all but the second one is.

jekkel commented 1 year ago

Could you maybe share (anonymized) config map, sidecar config and enabled debug logs?

whiskeysierra commented 1 year ago

Nevermind, we temporary used this sidecar because the one grafana uses didn't work. Now we updated grafana to the latest version and forgot to switch back. I'm pretty sure we configured this sidecar incorrectly (based on the docs of the other one), hence it didn't work as intended.

whiskeysierra commented 1 year ago

Maybe I confused the two, I just learned from my colleague... 🤦‍♂️

whiskeysierra commented 1 year ago

Yeah, sorry about the confusion:

https://github.com/grafana/helm-charts/blob/bf834bfa74e4f00d41e6de8acec258eefa2b35f9/charts/grafana/values.yaml#L762-L767

We're in the process of updating. Let me get back to you if this issue persists. Again, sorry for the noise.

jekkel commented 1 year ago

So for now the issue can be closed...?