Skip to content

Commit a23e843

Browse files
committed
feat(kubernetes): expose the control plane admission controllers
The tenant control plane now owns --enable-admission-plugins and drops an extraArgs entry naming it, which the chart refuses to render. That left an operator who had set admission plugins through extraArgs with nowhere to move them. The KamajiControlPlane already carries the list the control plane renders into that flag, so pass it through from the tenant values and point the refusal at it. The list is rendered only when it is non-empty: left out, the control plane keeps its own default set, and a tenant that sets nothing renders exactly as before. A non-empty list replaces that default rather than adding to it, which is also what the extraArgs entry did under the previous control plane build. Names are validated by the KamajiControlPlane CRD, so the chart schema carries no copy of them. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 565635d commit a23e843

8 files changed

Lines changed: 66 additions & 6 deletions

File tree

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

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

‎api/apps/v1alpha1/kubernetes/zz_generated.deepcopy.go‎

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

‎packages/apps/kubernetes/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ See the reference for components utilized in this service:
166166
| `controlPlane.apiServer.resources.memory` | Memory (RAM) available. | `quantity` | `""` |
167167
| `controlPlane.apiServer.resourcesPreset` | Preset if `resources` omitted. | `string` | `c1.medium` |
168168
| `controlPlane.apiServer.extraArgs` | Extra command-line flags appended to the tenant kube-apiserver, passed through to KamajiControlPlane `spec.apiServer.extraArgs`. For OIDC use `spec.oidc.mode` — this passthrough is the escape hatch for unrelated apiserver flags. The chart refuses an entry naming any of the following flags, because the tenant control plane sets each of them itself and drops such an entry before the apiserver sees it: `--advertise-address`, `--client-ca-file`, `--enable-admission-plugins`, `--service-cluster-ip-range`, `--kubelet-client-certificate`, `--kubelet-client-key`, `--kubelet-preferred-address-types`, `--proxy-client-cert-file`, `--proxy-client-key-file`, `--requestheader-allowed-names`, `--requestheader-client-ca-file`, `--secure-port`, `--service-account-key-file`, `--service-account-signing-key-file`, `--tls-cert-file`, `--tls-private-key-file`, `--etcd-servers`, `--etcd-cafile`, `--etcd-certfile`, `--etcd-keyfile`, `--etcd-prefix`, `--etcd-compaction-interval`, `--egress-selector-config-file`. When `spec.oidc.mode` is not `None` the chart also renders OIDC flags here, reads what you have written on them, and refuses some combinations outright; `docs/oidc-tenant.md` carries which flags, which combinations, and why. Do NOT add legacy `--oidc-*` flags here when `spec.oidc.mode` is not `None`; the chart injects `--authentication-config` and the apiserver refuses to boot with both. Empty by default (no change to current behavior). | `[]string` | `[]` |
169+
| `controlPlane.apiServer.admissionControllers` | Admission plugins the tenant kube-apiserver enables, passed through to KamajiControlPlane `spec.admissionControllers`, which the control plane renders as `--enable-admission-plugins`; the KamajiControlPlane CRD validates each name. A non-empty list replaces the control plane's default set instead of adding to it. Empty by default, which keeps that default set, taken from the TenantControlPlane CRD: CertificateApproval, CertificateSigning, CertificateSubjectRestriction, DefaultIngressClass, DefaultStorageClass, DefaultTolerationSeconds, LimitRanger, MutatingAdmissionWebhook, NamespaceLifecycle, PersistentVolumeClaimResize, Priority, ResourceQuota, RuntimeClass, ServiceAccount, StorageObjectInUseProtection, TaintNodesByCondition, ValidatingAdmissionWebhook. `NodeRestriction` is not in it. | `[]string` | `[]` |
169170
| `controlPlane.apiServer.extraVolumes` | Extra volumes added to the control-plane Deployment, passed through to KamajiControlPlane `spec.deployment.extraVolumes`. Use to mount a ConfigMap or Secret holding an AuthenticationConfiguration file referenced by `extraArgs`. Each item is a core/v1 Volume, but because the control-plane pod runs on the management cluster only `configMap` and `secret` sources are allowed (host-reaching sources like `hostPath`/`csi` and token-projection via `projected` are rejected); each volume must have a unique, non-empty name and exactly one source. The names `talos-ca` and `talos-tls-cert` are reserved by the chart. Empty by default. | `[]object` | `[]` |
170171
| `controlPlane.apiServer.extraVolumeMounts` | Extra volume mounts added to the tenant kube-apiserver container, passed through to KamajiControlPlane `spec.apiServer.extraVolumeMounts`. Each `name` must reference a volume declared in `extraVolumes`; the chart-managed talos secret volumes cannot be mounted. Each item is a core/v1 VolumeMount. Empty by default. | `[]object` | `[]` |
171172
| `controlPlane.controllerManager` | Controller Manager configuration. | `object` | `{}` |

