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 namespaces deletion handling #159

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tr-aheiev
Copy link

This PR removes outdated code from 'on_field_data' and simplifying secrets synchronization for both types - with inline data fields and with external secrets (with 'valueFrom' field). But after removing that code we need somehow handle namespace deletion operations - for this purpose I refactored 'namespace_watcher' function. Test for namespace creation I fixed also, but for namespace removing need to create new - not sure that can handle it myself, but will try.

All current tests are passed.

@axel7083
Copy link
Collaborator

axel7083 commented Feb 5, 2025

All current tests are passed.

Following #156 some conflicts are happening, do you think you might have some time to take a look?

@tr-aheiev
Copy link
Author

tr-aheiev commented Feb 6, 2025

All current tests are passed.

Following #156 some conflicts are happening, do you think you might have some time to take a look?

Yes, sure, but I propose to finish first with #157 and then I will update this one.

@tr-aheiev tr-aheiev force-pushed the fix-namespaces-deletion-handling branch from 5465f70 to dbabc96 Compare February 8, 2025 17:16
@tr-aheiev
Copy link
Author

Hi! I updated the code. Not sure - do I need to bump Chart version each time to pass tests?

@axel7083
Copy link
Collaborator

Hi! I updated the code. Not sure - do I need to bump Chart version each time to pass tests?

Yes, I cannot change the GitHub workflows, so need to bump it to let it pass :/

@@ -116,143 +116,6 @@ def test_on_field_data_sync(self):
{"key": "newvalue"},
)

def test_on_field_data_ns_deleted(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test has been removed, could you clarify? If the changes fixes an issue, we should have a regression tests, otherwise if it is adding a new behaviour, we should ensure it works as expected

Copy link
Author

Choose a reason for hiding this comment

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

Yes, you are right. Previously 'on_field_data' function was doing little more than now, so there was additional test for it and I removed it after it changes. But now when I added new functionality into 'namespace_watcher' function, seems I need to write some additional test for it. I will try to do this today/tomorrow.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! Really appreciate!

Copy link
Author

Choose a reason for hiding this comment

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

It took me a bit more time to fully understand the root purpose of the removed test and how the other tests work.

Initially, I assumed that the handler for namespace removal would eliminate the situation that the test was checking. However, that’s not the case - it only significantly reduces the likelihood of it occurring. In kopf, handlers for different objects (such as ClusterSecret and Namespace) don’t run sequentially; they execute in parallel. This means there’s still a very small chance that when 'on_field_data' is triggered, 'namespace_watcher' might still be in progress but not fully completed.

So, it seems that this test is not entirely redundant, even now. Of course we still need an additional test for 'namespace_watcher'.

I’ll continue working on this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This tests has been written a long time ago, so I cannot help much on that, thanks you for investigating.

Copy link
Author

Choose a reason for hiding this comment

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

Hello! Sorry for the delay.

I added an additional unit test for 'namespace_watcher' to verify the correct update of ClusterSecret and its cache after a namespace deletion.

I reviewed the 'test_on_field_data_ns_deleted' test once again and have now removed it. Since our handlers use synchronous functions, they execute sequentially, ensuring that namespaces changes in status fields are processed correctly. Even if a deletion occurs during the execution of 'on_fields_avoid_or_match_namespace', I have added an extra check in 'kubernetes_utils' to handle this properly and log a debug message accordingly.

I updated the code and think that now its ready for merge.

@tr-aheiev tr-aheiev force-pushed the fix-namespaces-deletion-handling branch from b95536f to 9f08521 Compare February 22, 2025 15:59
@tr-aheiev tr-aheiev force-pushed the fix-namespaces-deletion-handling branch from 9f08521 to 014cdcf Compare February 22, 2025 21:56
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