Repository navigation
Expand file tree
/
Copy pathcluster.yaml
More file actions
904 lines (896 loc) · 46.1 KB
/
Copy pathcluster.yaml
File metadata and controls
904 lines (896 loc) · 46.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
{{- /*
Talos -> Kubernetes support matrix. Each Talos minor release supports a
bounded window of Kubernetes minor versions; running a kubelet outside
that window produces a silently broken Talos+kubelet combination that
HelmRelease cannot detect. Fail the chart render instead, so the operator
sees the mismatch in Flux/dashboards before workers roll over.
Upstream declares the window per Talos *minor* release, and patch releases
never move it, so the lookup key is the minor derived from talos.version.
Keying on the full patch version would silently disable this guard on every
patch bump — exactly the mismatch it exists to catch.
The matrix only fires for Talos minors it knows about; operators who
override talos.version to something outside this list take responsibility
for compatibility themselves (extend the dict or upstream a PR).
Source: https://docs.siderolabs.com/talos/v1.13/getting-started/support-matrix
*/}}
{{- $talosK8sSupportMatrix := dict
"v1.13" (list "v1.31" "v1.32" "v1.33" "v1.34" "v1.35" "v1.36")
}}
{{- $talosMinor := regexFind "^v[0-9]+\\.[0-9]+" .Values.talos.version }}
{{- with index $talosK8sSupportMatrix $talosMinor }}
{{- if not (has $.Values.version .) }}
{{- fail (printf "Kubernetes %s is not supported by Talos %s. Supported versions: %v. Bump tenant 'version' or set talos.version explicitly." $.Values.version $.Values.talos.version .) }}
{{- end }}
{{- end }}
{{- $etcd := .Values._namespace.etcd }}
{{- /*
When $etcd is empty, the parent Tenant application has not populated
_namespace.etcd in cozystack-values yet - either the operator forgot to
set etcd: true on an ancestor Tenant, or the Tenant HelmRelease is still
reconciling. Either way, rendering a KamajiControlPlane with an empty
dataStoreName would be rejected by Kamaji's admission webhook and the
HelmRelease would fail to install, triggering remediation. Instead, emit
a single ConfigMap as a user-visible status beacon and skip the rest so
flux marks the HelmRelease Ready and retries its 5m reconcile loop until
the Tenant chart catches up.
*/}}
{{- /* The TalosConfigTemplate and the apiserver-Service ClusterIP-SAN
used to be rendered in this template behind a lookup gate that
races every fresh install: Service / Talos CA / K8s CA do not
exist on first Helm render, so the gate fails, the TCT is
skipped, and Helm's release-storage three-way merge then refuses
to upgrade because no values changed. Both objects are now
produced by the main-phase Job in
templates/talos/talos-reconcile-job.yaml, which blocks until the
four dependencies exist and then `kubectl apply`s deterministic
results. The Job owns the TCT through an ownerReference to the
KamajiControlPlane so K8s garbage-collects it naturally on
release uninstall. */}}
{{- /*
Cluster pod/service CIDRs MUST match between the CAPI Cluster
spec.clusterNetwork below and the Talos worker machineconfig's
cluster.network — Talos surfaces overlaps against the host pod CIDR
as a diagnostic at boot, and divergence between CAPI and Talos would
manifest as silently broken kube-proxy / Cilium routing. Keep them
in one place here.
*/}}
{{- $podCIDR := "10.243.0.0/16" }}
{{- $serviceCIDR := "10.95.0.0/16" }}
{{- $ingress := .Values._namespace.ingress }}
{{- $host := .Values._namespace.host }}
{{- $kubevirtmachinetemplateNames := list }}
{{- define "kubevirtmachinetemplate" -}}
spec:
{{- /* Talos has no SSH; use 'none' so CAPK does not block Machine.Ready
on an SSH probe that will never succeed. The Machine reaches Ready
once kubelet registers with the tenant apiserver via standard CSR. */}}
virtualMachineBootstrapCheck:
checkStrategy: none
virtualMachineTemplate:
metadata:
namespace: {{ $.Release.Namespace }}
labels:
{{- range .group.roles }}
node-role.kubernetes.io/{{ . }}: ""
{{- end }}
spec:
{{- /* Explicit resources take precedence over instanceType. When a node
group is sized by resources (both cpu and memory set), the
instancetype is omitted from the VM: KubeVirt rejects a
VirtualMachine that references an instancetype and also overrides
either domain.cpu or domain.memory. */}}
{{- $sizedByResources := and .group.resources .group.resources.cpu .group.resources.memory }}
{{- if and .group.instanceType (not $sizedByResources) }}
instancetype:
kind: VirtualMachineClusterInstancetype
name: {{ .group.instanceType }}
{{- end }}
runStrategy: Always
dataVolumeTemplates:
- metadata:
name: disk-system
annotations:
cdi.kubevirt.io/storage.usePopulator: "false"
spec:
{{- /* Use the openstack/configdrive Talos image: KubeVirt CAPK
injects bootstrap data via cloudInitConfigDrive (OpenStack
metadata service shape), and the openstack platform image
is the one that reads it. The nocloud-amd64 image silently
ignores configdrive and never applies the machineconfig. */}}
source:
http:
url: {{ $.Values.talos.imageFactoryURL | trimSuffix "/" }}/image/{{ $.Values.talos.schematicID }}/{{ $.Values.talos.version }}/openstack-amd64.raw.xz
{{- if hasKey .group "ephemeralStorage" }}
{{- fail (printf "nodeGroup %q: ephemeralStorage is no longer supported and should have been automatically migrated to diskSize by platform migration 41. If you see this error after upgrading, the migration did not run — check the cozystack-migration-hook Job logs in cozy-system." .groupName) }}
{{- end }}
storage:
resources:
requests:
storage: {{ .group.diskSize | default "20Gi" | quote }}
{{- /*
Worker VMs live-migrate, so their disks need ReadWriteMany. The
RWX access mode is supplied by the chosen StorageClass's CDI
StorageProfile — it is not set on the DataVolume here. linstor-csi
rejects RWX volumes that are not on a DRBD-backed StorageClass, so
an empty nodeGroup storageClass falls back to the application-level
storageClass (a replicated/DRBD class) instead of the cluster
default, which may be a non-DRBD class that the CSI driver would
reject. Both empty still omits the field so the cluster default
applies.
*/}}
{{- with .group.storageClass | default $.Values.storageClass }}
storageClassName: {{ . | quote }}
{{- end }}
template:
metadata:
annotations:
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
labels:
apps.cozystack.io/application.group: apps.cozystack.io
apps.cozystack.io/application.kind: Kubernetes
apps.cozystack.io/application.name: {{ $.Release.Name | trimPrefix "kubernetes-" | quote }}
{{- range .group.roles }}
node-role.kubernetes.io/{{ . }}: ""
{{- end }}
cluster.x-k8s.io/deployment-name: {{ $.Release.Name }}-{{ .groupName }}
spec:
{{- if .Values._cluster.scheduling }}
{{- $rawConstraints := get .Values._cluster.scheduling "globalAppTopologySpreadConstraints" }}
{{- if $rawConstraints }}
{{- $rawConstraints | fromYaml | toYaml | nindent 10 }}
labelSelector:
matchLabels:
cluster.x-k8s.io/cluster-name: {{ $.Release.Name }}
{{- end }}
{{- end }}
domain:
{{- if and .group.resources .group.resources.cpu }}
cpu:
threads: 1
cores: {{ .group.resources.cpu }}
sockets: 1
{{- end }}
devices:
{{- if .group.gpus }}
gpus:
{{- range $i, $gpu := .group.gpus }}
- name: gpu{{ add $i 1 }}
deviceName: {{ $gpu.name }}
{{- end }}
{{- end }}
disks:
- name: system
disk:
bus: virtio
pciAddress: 0000:07:00.0
blockSize:
custom:
logical: 512
physical: 4096
interfaces:
- name: default
bridge: {}
{{- if and .group.resources .group.resources.memory }}
memory:
guest: {{ .group.resources.memory }}
{{- end }}
resources:
{{/* 2Gi is enough: persistent DataVolumes are not counted as pod ephemeral storage */}}
{{- include "cozy-lib.resources.sanitize" (list (dict "ephemeral-storage" "2Gi") $) | nindent 14 }}
evictionStrategy: External
volumes:
- name: system
dataVolume:
name: disk-system
networks:
- name: default
pod: {}
{{- end }}
{{- if not $etcd }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-awaiting-etcd
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/name: kubernetes
app.kubernetes.io/instance: {{ .Release.Name }}
data:
status: "awaiting-etcd"
message: |
No DataStore is available for this tenant Kubernetes cluster. The parent
Tenant application has not populated _namespace.etcd. Set spec.etcd: true
on an ancestor Tenant (usually tenant-root) and wait for its HelmRelease
to reconcile - this HelmRelease will pick up the DataStore on its next
5m reconcile loop and provision the cluster.
{{- else }}
{{- /* Validate user-supplied apiServer.extraVolumes / extraVolumeMounts before
they are wired into the control-plane Deployment and apiserver container.
The KamajiControlPlane -> TenantControlPlane Deployment runs on the
MANAGEMENT cluster (in the tenant namespace), so volumes declared here
land on a management-cluster pod. To preserve tenant<->management
isolation we deny by default and allow only the ConfigMap/Secret sources
that satisfy the intended use case (mounting an AuthenticationConfiguration
file). Host-reaching sources (hostPath, csi, nfs, persistentVolumeClaim)
and token-projection sources (projected) are rejected — a tenant with
self-service access to the Kubernetes CR must not be able to mount
management-node paths or project arbitrary service-account tokens into
the apiserver pod.
Names must be unique and non-empty: the chart injects two reserved
volumes (talos-ca, talos-tls-cert), and a duplicate or empty volume name
would render an invalid podspec the apiserver rejects with an opaque,
apply-time error invisible to GitOps. Mounts may only reference a volume
the user declared in extraVolumes — the chart-managed talos secret
volumes are deliberately not mountable. */}}
{{- $allowedVolumeSources := list "configMap" "secret" }}
{{- $reservedVolumeNames := list "talos-ca" "talos-tls-cert" }}
{{- $userVolumeNames := list }}
{{- range $i, $vol := .Values.controlPlane.apiServer.extraVolumes }}
{{- $volName := $vol.name | default "" | toString }}
{{- if eq $volName "" }}
{{- fail (printf "controlPlane.apiServer.extraVolumes[%d]: every volume must set a non-empty name" $i) }}
{{- end }}
{{- if has $volName $reservedVolumeNames }}
{{- fail (printf "controlPlane.apiServer.extraVolumes: volume name %q is reserved by the chart for the talos control-plane secrets — rename your volume to avoid a duplicate volume name in the control-plane Deployment" $volName) }}
{{- end }}
{{- if has $volName $userVolumeNames }}
{{- fail (printf "controlPlane.apiServer.extraVolumes: duplicate volume name %q — each extra volume must have a unique name" $volName) }}
{{- end }}
{{- $userVolumeNames = append $userVolumeNames $volName }}
{{- $sources := without (keys $vol) "name" | sortAlpha }}
{{- if ne (len $sources) 1 }}
{{- fail (printf "controlPlane.apiServer.extraVolumes: volume %q must declare exactly one volume source, got %d (%v)" $volName (len $sources) $sources) }}
{{- end }}
{{- range $source := $sources }}
{{- if not (has $source $allowedVolumeSources) }}
{{- fail (printf "controlPlane.apiServer.extraVolumes: volume %q uses a %q source, which is not permitted on a management-cluster control-plane pod — only configMap and secret sources are allowed" $volName $source) }}
{{- end }}
{{- end }}
{{- end }}
{{- range $i, $mount := .Values.controlPlane.apiServer.extraVolumeMounts }}
{{- $mountName := $mount.name | default "" | toString }}
{{- if eq $mountName "" }}
{{- fail (printf "controlPlane.apiServer.extraVolumeMounts[%d]: every mount must set a non-empty name" $i) }}
{{- end }}
{{- if not (has $mountName $userVolumeNames) }}
{{- fail (printf "controlPlane.apiServer.extraVolumeMounts: mount %q references no volume declared in controlPlane.apiServer.extraVolumes — the chart-managed talos volumes cannot be mounted" $mountName) }}
{{- end }}
{{- end }}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
spec:
clusterNetwork:
pods:
cidrBlocks:
- {{ $podCIDR }}
services:
cidrBlocks:
- {{ $serviceCIDR }}
controlPlaneRef:
namespace: {{ .Release.Namespace }}
apiVersion: controlplane.cluster.x-k8s.io/v1alpha1
kind: KamajiControlPlane
name: {{ .Release.Name }}
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtCluster
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
---
apiVersion: controlplane.cluster.x-k8s.io/v1alpha1
kind: KamajiControlPlane
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
labels:
cluster.x-k8s.io/role: control-plane
annotations:
kamaji.clastix.io/kubeconfig-secret-key: "super-admin.svc"
{{- /*
OIDC wiring for `spec.oidc.mode` ≠ None:
- Inject `--authentication-config=/etc/kubernetes/authentication-config/config.yaml`
into the kube-apiserver extraArgs.
- Mount the per-release Secret carrying the structured
AuthenticationConfiguration at that path.
- Add the Secret as an extraVolume on the KCP Deployment.
The OIDC-managed flag and volume are kept ORTHOGONAL to the
user-supplied controlPlane.apiServer.extraArgs / extraVolumes /
extraVolumeMounts knobs — the user fields are preserved verbatim
and the OIDC additions are appended. The OIDC mount name
`authentication-config` is reserved by the chart; a user-supplied
volume reusing it would conflict in the rendered podSpec.
For mode=CustomConfig+secretRef, the user-owned Secret is mounted
directly (the chart does not copy the contents). Otherwise the
chart-owned `<release>-oidc-authn-config` Secret is mounted.
*/}}
{{- $oidcEnabled := ne .Values.oidc.mode "None" }}
{{- $oidcAuthnSecret := printf "%s-oidc-authn-config" .Release.Name }}
{{- $customSecretRefName := dig "customConfig" "secretRef" "name" "" .Values.oidc }}
{{- if and (eq .Values.oidc.mode "CustomConfig") (ne $customSecretRefName "") }}
{{- $oidcAuthnSecret = $customSecretRefName }}
{{- end }}
{{- if and $oidcEnabled (has "authentication-config" $userVolumeNames) }}
{{- fail "controlPlane.apiServer.extraVolumes: volume name \"authentication-config\" is reserved by the chart for OIDC AuthenticationConfiguration when spec.oidc.mode is not None — rename your volume." }}
{{- end }}
{{- /*
Legacy `--oidc-*` flags in the user-supplied extraArgs are mutually
exclusive with `--authentication-config`. The kube-apiserver refuses
to boot when both are set (`--authentication-config cannot be used with
any of --oidc-*`), so an existing cluster that previously configured
OIDC by hand via the user extra*-passthrough would BOOT-FAIL on upgrade
as soon as `spec.oidc.mode` is toggled to `System` or `CustomConfig`.
Fail the chart render with an actionable message instead.
When `spec.oidc.mode: None`, the user is free to keep --oidc-* flags
in their extraArgs (the chart does not touch them) — that path is
preserved for backward compatibility.
*/}}
{{- if $oidcEnabled }}
{{- range $arg := (.Values.controlPlane.apiServer.extraArgs | default list) }}
{{- if hasPrefix "--oidc-" $arg }}
{{- fail (printf "controlPlane.apiServer.extraArgs contains %q while spec.oidc.mode is %q — the kube-apiserver refuses to boot with both --authentication-config (injected by spec.oidc) and legacy --oidc-* flags. Remove the --oidc-* flags from controlPlane.apiServer.extraArgs and use spec.oidc.mode: CustomConfig with a customConfig.config carrying the same issuer/audience if you need to override, or spec.oidc.mode: System for the platform cozy default." $arg $.Values.oidc.mode) }}
{{- end }}
{{- if hasPrefix "--authentication-config" $arg }}
{{- fail (printf "controlPlane.apiServer.extraArgs contains %q while spec.oidc.mode is %q — the chart already injects --authentication-config= for OIDC. Drop your explicit flag and let spec.oidc.mode: CustomConfig own the AuthenticationConfiguration (customConfig.config or customConfig.secretRef.name), or leave spec.oidc.mode: None and keep managing the flag yourself." $arg $.Values.oidc.mode) }}
{{- end }}
{{- end }}
{{- end }}
spec:
apiServer:
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.controlPlane.apiServer.resourcesPreset .Values.controlPlane.apiServer.resources $) | nindent 6 }}
{{- /*
extraArgs and extraVolumeMounts are ALWAYS emitted (empty array when
nothing to inject). Kamaji's KamajiControlPlane is a CRD and Helm
applies JSON-merge-patch to CRDs, which for arrays REPLACES the whole
value. If we omitted the field for `oidc.mode: None` after previously
rendering it under `System`, JSON-merge-patch would leave the live
array untouched — the tenant apiserver would keep the stale
--authentication-config flag pointing at a Secret that no longer
exists, and would refuse to start on the next kubelet restart.
Rendering the empty array on the "off" path forces Helm to send a
REPLACE patch that clears the stale value.
*/}}
extraArgs:
{{- with .Values.controlPlane.apiServer.extraArgs }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- if $oidcEnabled }}
- --authentication-config=/etc/kubernetes/authentication-config/config.yaml
{{- end }}
{{- if not (or .Values.controlPlane.apiServer.extraArgs $oidcEnabled) }} []{{ end }}
extraVolumeMounts:
{{- with .Values.controlPlane.apiServer.extraVolumeMounts }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- if $oidcEnabled }}
- name: authentication-config
mountPath: /etc/kubernetes/authentication-config
readOnly: true
{{- end }}
{{- if not (or .Values.controlPlane.apiServer.extraVolumeMounts $oidcEnabled) }} []{{ end }}
controllerManager:
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.controlPlane.controllerManager.resourcesPreset .Values.controlPlane.controllerManager.resources $) | nindent 6 }}
scheduler:
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.controlPlane.scheduler.resourcesPreset .Values.controlPlane.scheduler.resources $) | nindent 6 }}
dataStoreName: "{{ $etcd }}"
addons:
konnectivity:
{{- $konnVersion := include "kubernetes.konnectivityVersion" $ | trim }}
{{- if $konnVersion }}
agent:
version: {{ $konnVersion }}
{{- end }}
server:
port: 8132
{{- if $konnVersion }}
version: {{ $konnVersion }}
{{- end }}
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.controlPlane.konnectivity.server.resourcesPreset .Values.controlPlane.konnectivity.server.resources $) | nindent 10 }}
kubelet:
cgroupfs: systemd
preferredAddressTypes:
- InternalIP
- ExternalIP
network:
serviceType: ClusterIP
ingress:
extraAnnotations:
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
hostname: {{ .Values.host | default (printf "%s.%s" .Release.Name $host) }}:443
className: "{{ $ingress }}"
additionalServicePorts:
- name: talos-trustd
port: 50001
targetPort: 50001
protocol: TCP
{{- /* Initial render lists only the DNS SANs because the apiserver
Service ClusterIP is not yet allocated when Helm executes the
template. The talos-reconcile main-phase Job re-patches certSANs
with the live ClusterIP once Kamaji emits the Service, and
Kamaji then re-issues the apiserver TLS cert to cover it. */}}
certSANs:
- {{ printf "%s.%s.svc" .Release.Name .Release.Namespace }}
- {{ printf "%s.%s.svc.%s" .Release.Name .Release.Namespace (include "kubernetes.tenantClusterDomain" .) }}
deployment:
podAdditionalMetadata:
labels:
policy.cozystack.io/allow-to-etcd: "true"
extraContainers:
- name: talos-csr-signer
image: "{{ default (.Files.Get "images/talos-csr-signer.tag" | trim) .Values.images.talosCsrSigner }}"
imagePullPolicy: IfNotPresent
ports:
- name: trustd
containerPort: 50001
protocol: TCP
env:
- name: TALOS_TOKEN
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-talos-secrets
key: token
resources:
requests:
cpu: 10m
memory: 32Mi
limits:
cpu: 200m
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 65532
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault
volumeMounts:
- name: talos-ca
mountPath: /etc/talos-ca
readOnly: true
- name: talos-tls-cert
mountPath: /etc/talos-server-crt
readOnly: true
extraVolumes:
- name: talos-ca
secret:
secretName: {{ .Release.Name }}-talos-ca
- name: talos-tls-cert
secret:
secretName: {{ .Release.Name }}-talos-tls-cert
{{- with .Values.controlPlane.apiServer.extraVolumes }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- if $oidcEnabled }}
- name: authentication-config
secret:
secretName: {{ $oidcAuthnSecret }}
items:
- key: config.yaml
path: config.yaml
{{- end }}
replicas: {{ .Values.controlPlane.replicas }}
version: {{ include "kubernetes.versionMap" $ }}
---
apiVersion: cozystack.io/v1alpha1
kind: WorkloadMonitor
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
spec:
replicas: 2
minReplicas: 1
kind: kubernetes
type: control-plane
selector:
kamaji.clastix.io/component: deployment
kamaji.clastix.io/name: {{ .Release.Name }}
version: {{ $.Chart.Version }}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtCluster
metadata:
annotations:
cluster.x-k8s.io/managed-by: kamaji
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
{{- range $groupName, $group := (include "kubernetes.nodeGroups" $ | fromYaml) }}
{{- /* instanceType and explicit resources are alternative sizing sources, and
explicit resources win. KubeVirt rejects a VirtualMachine that references
an instancetype while also overriding either domain.cpu or domain.memory,
so when a group is sized by resources (both cpu and memory set) the
instancetype is omitted from the VM (see the VM spec above) and the lookup
below is skipped — a stale instancetype name cannot fail an otherwise
valid, resource-sized group. Explicit resources are all-or-nothing: a
partial spec (only one of cpu/memory) would emit one domain override
alongside the instancetype, which KubeVirt rejects, so it fails here with
a clear render-time error instead of a late admission rejection. */}}
{{- $hasCpu := and $group.resources $group.resources.cpu }}
{{- $hasMem := and $group.resources $group.resources.memory }}
{{- if and $group.instanceType (or (and $hasCpu (not $hasMem)) (and $hasMem (not $hasCpu))) }}
{{- fail (printf "nodeGroup %s: set both resources.cpu and resources.memory, or neither" $groupName) }}
{{- end }}
{{/* Resolve instanceType once per group — reused for kubelet reservations and capacity annotations. */}}
{{- $instanceType := dict }}
{{- if and $group.instanceType (not (and $hasCpu $hasMem)) }}
{{- $instanceType = (lookup "instancetype.kubevirt.io/v1beta1" "VirtualMachineClusterInstancetype" "" $group.instanceType) }}
{{- if not $instanceType }}
{{- fail (printf "nodeGroup %s: specified instanceType %q not found in cluster" $groupName $group.instanceType) }}
{{- end }}
{{- end }}
{{/* Compute kubelet reservations: explicit resources.memory/cpu wins over instanceType spec.
Auto-computed system/kube reserved memory = 5% of effective memory, clamped to [256Mi, 1Gi].
Auto-computed system/kube reserved CPU = 5% of effective CPU, clamped to [50m, 500m]. */}}
{{- $effectiveMemory := "" }}
{{- if and $group.resources $group.resources.memory }}
{{- $effectiveMemory = $group.resources.memory | toString }}
{{- else if and $instanceType $instanceType.spec $instanceType.spec.memory $instanceType.spec.memory.guest }}
{{- $effectiveMemory = $instanceType.spec.memory.guest | toString }}
{{- end }}
{{- $effectiveCpu := "" }}
{{- if and $group.resources $group.resources.cpu }}
{{- $effectiveCpu = $group.resources.cpu | toString }}
{{- else if and $instanceType $instanceType.spec $instanceType.spec.cpu $instanceType.spec.cpu.guest }}
{{- $effectiveCpu = $instanceType.spec.cpu.guest | toString }}
{{- end }}
{{- $autoReservedMi := 256 }}
{{- if $effectiveMemory }}
{{- $effectiveMemMi := divf (include "cozy-lib.resources.toFloat" $effectiveMemory | float64) 1048576.0 | int }}
{{- $fivePercentMi := mulf ($effectiveMemMi | float64) 0.05 | int }}
{{- $autoReservedMi = min (max $fivePercentMi 256) 1024 }}
{{- end }}
{{- $autoReservedMillicores := 50 }}
{{- if $effectiveCpu }}
{{- $effectiveCpuMillicores := include "kubernetes.cpuToMillicores" $effectiveCpu | int }}
{{- $fivePercentMillis := mulf ($effectiveCpuMillicores | float64) 0.05 | int }}
{{- $autoReservedMillicores = min (max $fivePercentMillis 50) 500 }}
{{- end }}
{{- $kubeletOverride := $group.kubelet | default dict }}
{{- $systemReservedMemory := $kubeletOverride.systemReservedMemory | default (printf "%dMi" $autoReservedMi) }}
{{- $kubeReservedMemory := $kubeletOverride.kubeReservedMemory | default (printf "%dMi" $autoReservedMi) }}
{{- $systemReservedCpu := $kubeletOverride.systemReservedCpu | default (printf "%dm" $autoReservedMillicores) }}
{{- $kubeReservedCpu := $kubeletOverride.kubeReservedCpu | default (printf "%dm" $autoReservedMillicores) }}
{{- $evictionHardMemory := $kubeletOverride.evictionHardMemory | default "7%" }}
{{- $evictionSoftMemory := $kubeletOverride.evictionSoftMemory | default "10%" }}
{{/* Validate reservation field formats.
These guards check the USER-SUPPLIED value (from values.yaml via
$kubeletOverride), not the resolved/computed default — the default is
always valid by construction. The eviction threshold validation below
differs: it validates the RESOLVED values (user-supplied or default). */}}
{{- $validations := list
(dict "key" "systemReservedMemory" "value" $kubeletOverride.systemReservedMemory "pattern" `^[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?(Ki|Mi|Gi|Ti|Pi|Ei|k|M|G|T|P|E)?$` "hint" "a valid Kubernetes memory quantity (e.g. 128Mi, 1Gi, 1e9, 500e6)")
(dict "key" "kubeReservedMemory" "value" $kubeletOverride.kubeReservedMemory "pattern" `^[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?(Ki|Mi|Gi|Ti|Pi|Ei|k|M|G|T|P|E)?$` "hint" "a valid Kubernetes memory quantity (e.g. 128Mi, 1Gi, 1e9, 500e6)")
(dict "key" "systemReservedCpu" "value" $kubeletOverride.systemReservedCpu "pattern" `^([0-9]+m|[0-9]+(\.[0-9]+)?)$` "hint" "a valid Kubernetes CPU quantity (integer millicores like 100m, or decimal cores like 0.5, 1)")
(dict "key" "kubeReservedCpu" "value" $kubeletOverride.kubeReservedCpu "pattern" `^([0-9]+m|[0-9]+(\.[0-9]+)?)$` "hint" "a valid Kubernetes CPU quantity (integer millicores like 100m, or decimal cores like 0.5, 1)")
}}
{{- range $validations }}
{{- if and .value (not (regexMatch .pattern (.value | toString))) }}
{{- fail (printf "nodeGroup %s: invalid %s value %q — must be %s" $groupName .key (.value | toString) .hint) }}
{{- end }}
{{- end }}
{{/* Validate that user-supplied reservation values are positive (non-zero) */}}
{{- range $_, $entry := list (dict "key" "systemReservedMemory" "value" $kubeletOverride.systemReservedMemory) (dict "key" "kubeReservedMemory" "value" $kubeletOverride.kubeReservedMemory) }}
{{- if $entry.value }}
{{- $bytes := include "cozy-lib.resources.toFloat" ($entry.value | toString) | float64 }}
{{- if le $bytes 0.0 }}
{{- fail (printf "nodeGroup %s: %s must be a positive value, got %s" $groupName $entry.key ($entry.value | toString)) }}
{{- end }}
{{- end }}
{{- end }}
{{- range $_, $entry := list (dict "key" "systemReservedCpu" "value" $kubeletOverride.systemReservedCpu) (dict "key" "kubeReservedCpu" "value" $kubeletOverride.kubeReservedCpu) }}
{{- if $entry.value }}
{{- $cpuMillis := include "kubernetes.cpuToMillicores" $entry.value | float64 }}
{{- if le $cpuMillis 0.0 }}
{{- fail (printf "nodeGroup %s: %s must be a positive value, got %s" $groupName $entry.key ($entry.value | toString)) }}
{{- end }}
{{- end }}
{{- end }}
{{/* Validate absolute eviction threshold formats before converting */}}
{{- if not (hasSuffix "%" $evictionHardMemory) }}
{{- if not (regexMatch `^[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?(Ki|Mi|Gi|Ti|Pi|Ei|k|M|G|T|P|E)?$` $evictionHardMemory) }}
{{- fail (printf "nodeGroup %s: invalid evictionHardMemory value %q — must be a percentage (e.g. 7%%) or a valid Kubernetes memory quantity (e.g. 500Mi, 1Gi, 1e9)" $groupName $evictionHardMemory) }}
{{- end }}
{{- end }}
{{- if not (hasSuffix "%" $evictionSoftMemory) }}
{{- if not (regexMatch `^[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?(Ki|Mi|Gi|Ti|Pi|Ei|k|M|G|T|P|E)?$` $evictionSoftMemory) }}
{{- fail (printf "nodeGroup %s: invalid evictionSoftMemory value %q — must be a percentage (e.g. 10%%) or a valid Kubernetes memory quantity (e.g. 500Mi, 1Gi, 1e9)" $groupName $evictionSoftMemory) }}
{{- end }}
{{- end }}
{{- if and (hasSuffix "%" $evictionHardMemory) (hasSuffix "%" $evictionSoftMemory) }}
{{- $hardPctStr := trimSuffix "%" $evictionHardMemory }}
{{- $softPctStr := trimSuffix "%" $evictionSoftMemory }}
{{- if not (regexMatch `^[0-9]+(\.[0-9]+)?$` $hardPctStr) }}
{{- fail (printf "nodeGroup %s: evictionHardMemory percentage value %q is not a valid number" $groupName $hardPctStr) }}
{{- end }}
{{- if not (regexMatch `^[0-9]+(\.[0-9]+)?$` $softPctStr) }}
{{- fail (printf "nodeGroup %s: evictionSoftMemory percentage value %q is not a valid number" $groupName $softPctStr) }}
{{- end }}
{{- $hardPct := $hardPctStr | float64 }}
{{- $softPct := $softPctStr | float64 }}
{{- if le $hardPct 0.0 }}
{{- fail (printf "nodeGroup %s: evictionHardMemory percentage must be greater than 0 and at most 100, got %s%%" $groupName $hardPctStr) }}
{{- end }}
{{- if gt $hardPct 100.0 }}
{{- fail (printf "nodeGroup %s: evictionHardMemory percentage must be greater than 0 and at most 100, got %s%%" $groupName $hardPctStr) }}
{{- end }}
{{- if le $softPct 0.0 }}
{{- fail (printf "nodeGroup %s: evictionSoftMemory percentage must be greater than 0 and at most 100, got %s%%" $groupName $softPctStr) }}
{{- end }}
{{- if gt $softPct 100.0 }}
{{- fail (printf "nodeGroup %s: evictionSoftMemory percentage must be greater than 0 and at most 100, got %s%%" $groupName $softPctStr) }}
{{- end }}
{{- if ge $hardPct $softPct }}
{{- fail (printf "nodeGroup %s: evictionHardMemory (%s) must be strictly less than evictionSoftMemory (%s)" $groupName $evictionHardMemory $evictionSoftMemory) }}
{{- end }}
{{- else if and (not (hasSuffix "%" $evictionHardMemory)) (not (hasSuffix "%" $evictionSoftMemory)) }}
{{- $hardBytes := include "cozy-lib.resources.toFloat" $evictionHardMemory | float64 }}
{{- $softBytes := include "cozy-lib.resources.toFloat" $evictionSoftMemory | float64 }}
{{- if ge $hardBytes $softBytes }}
{{- fail (printf "nodeGroup %s: evictionHardMemory (%s) must be strictly less than evictionSoftMemory (%s)" $groupName $evictionHardMemory $evictionSoftMemory) }}
{{- end }}
{{- else }}
{{- fail (printf "nodeGroup %s: evictionHardMemory (%s) and evictionSoftMemory (%s) must use the same unit type (both percentage or both absolute)" $groupName $evictionHardMemory $evictionSoftMemory) }}
{{- end }}
{{/* Resolve eviction hard threshold to bytes for arithmetic.
Percentage is relative to effective node memory; absolute values are used as-is. */}}
{{- $evictionHardBytes := 0.0 }}
{{- if $effectiveMemory }}
{{- if hasSuffix "%" $evictionHardMemory }}
{{- $evictionPct := trimSuffix "%" $evictionHardMemory | float64 }}
{{- $evictionHardBytes = mulf (include "cozy-lib.resources.toFloat" $effectiveMemory | float64) (divf $evictionPct 100.0) }}
{{- else }}
{{- $evictionHardBytes = include "cozy-lib.resources.toFloat" $evictionHardMemory | float64 }}
{{- end }}
{{- end }}
{{/* Validate that total reserved memory (system + kube + eviction) does not exceed effective node memory */}}
{{- if $effectiveMemory }}
{{- $sysBytes := include "cozy-lib.resources.toFloat" $systemReservedMemory | float64 }}
{{- $kubeBytes := include "cozy-lib.resources.toFloat" $kubeReservedMemory | float64 }}
{{- $totalReservedBytes := addf (addf $sysBytes $kubeBytes) $evictionHardBytes }}
{{- $effectiveMemBytes := include "cozy-lib.resources.toFloat" $effectiveMemory | float64 }}
{{- if ge $totalReservedBytes $effectiveMemBytes }}
{{- fail (printf "nodeGroup %s: total reserved memory (systemReservedMemory=%s + kubeReservedMemory=%s + evictionHardMemory=%s) must be less than effective node memory (%s)" $groupName $systemReservedMemory $kubeReservedMemory $evictionHardMemory $effectiveMemory) }}
{{- end }}
{{- end }}
{{/* Validate that total reserved CPU does not exceed effective node CPU */}}
{{- if $effectiveCpu }}
{{- $sysCpuMillis := include "kubernetes.cpuToMillicores" $systemReservedCpu | float64 }}
{{- $kubeCpuMillis := include "kubernetes.cpuToMillicores" $kubeReservedCpu | float64 }}
{{- $totalCpuMillis := addf $sysCpuMillis $kubeCpuMillis }}
{{- $effectiveCpuMillicoresV := include "kubernetes.cpuToMillicores" $effectiveCpu | int }}
{{- $effectiveCpuMillis := float64 $effectiveCpuMillicoresV }}
{{- if ge $totalCpuMillis $effectiveCpuMillis }}
{{- fail (printf "nodeGroup %s: total reserved CPU (systemReservedCpu=%s + kubeReservedCpu=%s) must be less than effective node CPU (%s cores)" $groupName $systemReservedCpu $kubeReservedCpu $effectiveCpu) }}
{{- end }}
{{- end }}
{{/* Guard: explicit kubelet overrides require effective memory for validation */}}
{{- if not $effectiveMemory }}
{{- $hasOverride := or $kubeletOverride.systemReservedMemory $kubeletOverride.kubeReservedMemory $kubeletOverride.evictionHardMemory $kubeletOverride.evictionSoftMemory }}
{{- if $hasOverride }}
{{- fail (printf "nodeGroup %s: kubelet memory reservations require effective memory to validate — set resources.memory or instanceType" $groupName) }}
{{- end }}
{{- end }}
{{/* Guard: explicit kubelet CPU overrides require effective CPU for validation */}}
{{- if not $effectiveCpu }}
{{- $hasCpuOverride := or $kubeletOverride.systemReservedCpu $kubeletOverride.kubeReservedCpu }}
{{- if $hasCpuOverride }}
{{- fail (printf "nodeGroup %s: cannot validate kubelet CPU reservations without effective CPU — set resources.cpu or a valid instanceType" $groupName) }}
{{- end }}
{{- end }}
---
{{- /* TalosConfigTemplate is no longer rendered here — the chart cannot
produce a valid Talos worker machineconfig at Helm template time
because three of the inputs (apiserver Service ClusterIP, Talos
CA from cert-manager, Kamaji-issued tenant CA) are created
asynchronously after Helm applies this manifest. The main-phase
Job in templates/talos/talos-reconcile-job.yaml waits for those
inputs and produces the TalosConfigTemplate with a
KamajiControlPlane ownerReference for natural GC. That Job runs in
the main install phase, so it applies the template as soon as the
inputs appear — in parallel with the rest of the install. The
MachineDeployment below still references the TCT name; CAPI's
Machine controller blocks on its absence and unblocks the moment
the Job applies it. */}}
---
{{- $context := deepCopy $ }}
{{- $_ := set $context "group" $group }}
{{- $_ := set $context "groupName" $groupName }}
{{- $kubevirtmachinetemplate := include "kubevirtmachinetemplate" $context }}
{{- $kubevirtmachinetemplateHash := $kubevirtmachinetemplate | sha256sum | trunc 6 }}
{{- $kubevirtmachinetemplateName := printf "%s-%s-%s" $.Release.Name $groupName $kubevirtmachinetemplateHash }}
{{- $kubevirtmachinetemplateNames = append $kubevirtmachinetemplateNames $kubevirtmachinetemplateName }}
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtMachineTemplate
metadata:
name: {{ $.Release.Name }}-{{ $groupName }}-{{ $kubevirtmachinetemplateHash }}
namespace: {{ $.Release.Namespace }}
spec:
template:
{{- $kubevirtmachinetemplate | nindent 4 }}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
name: {{ $.Release.Name }}-{{ $groupName }}
namespace: {{ $.Release.Namespace }}
annotations:
cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "{{ $group.minReplicas }}"
cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "{{ $group.maxReplicas }}"
{{- if $effectiveMemory }}
{{- $sysBytes := include "cozy-lib.resources.toFloat" $systemReservedMemory | float64 }}
{{- $kubeBytes := include "cozy-lib.resources.toFloat" $kubeReservedMemory | float64 }}
{{- $totalReservedBytes := addf (addf $sysBytes $kubeBytes) $evictionHardBytes }}
{{- $allocatableBytes := subf (include "cozy-lib.resources.toFloat" $effectiveMemory | float64) $totalReservedBytes }}
{{- $allocatableMi := divf $allocatableBytes 1048576.0 | floor }}
capacity.cluster-autoscaler.kubernetes.io/memory: "{{ $allocatableMi }}Mi"
{{- end }}
{{- if $effectiveCpu }}
{{- $sysCpuMillisA := include "kubernetes.cpuToMillicores" $systemReservedCpu | float64 }}
{{- $kubeCpuMillisA := include "kubernetes.cpuToMillicores" $kubeReservedCpu | float64 }}
{{- $effectiveCpuMillicoresA := include "kubernetes.cpuToMillicores" $effectiveCpu | int }}
{{- $effectiveCpuMillisA := float64 $effectiveCpuMillicoresA }}
{{- $allocatableCpuMillis := subf $effectiveCpuMillisA (addf $sysCpuMillisA $kubeCpuMillisA) }}
{{- $allocatableCpuMillisInt := $allocatableCpuMillis | ceil | int }}
capacity.cluster-autoscaler.kubernetes.io/cpu: "{{ $allocatableCpuMillisInt }}m"
{{- end }}
spec:
clusterName: {{ $.Release.Name }}
# `spec.replicas` is intentionally omitted so the field is owned by
# the cluster-autoscaler alone. Two independent CAPI mechanisms —
# not Server-Side-Apply field managers — carry the guarantee:
# 1. Create: the MachineDeployment defaulting webhook seeds
# `spec.replicas` from the `cluster-api-autoscaler-node-group-
# min-size` annotation (see
# https://cluster-api.sigs.k8s.io/tasks/automated-machine-management/autoscaling).
# 2. Update: `calculateMachineDeploymentReplicas` preserves the
# existing live value (`oldMD.Spec.Replicas`) whenever the
# incoming spec has `replicas: nil`, clamping into
# `[min, max]` if it drifts outside — so a cluster the
# autoscaler holds above min-size is not drained by a
# `helm upgrade` that would otherwise re-render this field.
# Flux helm-controller applies this chart through the Helm SDK
# three-way merge (not SSA), so field-manager ownership is not the
# mechanism at play. The chart guarantee reduces to "leave the
# field out of the rendered manifest and let CAPI's update-time
# defaulting keep the live value stable". Emitting a chart-managed
# `replicas: N` here (as this chart did before
# cozystack/cozystack#3231) drains workers on every `helm upgrade`
# action until the autoscaler notices unschedulable Pods and
# scales back up — a real disruption window on every routine
# platform bump.
strategy:
rollingUpdate:
maxSurge: {{ $group.maxReplicas }}
maxUnavailable: 1
type: RollingUpdate
selector:
matchLabels:
cluster.x-k8s.io/cluster-name: {{ $.Release.Name }}
cluster.x-k8s.io/deployment-name: {{ $.Release.Name }}-{{ $groupName }}
template:
metadata:
labels:
cluster.x-k8s.io/cluster-name: {{ $.Release.Name }}
cluster.x-k8s.io/deployment-name: {{ $.Release.Name }}-{{ $groupName }}
{{- range $group.roles }}
node-role.kubernetes.io/{{ . }}: ""
{{- end }}
spec:
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
kind: TalosConfigTemplate
name: {{ $.Release.Name }}-{{ $groupName }}
namespace: {{ $.Release.Namespace }}
clusterName: {{ $.Release.Name }}
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtMachineTemplate
name: {{ $.Release.Name }}-{{ $groupName }}-{{ $kubevirtmachinetemplateHash }}
namespace: {{ $.Release.Namespace }}
version: {{ include "kubernetes.versionMap" $}}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineHealthCheck
metadata:
name: {{ $.Release.Name }}-{{ $groupName }}
namespace: {{ $.Release.Namespace }}
spec:
clusterName: {{ $.Release.Name }}
{{- /* MHC spec.maxUnhealthy is an IntOrString. CAPI admission accepts a
bare integer (0, 1, ...) or a percentage string ("0%", "50%"), but
rejects a quoted plain integer ("0"). Quote only when the operator
supplied a percentage; otherwise render the value as a bare int so
the admission webhook is happy with the chart-default "0". A node
group may override the cluster-wide nodeHealthCheck via
nodeGroups.<name>.maxUnhealthy / .nodeStartupTimeout. */}}
{{- $maxUnhealthy := toString $.Values.nodeHealthCheck.maxUnhealthy }}
{{- $muSource := "nodeHealthCheck.maxUnhealthy" }}
{{- if hasKey $group "maxUnhealthy" }}
{{- $maxUnhealthy = toString $group.maxUnhealthy }}
{{- $muSource = printf "nodeGroups.%s.maxUnhealthy" $groupName }}
{{- end }}
{{- if hasSuffix "%" $maxUnhealthy }}
{{- if not (regexMatch "^[0-9]+%$" $maxUnhealthy) }}
{{- fail (printf "%s must be a bare integer (e.g. 0, 1) or an integer percentage (e.g. 50%%), got %q" $muSource $maxUnhealthy) }}
{{- end }}
maxUnhealthy: {{ $maxUnhealthy | quote }}
{{- else if regexMatch "^[0-9]+$" $maxUnhealthy }}
maxUnhealthy: {{ $maxUnhealthy | int }}
{{- else }}
{{- fail (printf "%s must be a bare integer (e.g. 0, 1) or an integer percentage (e.g. 50%%), got %q" $muSource $maxUnhealthy) }}
{{- end }}
{{- $nodeStartupTimeout := $.Values.nodeHealthCheck.nodeStartupTimeout }}
{{- if hasKey $group "nodeStartupTimeout" }}{{ $nodeStartupTimeout = $group.nodeStartupTimeout }}{{ end }}
nodeStartupTimeout: {{ $nodeStartupTimeout }}
selector:
matchLabels:
cluster.x-k8s.io/cluster-name: {{ $.Release.Name }}
cluster.x-k8s.io/deployment-name: {{ $.Release.Name }}-{{ $groupName }}
unhealthyConditions:
- type: Ready
status: Unknown
timeout: 30s
- type: Ready
status: "False"
timeout: 300s
---
apiVersion: cozystack.io/v1alpha1
kind: WorkloadMonitor
metadata:
name: {{ $.Release.Name }}-{{ $groupName }}
namespace: {{ $.Release.Namespace }}
spec:
minReplicas: {{ $group.minReplicas }}
kind: kubernetes
type: worker
selector:
cluster.x-k8s.io/cluster-name: {{ $.Release.Name }}
cluster.x-k8s.io/deployment-name: {{ $.Release.Name }}-{{ $groupName }}
cluster.x-k8s.io/role: worker
version: {{ $.Chart.Version }}
{{- end }}
---
{{- /*
We must preserve all previous KubevirtMachineTemplates until a MachineSet references them.
*/ -}}
{{- $mss := (lookup "cluster.x-k8s.io/v1beta1" "MachineSet" $.Release.Namespace "").items }}
{{- $oldKubevirtmachinetemplates := dict }}
{{- range $kmt := (lookup "infrastructure.cluster.x-k8s.io/v1alpha1" "KubevirtMachineTemplate" .Release.Namespace "").items }}
{{- range $or := $kmt.metadata.ownerReferences }}
{{- /* Only re-emit KubevirtMachineTemplates that belong to THIS release. The
Cluster ownerReference alone is not enough: worker pools split out into
kubernetes-nodes releases share the same CAPI Cluster ownerReference, so
without the release-name scoping this block would re-emit a pool's KMT
(annotated meta.helm.sh/release-name=kubernetes-nodes-<cluster>-<pool>)
and the next upgrade of this release would fail Helm ownership
validation. */}}
{{- if and (eq $or.kind "Cluster") (eq $or.name $.Release.Name) (eq (dig "annotations" "meta.helm.sh/release-name" "" $kmt.metadata) $.Release.Name) }}
{{- range $ms := $mss }}
{{- if and (eq $ms.spec.template.spec.infrastructureRef.kind "KubevirtMachineTemplate") (eq $ms.spec.template.spec.infrastructureRef.name $kmt.metadata.name) }}
{{- if not (has $kmt.metadata.name $kubevirtmachinetemplateNames) }}
{{- $oldKubevirtmachinetemplates = merge $oldKubevirtmachinetemplates (dict $kmt.metadata.name $kmt) }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- range $oldKubevirtmachinetemplates }}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtMachineTemplate
metadata:
name: {{ .metadata.name }}
namespace: {{ .metadata.Namespace }}
spec:
{{- .spec | toYaml | nindent 2 }}
{{- end }}
{{- end }}