Files
cozystack/packages/system/cozystack-controller/templates/webhooks.yaml
Aleksei Sviridkin 91f922d380 feat(cozystack-controller): serve the GPU webhooks with GPU enabled
The GPU admission webhooks need a Service, a serving certificate and
webhook configurations, and the binder's metrics need a port a scrape
can reach. All of it renders only with GPU enabled, which the platform
sets where KubeVirt serves GPUs, so clusters without KubeVirt change
nothing.

The webhooks fail closed. The two mutating ones select only VMIs and
virt-launcher pods carrying the device-reference label, the pod webhook
also requiring the virt-launcher label, so of VMIs and pods a
controller outage blocks only the start of VMs with device references;
the GPUDevice webhook blocks new orders as well. The controller then
runs two replicas behind a PDB, since a single fail-closed replica
would block those starts on every rollout.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-10-21 13:31:26 +03:00

92 lines
3.1 KiB
YAML

{{- if (.Values.cozystackController.gpu).enabled }}
{{- $namespaceSelector := dict "matchExpressions" (list
(dict "key" "cozystack.io/system" "operator" "NotIn" "values" (list "true"))
(dict "key" "kubernetes.io/metadata.name" "operator" "NotIn" "values" (list "kube-system" "default"))) }}
# Both mutating webhooks select only objects carrying the device-reference
# label, so of VMIs and pods an outage of the controller blocks only the
# start of VMs with device references; the validating webhook below also
# blocks new GPUDevice orders. The name sorts before virt-api-mutator, so
# KubeVirt's own mutator sees the gpus entries too.
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: cozystack-gpu
annotations:
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/cozystack-controller-webhook
webhooks:
- name: vmi.gpu.cozystack.io
admissionReviewVersions: ["v1"]
# Creates template devices and attaches devices, but not on a dry run.
sideEffects: NoneOnDryRun
# The handler waits at most 10s for the binder; the API server calls it
# again after virt-api's mutator, within one 60s request deadline.
timeoutSeconds: 15
failurePolicy: Fail
reinvocationPolicy: IfNeeded
clientConfig:
service:
name: cozystack-controller-webhook
namespace: {{ .Release.Namespace }}
path: /gpu/mutate-vmi
rules:
- operations: [CREATE]
apiGroups: [kubevirt.io]
apiVersions: [v1]
resources: [virtualmachineinstances]
namespaceSelector:
{{- toYaml $namespaceSelector | nindent 4 }}
objectSelector:
matchLabels:
gpu.cozystack.io/device-reference: "true"
- name: virt-launcher.gpu.cozystack.io
admissionReviewVersions: ["v1"]
sideEffects: None
timeoutSeconds: 10
failurePolicy: Fail
# A later mutator may rewrite the affinity; the pin is added again.
reinvocationPolicy: IfNeeded
clientConfig:
service:
name: cozystack-controller-webhook
namespace: {{ .Release.Namespace }}
path: /gpu/pin-virt-launcher
rules:
- operations: [CREATE]
apiGroups: [""]
apiVersions: [v1]
resources: [pods]
namespaceSelector:
{{- toYaml $namespaceSelector | nindent 4 }}
# Both labels, so only virt-launcher pods with device references wait on
# this webhook during a networking disruption.
objectSelector:
matchLabels:
gpu.cozystack.io/device-reference: "true"
kubevirt.io: virt-launcher
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: cozystack-gpu
annotations:
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/cozystack-controller-webhook
webhooks:
- name: gpudevice.gpu.cozystack.io
admissionReviewVersions: ["v1"]
sideEffects: None
timeoutSeconds: 10
failurePolicy: Fail
clientConfig:
service:
name: cozystack-controller-webhook
namespace: {{ .Release.Namespace }}
path: /gpu/validate-gpudevice
rules:
- operations: [CREATE]
apiGroups: [gpu.cozystack.io]
apiVersions: [v1alpha1]
resources: [gpudevices]
namespaceSelector:
{{- toYaml $namespaceSelector | nindent 4 }}
{{- end }}