fix: delete plugin namespace after removing it#39
Conversation
| }, | ||
| } | ||
|
|
||
| func deleteNamespace(kubeConfigData, namespace string) error { |
There was a problem hiding this comment.
Include the namespace deletion as part of the plugin installation process. This helps maintain abstraction by keeping operational commands decoupled from the core logic, ensuring clearer separation of concerns.
e.g. in ArgoCD installer or helm installer you can set cleanup of the namespace.
There was a problem hiding this comment.
I got it,
but do you mean plugin uninstallation process not installation process?
what i will do.
- Move namespace cleanup logic from the command layer (remove.go) to the installer layer.
- Create a shared cleanup Namespace utility function in the installer package to handle namespace deletion.
- Add namespace cleanup as part of the UnInstall method in both Helm and ArgoCD installers.
There was a problem hiding this comment.
Yep uninstall. When I said installation process I meant the layer sorry for confusion. Let me know if you need any help in architecture
There was a problem hiding this comment.
@nmn3m First, investigate why the uninstall function in the Helm and ArgoCD installers does not clean up the namespace. Look into whether there are flags or options available in Helm and ArgoCD to ensure proper cleanup. Keep in mind that not all plugins are responsible for creating namespaces some are intended solely to update or override the configuration of other plugins.
There was a problem hiding this comment.
🧹 Uninstall Behavior & Namespace Ownership
Findings
-
Helm
helm uninstallonly removes release-managed resources.--namespaceis used for lookup; does not trigger deletion.- No built-in support for namespace cleanup.
-
ArgoCD
- Application deletion removes only managed resources.
- Destination namespace is specified but not managed.
Issues
- No tracking or handling of namespace ownership.
- Plugin types vary:
- Some create and own namespaces (e.g., ArgoCD, Cert-Manager).
- Some reuse existing namespaces (e.g., Ingress controllers, TLS).
- Some modify other namespaces.
Changes
- Introduced a mechanism to identify if a plugin owns its namespace.
- Namespace deletion is now conditional based on plugin type.
- Clear separation between resource cleanup and namespace management logic.
🛠️ Code Improvements
- Applied interface segregation to break import cycles instead of creating a new package.
🐛 Bug Fix: ArgoCD Uninstall Error
- Fixed
HTTP 415 - Invalid content typeduring ArgoCD app deletion. - Solution: Set proper header in
argo.go:req.Header.Set("Content-Type", "application/json")
| @@ -0,0 +1,57 @@ | |||
| package installer | |||
There was a problem hiding this comment.
The installer package includes the installers which implement installer interface, however here you added a utility. so it should be in different package
There was a problem hiding this comment.
I got your point,
Do you have a problem if i add this utility inside k8s package as i see, i will fit there with client.go
There was a problem hiding this comment.
Yes you can define a new function in the abstracted K8s client called DeleteNamespace
| return fmt.Errorf("failed to delete namespace %s: %w", namespace, err) | ||
| } | ||
|
|
||
| for { |
There was a problem hiding this comment.
There is no infinite stop here it will re-try for ever which is consuming the resources. also keep into account race condition between installer deleting the resource in background and deleting the namespace itself
| } | ||
|
|
||
| // Default implementation - plugins can override if needed | ||
| func (b *BasePlugin) OwnsNamespace() bool { |
There was a problem hiding this comment.
You do not need this as the plugin has a string namespace field so you check if it is empty
There was a problem hiding this comment.
Plugin Namespace Lifecycle Design
This design provides a clean and flexible way to handle plugin lifecycles:
-
Plugins that own their namespace (e.g., ArgoCD, Nginx, LoadBalancer)
→ Can safely delete the entire namespace during uninstallation. -
Plugins that share a namespace (e.g., TLS sharing the
cert-managernamespace)
→ Will leave the namespace intact during uninstallation to avoid disrupting other components. -
Separation of concerns between:
GetNamespace()— Defines where the plugin runs.OwnsNamespace()— Defines whether the plugin has exclusive control over that namespace.
This distinction is especially critical for shared environments, where deleting a shared namespace could unintentionally break other plugins or system components relying on it.
There was a problem hiding this comment.
Namespaces are not shared by design each plugin either defines its own namespace or operates without one. keep it simple
| Version: version, | ||
| KubeConfig: kubeConfig, | ||
| RepoName: plugin.GetRepoName(), | ||
| Plugin: plugin, |
| @@ -1,5 +1,15 @@ | |||
| package installer | |||
|
|
|||
| type PluginInterface interface { | |||
There was a problem hiding this comment.
Could you explain more why we need this interface inside the installer interface under installer package
There was a problem hiding this comment.
I forget to remove it, I was using it to solve Applied interface segregation to break import cycles instead of creating a new package
Fix
Impact