From 4e35e524219f3a4e17722e7044099bfc89d39815 Mon Sep 17 00:00:00 2001 From: Timofei Larkin Date: Fri, 2 Oct 2026 14:54:21 +0300 Subject: [PATCH] feat(cozyplane): vendor the sdn apiserver chart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The aggregated apiserver serves sdn.cozystack.io (VPC tenancy, policy) and is a separate package precisely so the CNI slot stays cert-manager-free: this component needs cert-manager Certificates, the etcd-operator and, for its PVC-backed etcd, storage — with no cycle, since linstor depends on the CNI rather than on this. The tenant kinds deliberately have no CRDs: one group served by both a CRD and an APIService collides in the kube-apiserver's OpenAPI merge and the group's schema never serves. The etcd is an etcd-operator v1alpha2 EtcdCluster in certManager TLS mode, PVC-backed on the replicated class by default (its objects are cluster state; a memory-backed member loses them on a full-cluster restart), addressed through the operator's Service because the operator names member pods randomly. The helm-unittest suite pins the EtcdCluster shape and the Service endpoint. Assisted-by: LLM Signed-off-by: Timofei Larkin --- .../system/cozyplane-apiserver/.helmignore | 8 + .../system/cozyplane-apiserver/Chart.yaml | 17 + packages/system/cozyplane-apiserver/Makefile | 27 ++ packages/system/cozyplane-apiserver/README.md | 50 +++ .../templates/_helpers.tpl | 15 + .../templates/apiserver.yaml | 376 ++++++++++++++++++ .../templates/etcd-cluster.yaml | 136 +++++++ .../tests/etcd_render_test.yaml | 72 ++++ .../system/cozyplane-apiserver/values.yaml | 58 +++ 9 files changed, 759 insertions(+) create mode 100644 packages/system/cozyplane-apiserver/.helmignore create mode 100644 packages/system/cozyplane-apiserver/Chart.yaml create mode 100644 packages/system/cozyplane-apiserver/Makefile create mode 100644 packages/system/cozyplane-apiserver/README.md create mode 100644 packages/system/cozyplane-apiserver/templates/_helpers.tpl create mode 100644 packages/system/cozyplane-apiserver/templates/apiserver.yaml create mode 100644 packages/system/cozyplane-apiserver/templates/etcd-cluster.yaml create mode 100644 packages/system/cozyplane-apiserver/tests/etcd_render_test.yaml create mode 100644 packages/system/cozyplane-apiserver/values.yaml diff --git a/packages/system/cozyplane-apiserver/.helmignore b/packages/system/cozyplane-apiserver/.helmignore new file mode 100644 index 000000000..a453db842 --- /dev/null +++ b/packages/system/cozyplane-apiserver/.helmignore @@ -0,0 +1,8 @@ +.DS_Store +*.swp +*.bak +*.tmp +*~ +.git +.gitignore +tests/ diff --git a/packages/system/cozyplane-apiserver/Chart.yaml b/packages/system/cozyplane-apiserver/Chart.yaml new file mode 100644 index 000000000..7fc146910 --- /dev/null +++ b/packages/system/cozyplane-apiserver/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v2 +name: cozyplane-apiserver +description: Aggregated API server for cozyplane's sdn.cozystack.io group (VPC tenancy), with its dedicated etcd +type: application +# Placeholder; the real version is stamped by the build/release pipeline. +version: 0.0.1 +appVersion: "0.1.0" +kubeVersion: ">=1.30.0-0" +keywords: + - cni + - networking + - api-aggregation + - cozystack + - vpc +home: https://github.com/lllamnyp/cozyplane +sources: + - https://github.com/lllamnyp/cozyplane diff --git a/packages/system/cozyplane-apiserver/Makefile b/packages/system/cozyplane-apiserver/Makefile new file mode 100644 index 000000000..9e0d58a9c --- /dev/null +++ b/packages/system/cozyplane-apiserver/Makefile @@ -0,0 +1,27 @@ +export NAME=cozyplane-apiserver +export NAMESPACE=cozy-cozyplane + +include ../../../hack/common-envs.mk +include ../../../hack/package.mk + +# Vendored from github.com/lllamnyp/cozyplane (chart/cozyplane-apiserver), +# adapted for Cozystack's etcd-operator (etcd-operator.cozystack.io/v1alpha2, +# memory-backed). The image is built and published from that repo; there is no +# image build target here. + +test: + helm lint . + helm unittest . + +# The vendoring ref in lllamnyp/cozyplane (a release tag once upstream cuts +# them; keep the three cozyplane packages on the same ref). Makefile and +# tests/ are Cozystack-side and survive the vendor, and so does the version +# stanza below: Cozystack owns the chart version, upstream keeps 0.0.0. +COZYPLANE_REF=65bade1c310c739edcf230af0a274086b1ac72f9 +CHART_VERSION=0.0.1 + +update: + find . -mindepth 1 -maxdepth 1 ! -name Makefile ! -name tests -exec rm -rf {} + + curl -sSL https://github.com/lllamnyp/cozyplane/archive/$(COZYPLANE_REF).tar.gz | \ + tar -xzf - --strip-components=3 cozyplane-$(COZYPLANE_REF)/chart/cozyplane-apiserver + sed -i -e '/# Unused as a release coordinate/,/^version: 0.0.0/c\# Placeholder; the real version is stamped by the build/release pipeline.\nversion: $(CHART_VERSION)' Chart.yaml diff --git a/packages/system/cozyplane-apiserver/README.md b/packages/system/cozyplane-apiserver/README.md new file mode 100644 index 000000000..6eceba3e0 --- /dev/null +++ b/packages/system/cozyplane-apiserver/README.md @@ -0,0 +1,50 @@ +# cozyplane-apiserver Helm chart + +The `sdn.cozystack.io` API group served by a real **aggregated API server** +(backed by a dedicated etcd) instead of CRDs — the design target: custom +validation, the export/peer verb checks in-server, and subresources (e.g. the +`/ports` observability subresource) beyond CRD ergonomics. + +This is a **separate chart from [cozyplane](../cozyplane)** by design. cozyplane +is the CNI and must install before almost everything — including cert-manager — +while this apiserver needs cert-manager `Certificate`s (its serving cert, the +etcd PKI). Splitting lets the CNI slot stay cert-manager-free and this chart +install later, once cert-manager is up (in Cozystack: a component that +`dependsOn` cert-manager). + +## The takeover + +The cozyplane chart installs the group's **CRDs** (its `crds.enabled` default), +so `sdn.cozystack.io` is served — and tenancy works — from the moment the CNI +lands. Installing this chart creates an explicit `APIService` for +`v1alpha1.sdn.cozystack.io`, which **atomically replaces** the CRDs' implicit +serving of the group: from that moment every request goes to the aggregated +server and its etcd. On a fresh cluster the CRD store is empty when that happens +(tenants come later), so the takeover needs no migration. On a cluster with +existing CRD-stored objects, export them first and re-apply after — the CRD +store is not visible through the aggregated server: + +```sh +kubectl get vpcs,ports,vpcbindings,vpcpeerings,securitygroups,floatingips,servicevips -A -o yaml > sdn-backup.yaml +helm install cozyplane-apiserver ./chart/cozyplane-apiserver -n cozyplane-system +kubectl apply -f sdn-backup.yaml +kubectl -n rollout restart deploy/cozyplane-controller ds/cozyplane-agent +``` + +(Strip `resourceVersion`/`uid`/`status` on re-apply, or use `kubectl create`.) + +The final restart is load-bearing: watch streams opened against the CRD serving +survive the takeover (the kube-apiserver closes idle watches only after 30–60 +minutes), so without it the controller and agents keep watching the shadowed +CRD store. Restart **after** the import so agent startup pruning sees a +populated store and no-ops instead of tearing down live datapath state. + +## Requirements + +- cert-manager (serving certificate, etcd PKI). +- For the production etcd: the aenix-io etcd-operator (`etcd.operator.enabled`), + replicated and PVC-backed. The default is a built-in single-pod etcd with + emptyDir storage — dev/evaluation only; a pod reschedule erases every + `sdn.cozystack.io` object. +- The [cozyplane](../cozyplane) chart (any order relative to it — but the CNI + normally lands first). diff --git a/packages/system/cozyplane-apiserver/templates/_helpers.tpl b/packages/system/cozyplane-apiserver/templates/_helpers.tpl new file mode 100644 index 000000000..28e9cdb9f --- /dev/null +++ b/packages/system/cozyplane-apiserver/templates/_helpers.tpl @@ -0,0 +1,15 @@ +{{/* Common metadata labels (not used as selectors — selectors stay stable). */}} +{{- define "cozyplane-apiserver.labels" -}} +app.kubernetes.io/name: cozyplane-apiserver +app.kubernetes.io/part-of: cozyplane +app.kubernetes.io/managed-by: {{ .Release.Service }} +helm.sh/chart: {{ printf "cozyplane-apiserver-%s" .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end -}} + +{{/* imagePullSecrets block, rendered only when set. Call with the root context. */}} +{{- define "cozyplane-apiserver.imagePullSecrets" -}} +{{- with .Values.imagePullSecrets }} +imagePullSecrets: + {{- toYaml . | nindent 2 }} +{{- end }} +{{- end -}} diff --git a/packages/system/cozyplane-apiserver/templates/apiserver.yaml b/packages/system/cozyplane-apiserver/templates/apiserver.yaml new file mode 100644 index 000000000..a27a806a3 --- /dev/null +++ b/packages/system/cozyplane-apiserver/templates/apiserver.yaml @@ -0,0 +1,376 @@ +{{- $ns := .Release.Namespace -}} +# The sdn.cozystack.io group served by a real aggregated API server (backed by a +# dedicated etcd) instead of CRDs — enabling custom validation and subresources +# beyond CRD ergonomics. Requires cert-manager for the serving certificate. +apiVersion: v1 +kind: ServiceAccount +metadata: + name: cozyplane-apiserver + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +--- +# Delegated authn/authz: the aggregated apiserver verifies incoming tokens and +# permissions via the kube-apiserver (TokenReview / SubjectAccessReview). +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cozyplane-apiserver:system:auth-delegator + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: system:auth-delegator +subjects: + - kind: ServiceAccount + name: cozyplane-apiserver + namespace: {{ $ns }} +--- +# Read the requestheader/front-proxy CA config the aggregation layer uses. +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: cozyplane-apiserver-auth-reader + namespace: kube-system + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: extension-apiserver-authentication-reader +subjects: + - kind: ServiceAccount + name: cozyplane-apiserver + namespace: {{ $ns }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: cozyplane-apiserver + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +rules: + # ResourceQuota admission (docs/multitenancy.md R5): the kube-apiserver's quota + # cannot see an aggregated API's kinds, so this server enforces + # `count/.sdn.cozystack.io` itself. It reads the tenant's ResourceQuotas + # and writes the observed usage back into their status. + - apiGroups: [""] + resources: ["resourcequotas"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["resourcequotas/status"] + verbs: ["get", "update", "patch"] + # Namespace-lifecycle admission reads namespaces. + - apiGroups: [""] + resources: ["namespaces"] + verbs: ["get", "list", "watch"] + # Admission (webhook + policy) informers. + - apiGroups: ["admissionregistration.k8s.io"] + resources: + - "validatingwebhookconfigurations" + - "mutatingwebhookconfigurations" + - "validatingadmissionpolicies" + - "validatingadmissionpolicybindings" + verbs: ["get", "list", "watch"] + # API Priority and Fairness informers. + - apiGroups: ["flowcontrol.apiserver.k8s.io"] + resources: ["flowschemas", "prioritylevelconfigurations"] + verbs: ["get", "list", "watch"] + # The server registers its own APIService at startup + # (--ensure-apiservice-service), rather than the chart shipping the object. + # Name-scoped: unscoped get/patch here would let this pod repoint any + # aggregated group in the cluster, Cozystack's own v1alpha1.apps.cozystack.io + # included. + - apiGroups: ["apiregistration.k8s.io"] + resources: ["apiservices"] + # Mirrors the server's own constant (internal/cmd/server/apiservice.go: + # sdnVersion + "." + sdnGroup); not a knob, the server derives it. + resourceNames: ["v1alpha1.sdn.cozystack.io"] + verbs: ["get", "patch"] + # create is separate and unnamed because RBAC ignores resourceNames for create + # (the name is in the body, not the request path), and first boot has no object + # to name yet. It confers no hold over an APIService that already exists — + # changing or removing one needs patch or delete, which are granted for this + # group's name alone. + - apiGroups: ["apiregistration.k8s.io"] + resources: ["apiservices"] + verbs: ["create"] + # For upgrades from a pre-split install only: --remove-bootstrap-crds (off by + # default) deletes the old single-group CRDs, which would otherwise keep the + # group's OpenAPI from merging. A fresh install has no CRDs in this group — + # see docs/api-groups.md §"Why two groups". delete alone, and only these names: + # the code deletes each by name and never gets or lists them + # (internal/cmd/server/apiservice.go, sdnPlurals — keep this list in step). + - apiGroups: ["apiextensions.k8s.io"] + resources: ["customresourcedefinitions"] + resourceNames: + - vpcs.sdn.cozystack.io + - vpcbindings.sdn.cozystack.io + - vpcpeerings.sdn.cozystack.io + - vpcgateways.sdn.cozystack.io + - ports.sdn.cozystack.io + - externalpools.sdn.cozystack.io + - floatingips.sdn.cozystack.io + - servicevips.sdn.cozystack.io + - securitygroups.sdn.cozystack.io + - hostfirewalls.sdn.cozystack.io + verbs: ["delete"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cozyplane-apiserver + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cozyplane-apiserver +subjects: + - kind: ServiceAccount + name: cozyplane-apiserver + namespace: {{ $ns }} +--- +{{- if not .Values.etcd.operator.enabled }} +{{- if .Values.etcd.persistence.enabled }} +# The single-pod etcd's storage. The aggregated API's objects are cluster state: +# an emptyDir would lose every VPC, Port and policy the moment the pod moves. +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: cozyplane-etcd-data + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + accessModes: [ReadWriteOnce] + {{- with .Values.etcd.persistence.storageClassName }} + storageClassName: {{ . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.etcd.persistence.size }} +--- +{{- end }} +# Built-in single-pod etcd. Production uses the operator-managed EtcdCluster +# instead — see templates/etcd-cluster.yaml. +apiVersion: apps/v1 +kind: Deployment +metadata: + name: cozyplane-etcd + namespace: {{ $ns }} + labels: + app: cozyplane-etcd + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + replicas: 1 + # Recreate, not RollingUpdate: two etcd pods must never hold the same RWO + # volume, and a rolling update would try. + strategy: + type: Recreate + selector: + matchLabels: + app: cozyplane-etcd + template: + metadata: + labels: + app: cozyplane-etcd + spec: + {{- include "cozyplane-apiserver.imagePullSecrets" . | nindent 6 }} + containers: + - name: etcd + image: {{ .Values.etcd.image }} + command: + - etcd + - --data-dir=/var/run/etcd/default.etcd + - --listen-client-urls=http://0.0.0.0:2379 + - --advertise-client-urls=http://cozyplane-etcd.{{ $ns }}.svc:2379 + ports: + - containerPort: 2379 + name: client + resources: + {{- toYaml .Values.etcd.resources | nindent 12 }} + volumeMounts: + - name: data + mountPath: /var/run/etcd + volumes: + - name: data + {{- toYaml .Values.etcd.storage | nindent 10 }} +--- +apiVersion: v1 +kind: Service +metadata: + name: cozyplane-etcd + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + selector: + app: cozyplane-etcd + ports: + - port: 2379 + targetPort: 2379 + name: client +{{- end }} +--- +# Self-signed CA + serving certificate (cert-manager). +apiVersion: cert-manager.io/v1 +kind: Issuer +metadata: + name: cozyplane-apiserver-selfsign + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + selfSigned: {} +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: cozyplane-apiserver-ca + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + isCA: true + commonName: cozyplane-apiserver-ca + secretName: cozyplane-apiserver-ca + duration: 87600h + privateKey: + algorithm: ECDSA + size: 256 + issuerRef: + name: cozyplane-apiserver-selfsign + kind: Issuer + group: cert-manager.io +--- +apiVersion: cert-manager.io/v1 +kind: Issuer +metadata: + name: cozyplane-apiserver-ca + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + ca: + secretName: cozyplane-apiserver-ca +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: cozyplane-apiserver-serving + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + secretName: cozyplane-apiserver-serving + duration: 8760h + privateKey: + algorithm: ECDSA + size: 256 + issuerRef: + name: cozyplane-apiserver-ca + kind: Issuer + group: cert-manager.io + dnsNames: + - cozyplane-apiserver + - cozyplane-apiserver.{{ $ns }} + - cozyplane-apiserver.{{ $ns }}.svc + - cozyplane-apiserver.{{ $ns }}.svc.cluster.local +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: cozyplane-apiserver + namespace: {{ $ns }} + labels: + app: cozyplane-apiserver + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + app: cozyplane-apiserver + template: + metadata: + labels: + app: cozyplane-apiserver + spec: + serviceAccountName: cozyplane-apiserver + {{- include "cozyplane-apiserver.imagePullSecrets" . | nindent 6 }} + containers: + - name: apiserver + image: {{ .Values.image }} + imagePullPolicy: {{ .Values.imagePullPolicy }} + command: ["/usr/local/bin/cozyplane-apiserver"] + args: + - --serve-sdn + # Register the group's APIService. Nothing else creates one: the + # tenant kinds have no CRDs, so no CRD autoregistration competes for + # the group (docs/api-groups.md). + - --ensure-apiservice-service={{ $ns }}/cozyplane-apiserver + - --ensure-apiservice-ca-injection={{ $ns }}/cozyplane-apiserver-serving + {{- if .Values.etcd.operator.enabled }} + # The operator names its members randomly (not -0/-1/-2) and fronts + # them with one Service — so address the Service, never per-pod + # endpoints. Getting this wrong looks exactly like a dead etcd: the + # apiserver dials names that never resolve and panics on the storage + # deadline. + - --etcd-servers=https://cozyplane-etcd.{{ $ns }}.svc:2379 + - --etcd-cafile=/etc/etcd-certs/ca.crt + - --etcd-certfile=/etc/etcd-certs/tls.crt + - --etcd-keyfile=/etc/etcd-certs/tls.key + {{- else }} + - --etcd-servers=http://cozyplane-etcd.{{ $ns }}.svc:2379 + {{- end }} + - --secure-port=6443 + - --tls-cert-file=/etc/apiserver-certs/tls.crt + - --tls-private-key-file=/etc/apiserver-certs/tls.key + - --audit-log-path=- + ports: + - containerPort: 6443 + name: https + livenessProbe: + httpGet: { path: /livez, port: 6443, scheme: HTTPS } + initialDelaySeconds: 15 + periodSeconds: 20 + readinessProbe: + httpGet: { path: /readyz, port: 6443, scheme: HTTPS } + initialDelaySeconds: 5 + periodSeconds: 10 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: certs + mountPath: /etc/apiserver-certs + readOnly: true + {{- if .Values.etcd.operator.enabled }} + - name: etcd-client-certs + mountPath: /etc/etcd-certs + readOnly: true + {{- end }} + volumes: + - name: certs + secret: + secretName: cozyplane-apiserver-serving + {{- if .Values.etcd.operator.enabled }} + - name: etcd-client-certs + secret: + secretName: cozyplane-etcd-client-tls + {{- end }} +--- +apiVersion: v1 +kind: Service +metadata: + name: cozyplane-apiserver + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + selector: + app: cozyplane-apiserver + ports: + - port: 443 + targetPort: 6443 + name: https diff --git a/packages/system/cozyplane-apiserver/templates/etcd-cluster.yaml b/packages/system/cozyplane-apiserver/templates/etcd-cluster.yaml new file mode 100644 index 000000000..4d4be66f1 --- /dev/null +++ b/packages/system/cozyplane-apiserver/templates/etcd-cluster.yaml @@ -0,0 +1,136 @@ +{{- /* Operator-managed etcd for the aggregated apiserver (etcd-operator.cozystack.io + v1alpha2). PVC-backed by default; `etcd.operator.persistent: false` gives a + tmpfs member instead, for an install with no storage layer. + TLS uses the operator's cert-manager integration: the operator emits the + server / operator-client / peer Certificates itself; we only supply the CA + issuers and the apiserver's own client cert. Requires cert-manager. The + self-signed root issuer comes from templates/apiserver.yaml. */ -}} +{{- if .Values.etcd.operator.enabled }} +{{- $ns := .Release.Namespace -}} +{{- $replicas := int .Values.etcd.operator.replicas -}} +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: cozyplane-etcd-peer-ca + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + isCA: true + usages: ["signing", "key encipherment", "cert sign"] + commonName: cozyplane-etcd-peer-ca + duration: 87600h + secretName: cozyplane-etcd-peer-ca-tls + privateKey: + algorithm: ECDSA + size: 256 + issuerRef: + name: cozyplane-apiserver-selfsign + kind: Issuer + group: cert-manager.io +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: cozyplane-etcd-ca + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + isCA: true + usages: ["signing", "key encipherment", "cert sign"] + commonName: cozyplane-etcd-ca + duration: 87600h + secretName: cozyplane-etcd-ca-tls + privateKey: + algorithm: ECDSA + size: 256 + issuerRef: + name: cozyplane-apiserver-selfsign + kind: Issuer + group: cert-manager.io +--- +# Peer CA issuer — the operator's peer certManager signs the peer cert with it. +apiVersion: cert-manager.io/v1 +kind: Issuer +metadata: + name: cozyplane-etcd-peer-issuer + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + ca: + secretName: cozyplane-etcd-peer-ca-tls +--- +# Client-plane CA issuer — signs the operator-emitted server + operator-client +# certs AND (below) the apiserver's own client cert, so a single ca.crt trusts +# every party on etcd's client surface (--client-cert-auth). +apiVersion: cert-manager.io/v1 +kind: Issuer +metadata: + name: cozyplane-etcd-issuer + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + ca: + secretName: cozyplane-etcd-ca-tls +--- +# The apiserver's client identity (a SEPARATE client from the operator's). Signed +# by the same client CA as the etcd server, so the server trusts it. Its Secret +# also carries ca.crt (the etcd server CA) for the apiserver's --etcd-cafile. +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: cozyplane-etcd-client + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + commonName: root + secretName: cozyplane-etcd-client-tls + usages: ["client auth", "signing", "key encipherment"] + privateKey: + rotationPolicy: Always + algorithm: ECDSA + size: 256 + issuerRef: + name: cozyplane-etcd-issuer + kind: Issuer + group: cert-manager.io +--- +apiVersion: etcd-operator.cozystack.io/v1alpha2 +kind: EtcdCluster +metadata: + name: cozyplane-etcd + namespace: {{ $ns }} + labels: + {{- include "cozyplane-apiserver.labels" . | nindent 4 }} +spec: + version: {{ .Values.etcd.operator.version | quote }} + replicas: {{ $replicas }} + storage: + {{- if .Values.etcd.operator.persistent }} + # PVC-backed (the default; see values.yaml `etcd.operator.persistent`). + medium: "" + {{- with .Values.etcd.operator.storageClass }} + storageClassName: {{ . | quote }} + {{- end }} + {{- else }} + # tmpfs. `medium` is immutable post-create; size is the tmpfs cap. + medium: Memory + {{- end }} + size: {{ .Values.etcd.operator.size }} + options: + autoCompactionMode: periodic + autoCompactionRetention: "5m" + snapshotCount: 10000 + tls: + client: + certManager: + serverIssuerRef: { name: cozyplane-etcd-issuer, kind: Issuer } + operatorClientIssuerRef: { name: cozyplane-etcd-issuer, kind: Issuer } + peer: + certManager: + issuerRef: { name: cozyplane-etcd-peer-issuer, kind: Issuer } +{{- end }} diff --git a/packages/system/cozyplane-apiserver/tests/etcd_render_test.yaml b/packages/system/cozyplane-apiserver/tests/etcd_render_test.yaml new file mode 100644 index 000000000..194544935 --- /dev/null +++ b/packages/system/cozyplane-apiserver/tests/etcd_render_test.yaml @@ -0,0 +1,72 @@ +suite: cozyplane-apiserver etcd wiring +# Cozystack-side suite over the vendored chart. The contract that matters to +# the platform: the operator-managed etcd is a valid v1alpha2 EtcdCluster, +# PVC-backed by default on the replicated class, and the apiserver dials the +# operator's Service — never per-pod endpoints, which the operator names +# randomly (getting that wrong looks exactly like a dead etcd). +templates: + - templates/etcd-cluster.yaml + - templates/apiserver.yaml +release: + name: cozyplane-apiserver + namespace: cozy-cozyplane +tests: + - it: renders a PVC-backed v1alpha2 EtcdCluster by default + templates: [templates/etcd-cluster.yaml] + documentSelector: + path: kind + value: EtcdCluster + asserts: + - equal: + path: apiVersion + value: etcd-operator.cozystack.io/v1alpha2 + - equal: + path: spec.storage.medium + value: "" + - equal: + path: spec.storage.storageClassName + value: replicated + # certManager-mode TLS: exactly one of certManager/secretRef per surface + # (a CRD CEL rule); the platform supplies the issuers. + - exists: + path: spec.tls.client.certManager.serverIssuerRef + - notExists: + path: spec.tls.client.serverSecretRef + - exists: + path: spec.tls.peer.certManager.issuerRef + + # tmpfs is the no-storage-layer escape hatch; spec.storage.medium is + # immutable post-create, so this must come out right the first time. + - it: renders a memory-backed member when persistence is off + templates: [templates/etcd-cluster.yaml] + set: + etcd: + operator: + persistent: false + documentSelector: + path: kind + value: EtcdCluster + asserts: + - equal: + path: spec.storage.medium + value: Memory + + - it: dials the operator's etcd Service, not per-pod endpoints + templates: [templates/apiserver.yaml] + documentSelector: + path: kind + value: Deployment + asserts: + - contains: + path: spec.template.spec.containers[0].args + content: --etcd-servers=https://cozyplane-etcd.cozy-cozyplane.svc:2379 + + - it: falls back to the built-in single-pod etcd when the operator is off + set: + etcd: + operator: + enabled: false + asserts: + - hasDocuments: + count: 0 + template: templates/etcd-cluster.yaml diff --git a/packages/system/cozyplane-apiserver/values.yaml b/packages/system/cozyplane-apiserver/values.yaml new file mode 100644 index 000000000..1bfd729c5 --- /dev/null +++ b/packages/system/cozyplane-apiserver/values.yaml @@ -0,0 +1,58 @@ +# Container image (shared with the cozyplane chart — the apiserver binary lives +# in the same image). Digest-pinned (no floating tag); keep it equal to +# chart/cozyplane/values.yaml's pin. See docs/packaging.md. +image: ghcr.io/lllamnyp/cozyplane@sha256:60111afff00d91883a63183a058d24f81620f250a4526a94dbb26b937bb327e7 +imagePullPolicy: IfNotPresent +imagePullSecrets: [] + +replicas: 1 +resources: + requests: + cpu: 50m + memory: 128Mi + limits: + memory: 256Mi + +etcd: + # Operator-managed etcd (the aenix-io etcd-operator; Cozystack ships it): + # replicated, PVC-backed, TLS end to end. The production path, and the default + # — the Cozystack install this chart is packaged for always has the operator + # (packages/packagesources/apiserver.yaml dependsOn cozystack.etcd-operator). + # Turn it off for a standalone/kind install with no operator: the chart then + # falls back to the built-in single-pod etcd below, which is one pod holding + # every sdn.cozystack.io object in the cluster. + operator: + enabled: true + replicas: 3 + size: 4Gi + # etcd version the operator runs (required by the EtcdCluster schema). + version: "3.6.11" + # persistent: PVC-backed (durable) vs tmpfs. The aggregated API's objects + # are cluster state; a memory-backed etcd loses all of them on a + # full-cluster restart, which is what a node reboot is. Requires a storage + # layer, so the component must be sequenced after it. + persistent: true + # StorageClass for the members' PVCs ("" = cluster default). Replicated, so + # a member's data survives losing the node it was scheduled on. Cozystack's + # storage layers (linstor, blockstor) both provide a "replicated" class. + storageClass: "replicated" + # Built-in single-pod etcd (dev/evaluation only). + image: registry.k8s.io/etcd:3.5.16-0 + # Storage for the built-in single-pod etcd. Default is a PVC — the aggregated + # API's objects (VPCs, Ports, policies) are cluster state, and an emptyDir + # loses them on a pod move. Set `emptyDir: {}` explicitly for a throwaway + # cluster with no storage class. + storage: + persistentVolumeClaim: + claimName: cozyplane-etcd-data + # The PVC the chart creates when storage above references it. + persistence: + enabled: true + storageClassName: "" # "" = the cluster default + size: 2Gi + resources: + requests: + cpu: 50m + memory: 128Mi + limits: + memory: 256Mi