Files
cozystack/packages
Aleksei Sviridkin fa09cdc184 fix(keycloak, foundationdb): apply operator CRD updates on upgrade (#4946)
## What this PR does

The generated HelmReleases leave `spec.upgrade.crds` unset unless the
PackageSource sets `upgradeCRDs`, so helm-controller never replaces a
CRD that a chart ships in `crds/`. keycloak-operator and
foundationdb-operator ship their CRDs that way and set no policy. On a
v1.6.4 cluster that came through earlier releases, the CRDs of both
operators were older than the ones in the v1.6.4 charts. The v1.25.0
ClusterKeycloakRealm schema has no `spec.sessions`, `spec.login` or
`spec.organizationsEnabled`, so the apiserver dropped the session
settings keycloak-configure sets and the operator never applied them to
the realm. Keycloak also rejected the dashboard KeycloakClient with HTTP
400 on that cluster, and replacing the 17 CRDs from the charts and
restarting keycloak-operator cleared it.

This opts both PackageSources into `upgradeCRDs: CreateReplace`, the
policy mongodb-operator, redis-operator and velero already use, and pins
it with a platform test for each. The keycloak-operator change is not
purely additive. v1.32.0 drops the `realm`, `targetRealm` and
`keycloakOwner` fields that v1.25.0 marked deprecated and requires
`realmRef` and `keycloakRef` instead. Every Keycloak object the platform
renders already uses the refs, and each of the 14 CRDs keeps its single
version, so the replace loses nothing the platform relies on and drops
no stored version. A hand-made object that still uses a deprecated field
would lose it on its next write, and that write needs the ref. The
foundationdb-operator CRDs only add fields from v2.13.0 to v2.30.0, plus
a pattern on `perpetual_storage_wiggle_locality`, which the platform
does not set.

helm-controller applies the policy only when it upgrades a release, and
it upgrades only when the release artifact or its values change. A
PackageSource edit changes neither. The PR therefore also gives the
keycloak-operator package a helm-unittest suite, which pins the realm
fields keycloak-configure sets against the ClusterKeycloakRealm CRD the
chart ships and changes the keycloak-operator artifact, so the CRDs are
replaced on the upgrade that brings this change even where nothing else
in the package changes, as on a backport to release-1.6. The platform
release writes the new PackageSource in the same apply that moves
`cozystack-packages` to the new revision, so the policy should reach the
HelmRelease before the new keycloak-operator artifact does. The
foundationdb-operator package does not change here, so its CRDs are
replaced at the next change to that package, and main already carries
one since v1.6.5.

Objects written while the CRDs were stale get the pruned fields back
only when their chart applies them again. For the cozy realm that is the
next keycloak-configure upgrade. On main it comes with the same platform
upgrade, since keycloak-configure changed after v1.6.5, and its
HelmRelease depends on the keycloak-operator one through the oidc
variant. On a branch where keycloak-configure does not change, the realm
keeps its current session limits until it does or until that release is
forced to upgrade.

#4901 adds the same `upgradeCRDs: CreateReplace` to the
foundationdb-operator PackageSource as part of the FoundationDB backup
work, and it changes the foundationdb-operator package as well. The
foundationdb commit here is separate from the keycloak one and does not
depend on it, so it can be dropped if #4901 lands first.

The other packages that ship CRDs only in `crds/` and set no policy are
bootbox, clickhouse-operator, clustersecret-operator,
cozystack-scheduler, external-dns, grafana-operator, kafka-operator and
snapshot-controller. None of their CRDs changed since v1.0.0, or since
the package was added, apart from description text in external-dns, so
no cluster is behind on them today. kafka-operator gets CreateReplace
with the Strimzi move in #4900. gpu-operator replaces its CRDs with its
own pre-upgrade Job, and the remaining packages render their CRDs from
templates or leave them to an operator. Each of the eight will need the
same review and opt-in the next time its CRDs change.

`make -C packages/core/platform test` passes with 58 suites and 287
tests, and `make -C packages/system/keycloak-operator test` passes. With
either PackageSource reverted to main, its suite fails with `unknown
path spec.variants[0].components[0].install.upgradeCRDs`. With the
v1.25.0 ClusterKeycloakRealm CRD in the chart, the keycloak-operator
suite fails all four assertions. The full `hack/helm-unit-tests.sh`
sweep passes.

### 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:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

Two PackageSources under `packages/core/platform/sources/` gain an
install option, three test suites are new, and
`packages/system/keycloak-operator/Makefile` gains the same `test`
target other packages have. Platform `values.yaml`, variants, bundles,
CRDs, `hack/` and the installer are untouched. The website's
`development.md` does not describe per-package test targets, so the
Makefile change needs nothing there, and no website page documents a
manual CRD replace for these operators.

### Release note

```release-note
fix(keycloak, foundationdb): keycloak-operator and foundationdb-operator now replace their CRDs on upgrade. Clusters upgraded from before v1.2.0 kept the v1.25.0 keycloak-operator CRDs, under which the apiserver dropped the Keycloak realm session settings and Keycloak could reject the dashboard client, and clusters upgraded from before v1.6.0 kept the v2.13.0 foundationdb-operator CRDs.
```


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

## Summary by CodeRabbit

* **Bug Fixes**
* Existing FoundationDB and Keycloak installations can now upgrade their
custom resource definitions with replacement behavior, including updates
to schemas and removal of deprecated fields.
* **Tests**
* Added checks for the operator upgrade settings and Keycloak CRD schema
fields.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-13 18:24:45 +03:00
..