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

fix: checking and deleting secrets without annotations and labels #509

Merged
merged 2 commits into from
Jan 14, 2021

Conversation

olevski
Copy link
Member

@olevski olevski commented Jan 13, 2021

I noticed that the cull image pull secrets jobs were failing with the following message.

INFO:root:Checking for user registry secrets whose names match the regex: .+-registry-[a-z0-9-]{36}$
Traceback (most recent call last):
  File "/cull_secrets/clean_user_registry_secrets.py", line 187, in <module>
    main()
  File "/cull_secrets/clean_user_registry_secrets.py", line 183, in main
    remove_user_registry_secret(args.namespace, k8s_client, args.age_hours_minimum)
  File "/cull_secrets/clean_user_registry_secrets.py", line 112, in remove_user_registry_secret
    for annotation_key in POD_ANNOTATIONS
  File "/cull_secrets/clean_user_registry_secrets.py", line 112, in <listcomp>
    for annotation_key in POD_ANNOTATIONS
AttributeError: 'NoneType' object has no attribute 'keys'

The problem is occurring because for any secret that has no annotations or labels the python k8s client returns None instead of an empty dictionary. But when annotations are present then secret.metadata.annotations are a dictionary of the annotation names and their values. The same occurs with the labels.

This problem occurred only on dev because there we had some old image pull registry secrets that did not have any annotations and/or labels and were causing this failure. In my testing environment I never had such a secret. This corrects the problem.

I confirmed I can trigger the error by making a specific secret that passes some of the initial conditions of the if statement that was changed here but without annotations. Also I tested to make sure that with this change the error does not occur anymore.

@olevski olevski requested a review from a team as a code owner January 13, 2021 19:54
Copy link
Contributor

@pameladelgado pameladelgado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, missing annotations or labels wont cause an error 👍
We would still need to clean up the old image pull secrets. We have some of these in production (with labels but no annotations).

@olevski olevski merged commit bfbb148 into master Jan 14, 2021
@olevski olevski deleted the fix-deleting-imagepull-secret-with-empty-label branch January 14, 2021 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants