Skip to content

Conversation

@erikgb
Copy link
Collaborator

@erikgb erikgb commented Aug 8, 2025

This PR will hopefully address #168, but it's a bit hard to know for sure, since I was unable to reproduce the issue in tests, even if the issue is 100% reproducible in one of our clusters. 🤔 I suggest keeping #168 open until the issue isn't reproducible in a real cluster.

This PR should be reviewed carefully, but some of the main things I have tried to address are:

  • Ensure that the finalizer is always removed from SubNamespace on finalization. I'm personally not a great fan of the goto construct, and it's even more confusing when the goto is named DELETE, which is misleading IMO.
  • Error handling: ignoring and not ignoring errors.
  • Small, but important change in the namespace event handler: ensure events for all potential owner subnamespaces when a sub-namespace is deleted (deletionTimestamp set).
  • Use a JSON Merge Patch to remove the subnamespace finalizer.
  • Reviewed and added/tuned logging.

Fixes #168
Closes #196

@erikgb erikgb force-pushed the reconcile-improvements branch from 54787e4 to 820d07e Compare August 8, 2025 20:03
@erikgb
Copy link
Collaborator Author

erikgb commented Aug 8, 2025

@ymmt2005 I would really love your review of this PR if you have time! 🙏

@erikgb erikgb force-pushed the reconcile-improvements branch 5 times, most recently from b7767e7 to 124eff1 Compare August 9, 2025 07:49
@erikgb
Copy link
Collaborator Author

erikgb commented Aug 9, 2025

I believe the failing check is a flake. Is there a way for me to retrigger the job?

@zoetrope
Copy link
Member

@erikgb
I’ve added you as an outside collaborator with Write access. Could you try rerunning the CI to see if it works?

@erikgb
Copy link
Collaborator Author

erikgb commented Aug 12, 2025

Thanks @zoetrope! I managed to re-run the failing job now.

@zoetrope zoetrope self-requested a review August 13, 2025 10:04
Namespace: parent,
Name: o.GetName(),
}})
return
Copy link
Member

Choose a reason for hiding this comment

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

I confirmed that removing this return statement resolved the issue👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice, then I will update the PR description to close the issue when this PR is merged. How do you explain the non-failing e2e-test? It is testing exactly this.

Copy link
Member

Choose a reason for hiding this comment

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

In #168, the conflicting Namespace was created as a SubNamespace, so the Namespace has a parent label.
In contrast, in the test, the Namespace is created directly and therefore doesn’t have a parent label.

As a result, it doesn’t meet the condition at the following line, and the Reconcile process for SubNamespaces is triggered.

controllerutil.RemoveFinalizer(sn, constants.Finalizer)
return r.Patch(ctx, sn, client.MergeFrom(orig))

// We'll use a JSON Merge Patch here to avoid removal of finalizers added by other controllers
Copy link
Member

Choose a reason for hiding this comment

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

Based on my testing, it appears that even with the previous code, finalizers added by other controllers would not have been removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's probably true. But as the finalizer is added by our admission webhook, I think it makes sense to remove it as precisely as possible. And a JSON patch is the most exact we can use AFAIK. So I don't think this harms. Do you want me to revert this change?

Copy link
Member

Choose a reason for hiding this comment

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

No problem. This implementation works for me.

zoetrope
zoetrope previously approved these changes Aug 19, 2025
Copy link
Member

@zoetrope zoetrope left a comment

Choose a reason for hiding this comment

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

@erikgb
I think this can be merged as is. If you feel that additional tests are needed, please feel free to add them.

@erikgb
Copy link
Collaborator Author

erikgb commented Aug 19, 2025

@erikgb I think this can be merged as is. If you feel that additional tests are needed, please feel free to add them.

Thanks @zoetrope. I would love to write a new end-to-end test to verify that this PR fixes the linked issue, as it cannot be tested with envTest. Thanks for explaining how this case differs from the e2e-test we already have.

@erikgb
Copy link
Collaborator Author

erikgb commented Feb 8, 2026

@zoetrope, sorry for the very long delay, but I have now added an e2e-test to verify that this PR fixes the issue. I created a draft PR to verify that the test is effective: #196. I would have preferred to write an integration test (envTest), but envTest doesn't support namespace deletion, as documented in the kubebuilder book.

Please review when you have some time!

@erikgb erikgb requested a review from zoetrope February 8, 2026 20:19
Copy link
Member

@zoetrope zoetrope left a comment

Choose a reason for hiding this comment

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

LGTM!!

@erikgb erikgb merged commit 09d0752 into cybozu-go:main Feb 9, 2026
7 checks passed
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.

Accurate doesn't create a new namespace after resolving an issue with conflicting namespaces

2 participants