Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: cannot access local variable 'dest_folder' where it is not associated with a value - 1.22 #268

Closed
mkjmdski opened this issue Apr 3, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@mkjmdski
Copy link

mkjmdski commented Apr 3, 2023

While upgrading image version on helm deployment of grafana (this specific value -> https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml#L774), with given config:

        sidecar:
          image:
            repository: quay.io/kiwigrid/k8s-sidecar
            tag: 1.22.4

          resources:
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 100m
              memory: 128Mi

          dashboards:
            # use when upgrading version of sidecar to spot issues
            # logLevel: DEBUG
            enabled: true
            label: grafana_dashboard
            folderAnnotation: grafana_dashboard_dir
            provider:
              foldersFromFilesStructure: true

          datasources:
            # use when upgrading version of sidecar to spot issues
            # logLevel: DEBUG
            enabled: true
            label: grafana_datasource
            skipReload: true
            initDatasources: true

last working value was: 1.19.2. Probably it's regression from 1.22 -> #231

anonymized stacktrace from DEBUG log of init-container grafana-init-sc-datasources. All of our datasources are secretes configured via ExternalSecret in extraObjects: key. They all contain k8s-sidecar-target-directory: "." annotation.

{"time": "2023-04-03T14:24:50.726994+00:00", "msg": "Working on secret: default/grafana-datasource", "level": "DEBUG"}
{"time": "2023-04-03T14:24:50.727101+00:00", "msg": "Found a folder override annotation, placing the grafana-datasource in: /etc/grafana/provisioning/datasources/.", "level": "INFO"}
{"time": "2023-04-03T14:24:50.727705+00:00", "msg": "Writing azure.yaml", "level": "DEBUG"}
{"time": "2023-04-03T14:24:50.727894+00:00", "msg": "Contents of azure.yaml haven't changed. Not overwriting existing file", "level": "DEBUG"}
... x 7 for all of the secrets
{"time": "2023-04-03T14:24:50.820574+00:00", "msg": "response body: {\"kind\":\"ConfigMapList\",\"apiVersion\":\"v1\",\"metadata\":{\"resourceVersion\":\"586142921\"},\"items\":[]}\n", "level": "DEBUG"}
Traceback (most recent call last):
  File "/app/sidecar.py", line 155, in <module>
    main()
  File "/app/sidecar.py", line 113, in main
    list_resources(label, label_value, target_folder, request_url, request_method, request_payload,
  File "/app/resources.py", line 128, in list_resources
    files_changed |= _process_config_map(dest_folder, item, resource, unique_filenames, enable_5xx, True)
                                         ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'dest_folder' where it is not associated with a value

cc: @AvihaiSam

@bartoszcisek
Copy link

Screenshot 2023-04-03 at 18 14 08

This looks like a good candidate.

@jekkel
Copy link
Member

jekkel commented Apr 3, 2023

Thanks for the report! Since you seem to have found the issue already, any chance you could provide the fix as well?

@mkjmdski
Copy link
Author

mkjmdski commented Apr 4, 2023

Hi @jekkel I don't feel like I have capacity at the moment to provide a fix. I hope someone else could pick this issue. I will have time later to look into that but that might not happen so soon.

@jekkel jekkel added the bug Something isn't working label Apr 12, 2023
@mario-steinhoff-gcx
Copy link
Contributor

Hey, I fixed this in my local branch, PR will follow shortly.

mario-steinhoff-gcx added a commit to mario-steinhoff-gcx/k8s-sidecar that referenced this issue May 17, 2023
we could use _get_destination_folder here but when is_removed is set to
True, dest_folder is not used

fixes kiwigrid#268
@jekkel jekkel closed this as completed in 52249ed May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants