Commit 499fbc7
authored
feat: Automating legacy konnector agent removal (#1384)
**What problem does this PR solve?**:
This PR adds functionality to automatically detect and uninstall legacy
Helm releases (chart name: `nutanix-k8s-agent`) during cluster upgrades.
This ensures a clean transition from the legacy Helm-based installation
to the new HelmChartProxy-based approach(addon), preventing conflicts
and orphaned resources.
When upgrading clusters that were previously deployed with the legacy
`nutanix-k8s-agent` Helm chart, the old Helm release remains in the
cluster alongside the new HelmChartProxy-managed installation. This can
lead to:
- **Resource Conflicts**: Both the legacy release and new HelmChartProxy
may try to manage the same resources
- **Orphaned Resources**: If the legacy release is manually deleted or
corrupted, its resources remain orphaned
- **Upgrade Failures**: Conflicts during upgrade can cause the upgrade
process to fail
- **Manual Intervention Required**: Currently, operators must manually
identify and uninstall legacy releases before upgrades
Previously, the `BeforeClusterUpgrade` hook had no logic to handle
legacy Helm releases, requiring manual cleanup before upgrades.
**Solution**:
This PR implements automatic legacy Helm release detection and
uninstallation during the `BeforeClusterUpgrade` lifecycle hook:
1. **Automatic Detection**: Scans for Helm release secrets containing
the legacy chart name `nutanix-k8s-agent`
2. **Proper Uninstallation**: Uses Helm's Go client
(`helm.sh/helm/v3/pkg/action`) to properly uninstall releases, ensuring
all associated Kubernetes resources are removed
3. **Best-Effort Operation**: Legacy cleanup errors are logged but don't
block the upgrade process
5. **Edge Case Handling**: Handles multiple legacy releases that may
exist from failed upgrades or manual installations
**Which issue(s) this PR fixes**:
Fixes #
[NCN-110886](https://jira.nutanix.com/browse/NCN-110886)
**How Has This Been Tested?**:
Deployed local kind clusters and tested both new cluster creation and
upgrades
Test logs:
Helm list - 2.16 cluster:
<img width="1357" height="214" alt="Beforeupgrade_helmlist"
src="https://github.com/user-attachments/assets/f710b213-32eb-48f1-a77f-4c81bb7fc636"
/>
After upgrade:
Helm list - 2.17-dev
<img width="1339" height="206" alt="Afterupgrade-helmlist"
src="https://github.com/user-attachments/assets/cf101145-f9a1-4847-939f-1e4d1f3cbcad"
/>
Upgrade logs:
`
I1110 03:56:32.057732 1 handler.go:664] "Uninstalling legacy helm
release" cluster="default/nkp-vijay-test-cluster-36"
releaseName="k8sagent" namespace="ntnx-system"
chartName="nutanix-k8s-agent"
I1110 03:56:32.301845 1 helmaddon.go:147] "Retrieving installation
values template for cluster" cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:33.016166 1 handler.go:740] "uninstall: Deleting k8sagent"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:33.016192 1 handler.go:740] "delete hooks disabled for
k8sagent" cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:34.630251 1 handler.go:740] "uninstall: given cascade value:
, defaulting to delete propagation background"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:34.630517 1 handler.go:740] "Starting delete for
\"nutanix-agent\" Deployment"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:34.886818 1 handler.go:740] "Starting delete for
\"nutanix-agent\" ClusterRoleBinding"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:35.145205 1 handler.go:740] "Starting delete for
\"nutanix-agent\" ClusterRole"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:35.402476 1 handler.go:740] "Starting delete for
\"ntnx-cluster-configmap\" ConfigMap"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:35.402706 1 handler.go:740] "Starting delete for
\"nutanix-agent-config\" ConfigMap"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:35.659980 1 handler.go:740] "Starting delete for
\"nutanix-agent\" ServiceAccount"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:35.917091 1 handler.go:740] "purge requested for k8sagent"
cluster="default/nkp-vijay-test-cluster-36"
I1110 03:56:36.586018 1 handler.go:683] "Successfully uninstalled legacy
helm release" cluster="default/nkp-vijay-test-cluster-36"
releaseName="k8sagent" namespace="ntnx-system"
I1110 03:56:37.623619 1 cm.go:88] "Fetching HelmChart info for
\"konnector-agent\" from configmap default/default-helm-addons-config"
cluster="default/nkp-vijay-test-cluster-36"`
**Special notes for your reviewer**:
<!--
Use this to provide any additional information to the reviewers.
This may include:
- Best way to review the PR.
- Where the author wants the most review attention on.
- etc.
-->1 parent a84fb3e commit 499fbc7
File tree
7 files changed
+750
-5
lines changed- api/v1alpha1
- pkg
- handlers/lifecycle/konnectoragent
- webhook/cluster
7 files changed
+750
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
67 | 71 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| 64 | + | |
60 | 65 | | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| 80 | + | |
74 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
75 | 85 | | |
76 | 86 | | |
| 87 | + | |
| 88 | + | |
77 | 89 | | |
| 90 | + | |
78 | 91 | | |
| 92 | + | |
79 | 93 | | |
80 | 94 | | |
81 | 95 | | |
82 | 96 | | |
| 97 | + | |
83 | 98 | | |
| 99 | + | |
84 | 100 | | |
85 | 101 | | |
86 | 102 | | |
87 | 103 | | |
| 104 | + | |
| 105 | + | |
88 | 106 | | |
89 | 107 | | |
90 | 108 | | |
| |||
98 | 116 | | |
99 | 117 | | |
100 | 118 | | |
| 119 | + | |
101 | 120 | | |
102 | 121 | | |
103 | 122 | | |
| |||
108 | 127 | | |
109 | 128 | | |
110 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
111 | 135 | | |
| 136 | + | |
112 | 137 | | |
| 138 | + | |
113 | 139 | | |
114 | 140 | | |
115 | 141 | | |
| 142 | + | |
116 | 143 | | |
117 | 144 | | |
118 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
119 | 150 | | |
120 | 151 | | |
121 | 152 | | |
122 | 153 | | |
123 | 154 | | |
| 155 | + | |
124 | 156 | | |
125 | 157 | | |
126 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
127 | 162 | | |
128 | 163 | | |
| 164 | + | |
129 | 165 | | |
| 166 | + | |
130 | 167 | | |
131 | 168 | | |
132 | 169 | | |
133 | 170 | | |
134 | | - | |
| 171 | + | |
135 | 172 | | |
136 | 173 | | |
| 174 | + | |
137 | 175 | | |
138 | 176 | | |
139 | 177 | | |
140 | 178 | | |
141 | 179 | | |
142 | 180 | | |
| 181 | + | |
| 182 | + | |
143 | 183 | | |
144 | 184 | | |
145 | 185 | | |
| |||
153 | 193 | | |
154 | 194 | | |
155 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
156 | 200 | | |
157 | 201 | | |
158 | 202 | | |
| |||
162 | 206 | | |
163 | 207 | | |
164 | 208 | | |
| 209 | + | |
165 | 210 | | |
166 | 211 | | |
167 | 212 | | |
| |||
188 | 233 | | |
189 | 234 | | |
190 | 235 | | |
| 236 | + | |
| 237 | + | |
191 | 238 | | |
192 | 239 | | |
193 | 240 | | |
| 241 | + | |
| 242 | + | |
194 | 243 | | |
195 | 244 | | |
0 commit comments