Commit 72bc87d
fix(plugindefinitions): cleanup orphaned Flux HelmChart resources (#2061)
* fix(plugindefinition): cleanup orphaned Flux HelmChart resources on version bump (#2047)
When the HelmChart version in a PluginDefinition spec is updated, the
controller now lists all HelmChart resources owned (controller-reference)
by the PluginDefinition and deletes any whose name no longer matches the
current FluxHelmChartResourceName (i.e. <pluginDef.Name>-<version>).
This prevents accumulation of orphaned HelmChart resources that were
previously left behind whenever the chart version was bumped.
The cleanup is performed in the EnsureCreated reconcile path after the
new HelmChart has been created/updated, so it only runs when the
PluginDefinition is active.
Adds a controller integration test that:
- creates a PluginDefinition with chart version 1.0.0
- bumps the version to 2.0.0
- asserts the new HelmChart (v2.0.0) is created
- asserts the orphaned HelmChart (v1.0.0) is deleted
Fixes: #2047
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
* fix(plugindefinition): address PR review comments (#2047)
- Ignore NotFound error when deleting orphaned HelmChart (avoids hard
reconciliation failure if a chart is deleted concurrently)
- Compare owner UIDs directly (types.UID) instead of via string()
conversions for clarity
- Wire deleteOrphanedHelmCharts into ClusterPluginDefinitionReconciler
so both PluginDefinition and ClusterPluginDefinition clean up orphans
- Tests now derive expected HelmChart names via FluxHelmChartResourceName()
instead of hard-coding the name+version concatenation convention
- Added ClusterPluginDefinition orphan cleanup integration test mirroring
the PluginDefinition test
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
* chore: add sign-off to commits
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
* fix(plugindefinition): address additional review comments on PR #2047
- Add LabelKeyPluginDefinition label to HelmChart during CreateOrUpdate so
the orphan-cleanup list call can use a label selector instead of scanning
all HelmCharts in the namespace on every reconcile (scalability).
- Switch deleteOrphanedHelmCharts to use client.MatchingLabels with
greenhouseapis.LabelKeyPluginDefinition for an efficient server-side filter.
- Replace clientutil.GetOwnerReference + GetObjectKind().GroupVersionKind().Kind
with metav1.GetControllerOf() which is the idiomatic, reliable way to get
the controller owner reference (GetObjectKind() can return an empty Kind when
an object is constructed directly rather than decoded from the API).
- Remove now-unused 'clientutil' import.
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
* fix(plugindefinition): apply review feedback and rebase on upstream main (#2047)
Rebase on top of upstream commit 4d2da4b which was merged by
abhijith-darshan after the PR was opened.
- Incorporate LabelKeyOwnedBy propagation from upstream PR #2062:
when the PluginDefinition has an 'owned-by' label it is propagated
to the managed HelmChart.
- Add deleteOrphanedHelmCharts() with:
- client.MatchingLabels{LabelKeyPluginDefinition: name} for efficient
server-side filtering (abhijith-darshan request)
- metav1.GetControllerOf() for reliable owner reference lookup
- apierrors.IsNotFound guard for concurrent deletion safety
- lowercase log message (NIT by abhijith-darshan)
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
* fix(plugindefinition): run make fmt to fix lint/formatting errors
Run 'make fmt' (goimports + gofmt) to fix import ordering and formatting
issues flagged by the CI linter.
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
---------
Signed-off-by: Edrilan Berisha <edi91@gmx.net>
Co-authored-by: Abhijith Ravindra <137736216+abhijith-darshan@users.noreply.github.com>1 parent 58d11ce commit 72bc87d
6 files changed
Lines changed: 156 additions & 3 deletions
File tree
- api
- meta/v1alpha1
- v1alpha1
- internal/controller/plugindefinition
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
104 | 109 | | |
105 | 110 | | |
106 | 111 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
| |||
Lines changed: 103 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
207 | 310 | | |
208 | 311 | | |
209 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
188 | 189 | | |
189 | 190 | | |
190 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
191 | 234 | | |
192 | 235 | | |
193 | 236 | | |
| |||
0 commit comments