fix(kubernetes): apply the worker TalosConfigTemplate server-side in the kubernetes chart (#4961)

## What this PR does

On release-1.6 the kubernetes chart still renders its own
talos-reconcile Job for every node group of a Kubernetes application,
and that Job applies the worker TalosConfigTemplate with a client-side
`kubectl apply` under a 256Mi memory limit. This PR makes it `kubectl
apply --server-side --force-conflicts`, the command the kubernetes-nodes
chart has used on this branch since #4575.

#4163 fixed the OOMKill on main, where the Job lives only in
kubernetes-nodes since 92b9785da took the worker pools out of the
kubernetes chart. So its backport #4575 changed only kubernetes-nodes
here, and the kubernetes chart kept the client-side apply that #3519 was
reported against. v1.6.5 still has it at line 324 of
`packages/apps/kubernetes/templates/talos/talos-reconcile-job.yaml`.
Neither main nor release-1.7 has this Job in the kubernetes chart, so
there is nothing to backport and the fix goes to release-1.6 directly.

Seen on a v1.6.5 cluster upgraded from v1.6.4. The upgrade ran the
`talos-reconcile-md0` Job of a tenant Kubernetes cluster again, and
within about eight minutes its container had restarted 6 times
(`restartCount`), the last time with `lastState.terminated.reason`
`OOMKilled`, and the pod sat in CrashLoopBackOff. The log ends after the
KamajiControlPlane patch (`patched (no change)`), before the template
apply reports anything, the same picture as in #3519. #4163 has the
mechanism and the measurements. With the template already in place, the
client-side apply builds its merge patch from the full OpenAPI document
of the management cluster, while server-side apply leaves the merge to
the apiserver.

Only this apply changes. The Role already grants `create` and `patch` on
`talosconfigtemplates`, which server-side apply needs. The other
`kubectl` calls in the Job are `get` with a jsonpath and a merge `patch`
of the KamajiControlPlane, which do not load the schema, and the log
above shows the patch finishing. The bootstrap-token and OIDC Jobs of
this chart apply into the tenant apiserver and both completed on the
same upgrade, so they are left alone.

The immutability webhook from #3515 is not touched. CABPT v0.6.12, which
this branch ships, rejects a TalosConfigTemplate update only when the
spec differs, so a re-run with an unchanged render should pass it as a
no-op, and a render that changes the template is still refused as
before. On main that was solved with content-hash names in #3523, a
larger change that rolls the workers, and it is not part of this fix.

`tests/talos_reconcile_server_side_apply_test.yaml` is the suite #4163
added to kubernetes-nodes, adapted to this chart, plus a case with two
node groups that checks the Job of each group, since this chart renders
one Job per group. Against the release-1.6 template all 3 cases fail, 6
assertions in total, and the other 190 tests pass. On this branch `helm
unittest` passes 193 of 193 tests in 20 suites, against 190 in 19 on
release-1.6, with helm-unittest 1.1.2. The new Job spec rotates its
content-hash name, so the two fixtures in
`tests/talos_templates_test.yaml` that pin it move from `16c1c9` and
`a9dc0c` to `4916b0` and `63c431`, and an existing cluster gets a new
Job on its next upgrade. `helm template` of the whole chart renders, the
Job script passes `sh -n` under busybox, and
`hack/admin-kubeconfig-invariant.bats`, the Bats file that renders this
chart, passes 3 of 3. I have not run it on a live cluster.

### Screenshots

Not a UI change.

### Downstream repositories

One template line and tests in `packages/apps/kubernetes`. No values,
schema, README, defaults, image or `ApplicationDefinition` change, and
the website mentions this Job only in the generated values table, so no
trigger map entry applies.

- [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:

### Release note

```release-note
fix(kubernetes): the talos-reconcile Job of the kubernetes chart now applies the worker TalosConfigTemplate server-side, like the kubernetes-nodes chart. Before, on management clusters with many CRDs its client-side apply was OOMKilled at the 256Mi limit after every upgrade, and the Job crash-looped.
```
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-11-17 11:16:59 +03:00
commit f2afc7f521
3 files changed
+80 -5

No files matched your search

@@ -321,7 +321,7 @@ spec:
# Apply the TalosConfigTemplate. ownerReference back to the KCP
# makes the standard Kubernetes garbage collector clean it up on
# release uninstall; Helm itself does not track this resource.
cat <<EOF | kubectl apply -f -
cat <<EOF | kubectl apply --server-side --force-conflicts -f -
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
kind: TalosConfigTemplate
metadata:
@@ -0,0 +1,75 @@
suite: worker TalosConfigTemplate is applied server-side
templates:
- templates/talos/talos-reconcile-job.yaml
release:
name: test-k8s
namespace: tenant-test
set:
_namespace:
etcd: etcd
ingress: nginx
host: example.com
_cluster:
cluster-domain: cozy.local
tests:
- it: applies the TalosConfigTemplate server-side
asserts:
- matchRegex:
path: spec.template.spec.containers[0].command[2]
pattern: 'kubectl apply --server-side --force-conflicts -f -'
documentSelector:
path: kind
value: Job
- it: never falls back to a client-side apply
asserts:
- notMatchRegex:
path: spec.template.spec.containers[0].command[2]
pattern: 'kubectl apply -f -'
documentSelector:
path: kind
value: Job
- it: applies server-side from the Job of every node group
set:
nodeGroups:
worker0:
minReplicas: 1
maxReplicas: 3
instanceType: u1.medium
diskSize: 20Gi
storageClass: ""
roles:
- ingress-nginx
resources: {}
gpus: []
kubelet: {}
worker1:
minReplicas: 0
maxReplicas: 5
instanceType: u1.medium
diskSize: 20Gi
storageClass: ""
roles: []
resources: {}
gpus: []
kubelet: {}
asserts:
- hasDocuments:
count: 8
- matchRegex:
path: spec.template.spec.containers[0].command[2]
pattern: 'kubectl apply --server-side --force-conflicts -f -'
documentSelector:
path: kind
value: Job
matchMany: true
- notMatchRegex:
path: spec.template.spec.containers[0].command[2]
pattern: 'kubectl apply -f -'
documentSelector:
path: kind
value: Job
matchMany: true
@@ -156,7 +156,7 @@ tests:
asserts:
- equal:
path: metadata.name
value: test-k8s-talos-reconcile-md0-16c1c9
value: test-k8s-talos-reconcile-md0-4916b0
documentSelector:
path: kind
value: Job
@@ -189,12 +189,12 @@ tests:
gpus:
- name: nvidia.com/GH200
asserts:
# Only gpus changed vs the case above, yet the suffix differs (a9dc0c vs
# 16c1c9) — the content hash tracks the rendered spec, and the TCT the Job
# Only gpus changed vs the case above, yet the suffix differs (63c431 vs
# 4916b0) — the content hash tracks the rendered spec, and the TCT the Job
# applies is what changed (GPU nodeLabels).
- equal:
path: metadata.name
value: test-k8s-talos-reconcile-md0-a9dc0c
value: test-k8s-talos-reconcile-md0-63c431
documentSelector:
path: kind
value: Job