Skip to content

Commit c3ac843

Browse files
author
Matthieu
committed
[platform] Use application.kind label in resourcesPreset migration
Match HelmReleases by the apps.cozystack.io/application.kind label that cozystack-api sets on every HR it creates, instead of regexing the HR name. The previous patterns 'ingress-*' and 'external-dns-*' were dead code: both ApplicationDefinitions set release.prefix="", so HRs are named after the user-chosen CR (e.g. 'default'), which never matched, and explicit resourcesPreset overrides on those apps fell through to the u1 default instead of s1. Document the known limitation that a single series is applied uniformly across nested resourcesPreset fields — affects only users with explicit nested overrides on apps with mixed-series chart defaults (ClickHouse, Kafka, OpenSearch, Kubernetes). Signed-off-by: Matthieu <[email protected]>
1 parent 3f84d83 commit c3ac843

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

  • packages/core/platform/images/migrations/migrations

‎packages/core/platform/images/migrations/migrations/39‎

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,42 @@
22
# Migration 39 --> 40
33
# Migrate resourcesPreset values from flat names to instance-type names (s1/u1/m1)
44
#
5-
# Series selection per app type:
6-
# m1 (Memory, 1:8) — memory-intensive: redis, opensearch, qdrant
7-
# u1 (Universal, 1:4) — databases & messaging: postgres, mariadb, mongodb,
8-
# clickhouse, foundationdb, kafka, rabbitmq, nats, ferretdb
9-
# s1 (Standard, 1:2) — stateless services: harbor, vpn, tcp-balancer,
10-
# http-cache, openbao, ingress, external-dns
11-
# u1 — fallback for unknown app types
5+
# Series selection per app kind (read from the
6+
# apps.cozystack.io/application.kind label):
7+
# m1 (Memory, 1:8) — memory-intensive: Redis, OpenSearch, Qdrant
8+
# u1 (Universal, 1:4) — databases & messaging: Postgres, MariaDB, MongoDB,
9+
# ClickHouse, FoundationDB, Kafka, RabbitMQ, NATS,
10+
# plus Kubernetes/VMInstance and any app without the
11+
# kind label (safe over-sizing fallback).
12+
# s1 (Standard, 1:2) — stateless services: Harbor, VPN, TCPBalancer,
13+
# HTTPCache, OpenBAO, Ingress, ExternalDNS
14+
#
15+
# Limitation: a single series is applied uniformly across every nested
16+
# resourcesPreset in the values tree. A few apps have mixed series in their
17+
# chart defaults (e.g. ClickHouse top u1 + clickhouseKeeper s1; OpenSearch top
18+
# m1 + dashboards s1; Kubernetes apiServer u1 + controllerManager/scheduler/
19+
# konnectivity s1). Users who explicitly overrode resourcesPreset on those
20+
# nested fields will end up with the parent app's series there too — i.e.
21+
# slightly over-sized sub-components. The chart defaults still apply for
22+
# fields the user did not override, so the common case is unaffected.
1223

1324
set -euo pipefail
1425

1526
echo "Migrating HelmReleases: renaming resourcesPreset values to instance-type format"
1627

17-
# Determine the target series based on HelmRelease name prefix
28+
# Determine the target series based on the application kind label set by
29+
# cozystack-api on every HelmRelease it creates
30+
# (apps.cozystack.io/application.kind, see pkg/apis/apps/v1alpha1/types.go).
31+
# Keying off the label avoids duplicating the release.prefix list from
32+
# ApplicationDefinitions and works regardless of the HR name the user picked.
33+
# HelmReleases without this label (e.g. created outside cozystack-api)
34+
# fall through to the u1 default — a safe over-sizing on the universal series.
1835
get_series() {
19-
local name="$1"
20-
case "$name" in
21-
redis-*|opensearch-*|qdrant-*)
36+
local kind="$1"
37+
case "$kind" in
38+
Redis|OpenSearch|Qdrant)
2239
echo "m1" ;;
23-
harbor-*|vpn-*|tcp-balancer-*|http-cache-*|openbao-*|ingress-*|external-dns-*)
40+
Harbor|VPN|TCPBalancer|HTTPCache|OpenBAO|Ingress|ExternalDNS)
2441
echo "s1" ;;
2542
*)
2643
echo "u1" ;;
@@ -29,11 +46,13 @@ get_series() {
2946

3047
# Find all HelmReleases that have resourcesPreset in their spec.values
3148
kubectl get helmreleases --all-namespaces -o json | \
32-
jq -r '.items[] | select(.spec.values | tostring | test("resourcesPreset")) | "\(.metadata.namespace)|\(.metadata.name)"' | \
33-
while IFS='|' read -r namespace name; do
34-
echo "Processing HelmRelease $namespace/$name"
49+
jq -r '.items[]
50+
| select(.spec.values | tostring | test("resourcesPreset"))
51+
| "\(.metadata.namespace)|\(.metadata.name)|\(.metadata.labels["apps.cozystack.io/application.kind"] // "")"' | \
52+
while IFS='|' read -r namespace name kind; do
53+
echo "Processing HelmRelease $namespace/$name (kind: ${kind:-<none>})"
3554

36-
series=$(get_series "$name")
55+
series=$(get_series "$kind")
3756
echo " Using series: $series"
3857

3958
values=$(kubectl get helmrelease -n "$namespace" "$name" -o jsonpath='{.spec.values}')

0 commit comments

Comments
 (0)