‎packages/apps/kubernetes/templates/cluster.yaml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ data:
216216
"--etcd-compaction-interval" "--egress-selector-config-file" }}
217217
{{- range $arg := .Values.controlPlane.apiServer.extraArgs | default list }}
218218
{{- $flag := index (splitList "=" (toString $arg)) 0 }}
219-
{{- if has $flag $kamajiManagedArgs }}
219+
{{- if eq $flag "--enable-admission-plugins" }}
220+
{{- fail (printf "controlPlane.apiServer.extraArgs contains %q — the tenant control plane sets --enable-admission-plugins itself, from controlPlane.apiServer.admissionControllers, and drops every entry naming it before the kube-apiserver sees the list, so this entry has no effect, and written without =value it leaves its value behind as an argument the apiserver refuses. Move the plugins to controlPlane.apiServer.admissionControllers; that list replaces the control plane's default set, as this entry used to." $arg) }}
221+
{{- else if has $flag $kamajiManagedArgs }}
220222
{{- fail (printf "controlPlane.apiServer.extraArgs contains %q — the tenant control plane sets %s itself and drops every entry naming it before the kube-apiserver sees the list, so this entry has no effect, and written without =value it leaves its value behind as an argument the apiserver refuses. Remove the entry; the description of controlPlane.apiServer.extraArgs lists every flag the control plane owns." $arg $flag) }}
221223
{{- end }}
222224
{{- end }}
@@ -713,6 +715,10 @@ spec:
713715
scheduler:
714716
resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.controlPlane.scheduler.resourcesPreset .Values.controlPlane.scheduler.resources $) | nindent 6 }}
715717
dataStoreName: "{{ $etcd }}"
718+
{{- with .Values.controlPlane.apiServer.admissionControllers }}
719+
admissionControllers:
720+
{{- toYaml . | nindent 4 }}
721+
{{- end }}
716722
addons:
717723
konnectivity:
718724
{{- $konnVersion := include "kubernetes.konnectivityVersion" $ | trim }}

‎packages/apps/kubernetes/tests/kamaji_managed_args_test.yaml‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tests:
3636
- --enable-admission-plugins=x
3737
asserts:
3838
- failedTemplate:
39-
errorPattern: '^.*extraArgs contains "--enable-admission-plugins=x" — the tenant control plane sets --enable-admission-plugins itself '
39+
errorPattern: '^.*extraArgs contains "--enable-admission-plugins=x" — the tenant control plane sets --enable-admission-plugins itself, from controlPlane.apiServer.admissionControllers, .* Move the plugins to controlPlane.apiServer.admissionControllers;'
4040

4141
- it: refuses --service-cluster-ip-range=value
4242
set:
@@ -225,7 +225,7 @@ tests:
225225
- NodeRestriction,AlwaysPullImages
226226
asserts:
227227
- failedTemplate:
228-
errorMessage: 'controlPlane.apiServer.extraArgs contains "--enable-admission-plugins" — the tenant control plane sets --enable-admission-plugins itself and drops every entry naming it before the kube-apiserver sees the list, so this entry has no effect, and written without =value it leaves its value behind as an argument the apiserver refuses. Remove the entry; the description of controlPlane.apiServer.extraArgs lists every flag the control plane owns.'
228+
errorMessage: 'controlPlane.apiServer.extraArgs contains "--enable-admission-plugins" — the tenant control plane sets --enable-admission-plugins itself, from controlPlane.apiServer.admissionControllers, and drops every entry naming it before the kube-apiserver sees the list, so this entry has no effect, and written without =value it leaves its value behind as an argument the apiserver refuses. Move the plugins to controlPlane.apiServer.admissionControllers; that list replaces the control plane''s default set, as this entry used to.'
229229

230230
- it: refuses a managed flag with spec.oidc.mode System as well
231231
values:
@@ -236,7 +236,7 @@ tests:
236236
- --enable-admission-plugins=NodeRestriction
237237
asserts:
238238
- failedTemplate:
239-
errorPattern: 'extraArgs contains "--enable-admission-plugins=NodeRestriction" — the tenant control plane sets --enable-admission-plugins itself '
239+
errorPattern: 'extraArgs contains "--enable-admission-plugins=NodeRestriction" — the tenant control plane sets --enable-admission-plugins itself, from controlPlane.apiServer.admissionControllers, '
240240

241241
- it: renders a flag the control plane only defaults, since the entry replaces the default
242242
set:
@@ -269,3 +269,38 @@ tests:
269269
- --secure-port-x=1
270270
asserts:
271271
- notFailedTemplate: {}
272+
273+
- it: points every other managed flag at the generic message, not at admissionControllers
274+
set:
275+
controlPlane.apiServer.extraArgs:
276+
- --secure-port=6444
277+
asserts:
278+
- failedTemplate:
279+
errorMessage: 'controlPlane.apiServer.extraArgs contains "--secure-port=6444" — the tenant control plane sets --secure-port itself and drops every entry naming it before the kube-apiserver sees the list, so this entry has no effect, and written without =value it leaves its value behind as an argument the apiserver refuses. Remove the entry; the description of controlPlane.apiServer.extraArgs lists every flag the control plane owns.'
280+
281+
- it: leaves spec.admissionControllers out by default, so the control plane keeps its own default set
282+
asserts:
283+
- notExists:
284+
path: spec.admissionControllers
285+
documentIndex: 1
286+
287+
- it: leaves spec.admissionControllers out for an explicitly empty list
288+
set:
289+
controlPlane.apiServer.admissionControllers: []
290+
asserts:
291+
- notExists:
292+
path: spec.admissionControllers
293+
documentIndex: 1
294+
295+
- it: renders controlPlane.apiServer.admissionControllers into spec.admissionControllers verbatim
296+
set:
297+
controlPlane.apiServer.admissionControllers:
298+
- NodeRestriction
299+
- AlwaysPullImages
300+
asserts:
301+
- equal:
302+
path: spec.admissionControllers
303+
value:
304+
- NodeRestriction
305+
- AlwaysPullImages
306+
documentIndex: 1

0 commit comments

Comments
 (0)