Skip to content

Conversation

@tralafiti
Copy link
Contributor

Prevent blocking namespace deletion by yielding in chart handlers OnRemove callback if target namespace is in terminating phase.

Fixes #135

@tralafiti tralafiti force-pushed the fix-namespace-deletion branch from e87f0b1 to 595caf4 Compare December 19, 2025 14:13
Copy link
Member

@brandond brandond left a comment

Choose a reason for hiding this comment

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

Question: rather than adding a new watch+cache on namespaces, would it be easier to handle the unable to create new content in namespace NS because it is being terminated error when applying the job? You can use apierrors.IsForbidden(err) && apierrors.HasStatusCause(err, corev1.NamespaceTerminatingCause) for this.

@tralafiti
Copy link
Contributor Author

tralafiti commented Dec 20, 2025

@brandond Thank you for the feedback! Inspecting the error was my first approach actually. Sadly it's an github.com/rancher/wrangler/v3/pkg/merr which apierrors didn't handle correctly. IMHO typecasting and iterating over the []error for the check was a bit cumbersome and just inspecting the namespace itself sounded cleaner to me. Also firing the jobs just to check if they failed felt wasteful. I'm not familiar with wrangler and would have expecting a just-in-time querying of the k8s resource and not an additional watch to be honest. Please let me know if you prefer the error-checking-solution and I will update the PR :)

@brandond
Copy link
Member

You would need to do a type switch to see if the return is merr.Errors (type alias for []error) or just a single error - but I think that's preferable if it works.

While it may be a little more code, the alternative is adding a namespace cache, or doing an uncached lookup against the apiserver every time this OnRemove handler runs - which may be multiple times in short succession due to how wrangler retries handlers.

@tralafiti tralafiti force-pushed the fix-namespace-deletion branch from 595caf4 to f6f8fbc Compare December 22, 2025 10:20
@tralafiti
Copy link
Contributor Author

Replaced the commit with the discussed solution

@brandond
Copy link
Member

brandond commented Dec 22, 2025

LGTM - but does it work? Can you add a test for this to https://github.com/k3s-io/helm-controller/blob/master/test/suite/helm_test.go ?

Should be pretty easy to just copy one of the existing create/delete tests - just add a step in the middle to delete the ns.

@tralafiti
Copy link
Contributor Author

Only checked the make file and didn't see the e2e tests in scripts, thanks for your hint. Added test coverage. FYI I had to change the controller args to start cluster scoped for this to be possible.

@brandond
Copy link
Member

LGTM, tests look good - but please make sure all your commits have --sign-off for DCO.

@tralafiti tralafiti force-pushed the fix-namespace-deletion branch from b68e62e to 009255c Compare December 23, 2025 19:26
@tralafiti
Copy link
Contributor Author

tralafiti commented Dec 23, 2025

Sorry, my muscle memory favors -S over -s 😅. Fixed

@brandond brandond merged commit 1b28363 into k3s-io:master Dec 23, 2025
3 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.

Namespace deletion hanging

2 participants