Aleksei Sviridkin 177da7843d fix(kubernetes): keep tenant addon CRDs when a release is uninstalled (#3586)
## What this PR does

Four tenant addon HelmReleases render their CRDs from a chart's
`templates/` directory and remediate a failed install by uninstalling
the release. An uninstall deletes what the chart rendered, and deleting
a CRD makes the API server garbage-collect every custom resource of that
kind, so a failed reinstall takes every Gateway, VerticalPodAutoscaler,
ServiceMonitor or VolumeSnapshot in the tenant cluster with it. This
annotates the CRDs of the four packages behind them, `gateway-api-crds`,
`vertical-pod-autoscaler-crds`, `prometheus-operator-crds` and
`vsnap-crd` (that last one is declared by
`helmreleases/volumesnapshot-crd.yaml`), with `helm.sh/resource-policy:
keep`, which is what `cert-manager-crds` and `etcd-operator-crds`
already carry in this tree.

Three of the four regenerate `templates/` from upstream on `make
update`: two delete the directory outright and the third overwrites its
file. So the annotation is written into the vendored files and reapplied
by a step in each `update:` target. Without that second half the next
regeneration drops it silently, with nothing reporting the loss. I ran
`make update` for real to check the pair holds: `gateway-api-crds` and
`vsnap-crd` come back byte-identical to what is committed here, and
`vertical-pod-autoscaler-crds` reproduces the annotation on both of its
CRDs. The rest of the VPA diff is upstream drift, because that package's
`update:` tracks a branch rather than a pinned ref; the bump itself is
not in this PR. The step is idempotent, so running it twice does not
stack a second annotation into the same mapping.

`prometheus-operator-crds` ships its CRDs in a vendored subchart that
`make update` re-pulls, so nothing under `charts/` is edited. The
upstream template already renders `.Values.annotations` onto every CRD
it emits, and the annotation is set through the package's `values.yaml`.

The Gateway API kustomization also emits a `ValidatingAdmissionPolicy`
and its binding. Those hold no user data, so the stamping step selects
on `kind: CustomResourceDefinition` and leaves them alone.

Each package gains a helm-unittest suite and the `test:` target that
`hack/helm-unit-tests.sh` requires before it will run a suite at all.
Every suite asserts the annotation across all CRDs its chart renders,
not only the ones listed by name, so a CRD arriving in a later upstream
bump is covered without editing the test.

The annotation has a cost worth stating plainly: uninstalling one of
these releases on purpose now leaves the CRDs behind, to be removed by
hand. That is the same trade-off `cert-manager-crds` already carries.

This covers the first of the two directions in #3555. The second one,
setting `install.strategy.name: RetryOnFailure` on these releases, is a
separate decision with a different blast radius and is not part of this
PR.

### Screenshots

Not a UI change.

### Downstream repositories

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:

I walked the trigger map in `docs/agents/contributing.md` against the
file list of this diff. It touches four packages under
`packages/system/` and nothing else: no `hack/package.mk`, no app
`values.schema.json`, no platform values, no `ApplicationDefinition`, no
release asset names. The one line that looked close is the website's
"developer tooling (the package Makefiles)" trigger, so I read
`content/en/docs/next/development.md` in the website repo: it documents
`make update` and `make test` in general terms, and neither goes stale
from this change.

### Release note

```release-note
fix(kubernetes): tenant addon CRDs for Gateway API, VerticalPodAutoscaler, Prometheus Operator and VolumeSnapshot now carry `helm.sh/resource-policy: keep`. A failed install that remediates by uninstalling the release no longer deletes those CRDs and, with them, every custom resource of those kinds in the tenant cluster. In exchange, uninstalling one of these releases on purpose now leaves the CRDs in the cluster to be removed by hand.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Custom Resource Definitions for Gateway API, Prometheus Operator,
Vertical Pod Autoscaler, and VolumeSnapshot are now retained when their
Helm charts are uninstalled.
* Prevents loss of custom resources and related configuration during
chart lifecycle operations.
* **Tests**
* Added automated validation confirming all included CRDs receive the
retention policy.
  * Added chart test commands to simplify verification of CRD updates.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-07 17:47:14 +03:00
2025-10-08 09:43:34 +05:00
2025-04-01 18:48:14 +02:00
2024-02-08 12:04:32 +01:00

Cozystack Cozystack

Open Source Apache-2.0 License Support Active GitHub Release GitHub Commit OpenSSF Best Practices OpenSSF Scorecard

Cozystack

Cozystack is a free platform and framework for building clouds.

Cozystack is a CNCF Sandbox Level Project that was originally built and sponsored by Ænix.

With Cozystack, you can transform a bunch of servers into an intelligent system with a simple REST API for spawning Kubernetes clusters, Database-as-a-Service, virtual machines, load balancers, HTTP caching services, and other services with ease.

Use Cozystack to build your own cloud or provide a cost-effective development environment.

Cozystack user interface

Use-Cases

Documentation

The documentation is located on the cozystack.io website.

Read the Getting Started section for a quick start.

If you encounter any difficulties, start with the troubleshooting guide and work your way through the process that we've outlined.

Versioning

Versioning adheres to the Semantic Versioning principles.
A full list of the available releases is available in the GitHub repository's Release section.

Contributions

Contributions are highly appreciated and very welcomed!

In case of bugs, please check if the issue has already been opened by checking the GitHub Issues section. If it isn't, you can open a new one. A detailed report will help us replicate it, assess it, and work on a fix.

You can express your intention to on the fix on your own. Commits are used to generate the changelog, and their author will be referenced in it.

If you have a concrete feature request, open an issue. For a cross-cutting or architectural change, open a design proposal in the community repo. For questions or early ideas, use GitHub Discussions. See CONTRIBUTING.md for the full routing.

Community

You are welcome to join our Telegram group and come to our weekly community meetings. Add them to your Google Calendar or iCal for convenience.

License

Cozystack is licensed under Apache 2.0.
The code is provided as-is with no warranties.

Commercial Support

A list of companies providing commercial support for this project can be found on official site.

Languages
Go 48%
Shell 37%
TypeScript 6.9%
Go Template 5.3%
Makefile 1.4%
Other 1.2%