Skip to content

Commit c247bf4

Browse files
authored
feat(apps): instance-type resource presets with five series (#2607)
## What this PR does Closes #1959. Continuation of @matthieu-robin's instance-type resource presets work, addressing the migration gaps and resource regressions surfaced during the review of #1959. Resource presets now follow a cloud-style `<series>.<size>` naming convention. Five series cover the full CPU-to-memory ratio range, each with eight sizes (`nano` through `4xlarge`): | Series | Ratio | Use case | | ------ | ----- | -------- | | `t1` | 1:0.5 | Tiny / burstable, low memory | | `c1` | 1:1 | Compute-balanced | | `s1` | 1:2 | Standard — proxies, caches | | `u1` | 1:4 | Universal — databases, messaging | | `m1` | 1:8 | Memory — search, analytics | 40 instance-type presets in total. The seven legacy flat names (`nano`, `micro`, `small`, `medium`, `large`, `xlarge`, `2xlarge`) remain accepted as deprecated aliases. ### Upgrade path The combination of three mechanisms makes the rename a no-op for existing deployments: 1. **`cozy-lib` legacy aliases** — preserve the exact pre-rename CPU and memory for every legacy name. `helm template ... --set resourcesPreset=small` continues to render `1 CPU / 512Mi`, identical to before. No HelmRelease that already lives on the cluster breaks. 2. **Migration 39** — a pre-upgrade hook walks every `HelmRelease.spec.values` and every app CR under `apps.cozystack.io/v1alpha1`, rewriting legacy values to their 1:1 instance-type equivalents (`nano → t1.nano`, `medium → c1.small`, etc). Idempotent, best-effort, dry-runnable via `MIGRATION_DRY_RUN=1`, distinguishes "no items" from "kubectl errored" so a broken cluster cannot silently stamp the version. 3. **`cozystack-api` deprecation warning** — every `Create` and `Update` on an app CR with a legacy value emits a `klog` warning naming the JSON path and the 1:1 replacement, so operators discover any remaining legacy data after the platform upgrade. The legacy-to-instance-type mapping is 1:1 by CPU and memory: | Legacy | CPU | Memory | Instance-type | | -------- | ---- | ------ | ------------- | | `nano` | 250m | 128Mi | `t1.nano` | | `micro` | 500m | 256Mi | `t1.micro` | | `small` | 1 | 512Mi | `t1.small` | | `medium` | 1 | 1Gi | `c1.small` | | `large` | 2 | 2Gi | `c1.medium` | | `xlarge` | 4 | 4Gi | `c1.large` | | `2xlarge`| 8 | 8Gi | `c1.xlarge` | Mirrored in four places (cozy-lib template, Go package, migration jq, docs) with cross-reference comments so drift is visible. ### Why not just #1959 The implementation in #1959 had three blockers that motivated this rewrite: - **`cozy-lib` lost the legacy names entirely**, so any existing HelmRelease with `resourcesPreset: small` failed render with `Preset key 'small' invalid`. Aliases close this hole. - **Migration only touched HelmReleases**, leaving app CRs unmigrated; the next `kubectl edit` would fail enum validation. The new migration walks both. - **Defaults silently inflated memory**, e.g. Redis `nano → m1.nano` jumped from 128Mi to 2Gi (×16). With two replicas plus sentinel the e2e VM ran out of memory, producing the Redis 90s timeout that blocked the original PR. New defaults preserve resources 1:1. ### Deprecation timeline Legacy aliases are scheduled for removal in a future cozystack release. The combination of migration + operator warnings is expected to converge production clusters before then. Removal will land as a separate PR with its own migration cleanup pass. ### Test plan - `make unit-tests` — Go tests for the preset walker + warning helper, `helm unittest` legacy↔instance-type parity suites for `postgres`/`clickhouse`/`opensearch`, RD schema invariance check via `hack/check-rd-presets.sh`. - `make generate` is idempotent. - `helm template ./packages/apps/redis` with the new default renders 250m / 128Mi (matches pre-rename Redis exactly — closes the e2e blocker). - `helm template ./packages/apps/postgres --set resourcesPreset=small` renders 1 / 512Mi (legacy alias works). - Migration dry-run is exercised via `MIGRATION_DRY_RUN=1`. ### Documentation See [`docs/operations/resource-presets.md`](docs/operations/resource-presets.md) for the full size matrix and migration table. ### Release note ```release-note feat(cozy-lib): introduce `<series>.<size>` instance-type resource presets (t1/c1/s1/u1/m1 × 8 sizes). Legacy flat names (nano…2xlarge) remain accepted as deprecated 1:1 aliases; migration 39 rewrites stored values to the new form. CPU and memory are preserved exactly across the rename. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Expanded resource preset options to instance-style names (e.g., t1.*, c1.*, m1.*); legacy flat names remain supported as deprecated aliases. * Deprecation warnings now surface when legacy presets are detected. * **Documentation** * Added a comprehensive resource-presets guide and updated chart/app docs to the new naming convention. * **Tests** * Added compatibility tests ensuring legacy ↔ instance-type presets render identical resources. * **Chores** * Migration and CI checks to detect/upgrade legacy preset values. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/cozystack/cozystack/pull/2607) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 86f5267 + 55a98b8 commit c247bf4

117 files changed

Lines changed: 3857 additions & 593 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Makefile‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: manifests assets unit-tests helm-unit-tests bats-unit-tests preflight
1+
.PHONY: manifests assets unit-tests helm-unit-tests bats-unit-tests rd-presets-check preflight
22

33
include hack/common-envs.mk
44

@@ -94,11 +94,18 @@ test:
9494
make -C packages/core/testing apply
9595
make -C packages/core/testing test
9696

97-
unit-tests: helm-unit-tests bats-unit-tests go-unit-tests
97+
unit-tests: helm-unit-tests bats-unit-tests go-unit-tests rd-presets-check
9898

9999
helm-unit-tests:
100100
hack/helm-unit-tests.sh
101101

102+
# Pin the resourcesPreset enum in every ApplicationDefinition openAPISchema
103+
# to the canonical 47-value set (40 instance-type names + 7 legacy aliases).
104+
# Catches the regression where one chart's Makefile forgets to invoke
105+
# hack/update-crd.sh and that RD's schema drifts from values.schema.json.
106+
rd-presets-check:
107+
hack/check-rd-presets.sh
108+
102109
# Scoped go test over the cozystack-api surface that this repo owns. Kept
103110
# narrow intentionally - running `go test ./...` pulls in generated code
104111
# round-trip suites whose behavior depends on tool versions outside this

‎api/apps/v1alpha1/clickhouse/types.go‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/foundationdb/types.go‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/harbor/types.go‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/httpcache/types.go‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/kafka/types.go‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/kubernetes/types.go‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/mariadb/types.go‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/mongodb/types.go‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/nats/types.go‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)