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

Avoid conflicts when deployed by ArgoCD #147

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

harmathy
Copy link
Contributor

@harmathy harmathy commented Oct 9, 2024

This change introduces a black list for labels like the one already existing for metadata.

The list contains one entry for the prefix "app.kubernetes.io". The label "app.kubernetes.io/instance" is per default used by ArgoCD to track resources, which causes copied Secrets to be potentially deleted again by ArgoCD. Also labels with prefix "app.kubernetes.io" are in general very specific to the resources in their respective namespace and therefore shouldn't probably be automatically copied to resources in other namespaces anyway.

In order to avoid code duplication the filtering is delegated to an embedded function filter_dict.

closes #146

Copy link

@mihaigalos mihaigalos left a comment

Choose a reason for hiding this comment

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

Nice work. Remember to also add unit tests for this logic.

return V1ObjectMeta(
name=name,
namespace=namespace,
annotations=_annotations,
labels=_labels,
annotations=dict(_annotations),
Copy link

@mihaigalos mihaigalos Oct 11, 2024

Choose a reason for hiding this comment

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

filter_dict already returns a dict, no need for a typecast. Or?

Suggested change
annotations=dict(_annotations),
annotations=_annotations,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, actually it returns a generator object, which has to be unfolded into a dict before passing to V1ObjectMeta constructor. The type annotation of filter_dict is wrong. Nice catch! I'll fix that!

Choose a reason for hiding this comment

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

Yes, of course. Makes sense.
I see you corrected the logic.

Any chance you can add some u-tests as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mihaigalos working on it

@harmathy harmathy force-pushed the do-not-copy-app.kubernetes.io-labels branch from d3831a6 to 1c5ce10 Compare October 11, 2024 08:06
This change introduces a black list for labels like the one already
existing for metadata.

The list contains one entry for the prefix "app.kubernetes.io". The
label "app.kubernetes.io/instance" is per default used by ArgoCD to
track resources, which causes copied Secrets to be potentially deleted
again by ArgoCD. Also labels with prefix "app.kubernetes.io" are in
general very specific to the resources in their respective namespace and
therefore shouldn't probably be automatically copied to resources in
other namespaces anyway.

In order to avoid code duplication the filtering is delegated to an
embedded function filter_dict.

Signed-off-by: Max Harmathy <[email protected]>
@harmathy harmathy force-pushed the do-not-copy-app.kubernetes.io-labels branch from 1c5ce10 to 60d5abc Compare October 11, 2024 08:31
This tests the create_secret_metadata function against some combinations
of annotations and labels.

Signed-off-by: Max Harmathy <[email protected]>
@harmathy harmathy force-pushed the do-not-copy-app.kubernetes.io-labels branch from a22358e to 2330b7d Compare October 11, 2024 16:14
@zakkg3 zakkg3 self-assigned this Oct 11, 2024
Copy link
Owner

@zakkg3 zakkg3 left a comment

Choose a reason for hiding this comment

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

LGTM

@zakkg3 zakkg3 merged commit af0c823 into zakkg3:master Oct 11, 2024
11 checks passed
@greut greut mentioned this pull request Nov 11, 2024
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.

Deploying a ClusterSecret with ArgoCD result in copied Secrets being OutOfSync
3 participants