Skip to content

Commit

Permalink
fixup! fixup! feat: allow to customize the blocked labels
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <[email protected]>
  • Loading branch information
greut committed Nov 12, 2024
1 parent c86da2a commit 060a3a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ def get_replace_existing() -> bool:

@cache
def get_blocked_labels() -> list[str]:
blocked_labels = os.getenv('BLOCKED_LABELS', ','.join(BLOCKED_LABELS))
return [label.strip() for label in blocked_labels.split(',')]
blocked_labels = os.getenv('BLOCKED_LABELS')

if not blocked_labels:
return BLOCKED_LABELS

return [label.strip() for label in blocked_labels.split(',')]

@cache
def in_cluster() -> bool:
Expand Down
8 changes: 4 additions & 4 deletions src/tests/test_kubernetes_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_create_secret_metadata(self) -> None:
(LAST_SYNC_ANNOTATION, is_iso_format)
]

attributes_black_lists = dict(
attributes_blocked_lists = dict(
labels=get_blocked_labels(),
annotations=BLOCKED_ANNOTATIONS,
)
Expand Down Expand Up @@ -140,15 +140,15 @@ def test_create_secret_metadata(self) -> None:

self.assertIsInstance(obj=subject, cls=V1ObjectMeta, msg='returned value has correct type')

for attribute, black_list in attributes_black_lists.items():
for attribute, blocked_list in attributes_blocked_lists.items():
attribute_object = subject.__getattribute__(attribute)
self.assertIsNotNone(obj=attribute_object, msg=f'attribute "{attribute}" is not None')

for key in attribute_object.keys():
self.assertIsInstance(obj=key, cls=str, msg=f'the {attribute} key is a string')
for black_listed_label_prefix in black_list:
for blocked_listed_label_prefix in blocked_list:
self.assertFalse(
expr=key.startswith(black_listed_label_prefix),
expr=key.startswith(blocked_listed_label_prefix),
msg=f'{attribute} key does not match black listed prefix'
)

Expand Down

0 comments on commit 060a3a2

Please sign in to comment.