diff --git a/packages/system/cozyplane-kpr/.helmignore b/packages/system/cozyplane-kpr/.helmignore new file mode 100644 index 000000000..a453db842 --- /dev/null +++ b/packages/system/cozyplane-kpr/.helmignore @@ -0,0 +1,8 @@ +.DS_Store +*.swp +*.bak +*.tmp +*~ +.git +.gitignore +tests/ diff --git a/packages/system/cozyplane-kpr/Chart.yaml b/packages/system/cozyplane-kpr/Chart.yaml new file mode 100644 index 000000000..c426744b8 --- /dev/null +++ b/packages/system/cozyplane-kpr/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v2 +name: cozyplane-kpr +description: cozyplane kube-proxy replacement — socket-LB service load balancing (replaces Cilium/kube-proxy KPR) +type: application +# Placeholder; the real version is stamped by the build/release pipeline. +version: 0.1.0 +appVersion: "0.1.0" +kubeVersion: ">=1.30.0-0" +keywords: + - kube-proxy + - service + - load-balancer + - ebpf + - cozystack +home: https://github.com/lllamnyp/cozyplane +sources: + - https://github.com/lllamnyp/cozyplane diff --git a/packages/system/cozyplane-kpr/Makefile b/packages/system/cozyplane-kpr/Makefile new file mode 100644 index 000000000..ece428cf4 --- /dev/null +++ b/packages/system/cozyplane-kpr/Makefile @@ -0,0 +1,26 @@ +export NAME=cozyplane-kpr +export NAMESPACE=cozy-cozyplane + +include ../../../hack/common-envs.mk +include ../../../hack/package.mk + +# cozyplane-kpr builds and publishes its own container image from +# github.com/lllamnyp/cozyplane (kpr/); this package only vendors the Helm chart +# and references the published image in values.yaml. 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.1.0 + +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-kpr + 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-kpr/templates/daemonset.yaml b/packages/system/cozyplane-kpr/templates/daemonset.yaml new file mode 100644 index 000000000..ecc198611 --- /dev/null +++ b/packages/system/cozyplane-kpr/templates/daemonset.yaml @@ -0,0 +1,102 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: cozyplane-kpr + namespace: {{ .Release.Namespace }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: cozyplane-kpr +rules: + # The LB control plane watches Services + their endpoints and node/topology. + - apiGroups: [""] + resources: [services, endpoints, nodes, namespaces, pods] + verbs: [get, list, watch] + - apiGroups: [discovery.k8s.io] + resources: [endpointslices] + verbs: [get, list, watch] + # Leader election. + - apiGroups: [coordination.k8s.io] + resources: [leases] + verbs: [get, list, watch, create, update, patch, delete] + - apiGroups: [""] + resources: [events] + verbs: [create, patch] + # Cilium's imported cells reconcile their own CRDs (CiliumNode, LB IP pools, …). + - apiGroups: [cilium.io] + resources: ["*"] + verbs: [get, list, watch, create, update, patch, delete] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cozyplane-kpr +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cozyplane-kpr +subjects: + - kind: ServiceAccount + name: cozyplane-kpr + namespace: {{ .Release.Namespace }} +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: cozyplane-kpr + namespace: {{ .Release.Namespace }} + labels: {app: cozyplane-kpr} +spec: + selector: + matchLabels: {app: cozyplane-kpr} + updateStrategy: + type: RollingUpdate + template: + metadata: + labels: {app: cozyplane-kpr} + spec: + serviceAccountName: cozyplane-kpr + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + priorityClassName: system-node-critical + tolerations: + - operator: Exists + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: kpr + image: {{ .Values.image }} + imagePullPolicy: {{ .Values.imagePullPolicy }} + args: + {{- if .Values.apiServerURL }} + - --k8s-api-server-urls={{ .Values.apiServerURL }} + {{- end }} + env: + - {name: KPR_CGROUP_ROOT, value: {{ .Values.cgroupRoot | quote }}} + - {name: KPR_BPFFS_ROOT, value: {{ .Values.bpffsRoot | quote }}} + # Without NODE_NAME kpr cannot tell which endpoints are node-local, + # so it writes NO LoadBalancer-ingress, NodePort or externalIP rows + # at all -- ClusterIPs keep working, which is why the omission is + # easy to miss (docs/lb-ingress.md). + - name: NODE_NAME + valueFrom: {fieldRef: {fieldPath: spec.nodeName}} + - {name: CLUSTER_DSR, value: {{ .Values.clusterDSR | quote }}} + securityContext: + privileged: true + volumeMounts: + # kpr mounts bpffs here itself at startup if the node has none, and + # Bidirectional propagates that to the host so the pins outlive the + # process. The check is statfs on the mount point, not the mount's + # source name: Talos names its bpffs source "none", and a guard that + # matched "bpf" stacked an empty bpffs over the real one, hiding the + # agent's pins (kpr/bpffs.go). + - {name: bpffs, mountPath: {{ .Values.bpffsRoot }}, mountPropagation: Bidirectional} + - {name: cgroup2, mountPath: {{ .Values.cgroupRoot }}} + volumes: + - name: bpffs + hostPath: {path: {{ .Values.bpffsRoot }}, type: DirectoryOrCreate} + - name: cgroup2 + hostPath: {path: /sys/fs/cgroup, type: Directory} diff --git a/packages/system/cozyplane-kpr/tests/talos_render_test.yaml b/packages/system/cozyplane-kpr/tests/talos_render_test.yaml new file mode 100644 index 000000000..d3fe7d6e5 --- /dev/null +++ b/packages/system/cozyplane-kpr/tests/talos_render_test.yaml @@ -0,0 +1,56 @@ +suite: cozyplane-kpr renders with the Talos overlay +# Cozystack-side suite over the vendored chart: assert the contract the +# platform relies on (the bootstrap endpoint, the node identity, the DSR +# default), not chart internals. +templates: + - templates/daemonset.yaml +release: + name: cozyplane-kpr + namespace: cozy-cozyplane +tests: + # Same chicken-and-egg as the agent: kpr IS the ClusterIP proxy, so it + # cannot reach the apiserver through the ClusterIP it has not programmed + # yet. On Talos it dials KubePrism. + - it: dials KubePrism on Talos + values: + - ../values-talos.yaml + documentSelector: + path: kind + value: DaemonSet + asserts: + - contains: + path: spec.template.spec.containers[0].args + content: "--k8s-api-server-urls=https://localhost:7445" + + - it: uses the in-cluster config when no endpoint is set + documentSelector: + path: kind + value: DaemonSet + asserts: + # No apiServerURL renders an empty args list — kpr then reads the + # in-cluster config, valid only where some other proxy already serves + # the ClusterIP. + - equal: + path: spec.template.spec.containers[0].args + value: null + + # Without NODE_NAME kpr cannot tell which endpoints are node-local and + # serves no external address; DSR is strictly opt-in (the fleet-wide LB-IP + # spoof permission it needs is an underlay property). + - it: carries the node identity and keeps DSR off by default + documentSelector: + path: kind + value: DaemonSet + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - contains: + path: spec.template.spec.containers[0].env + content: + name: CLUSTER_DSR + value: "false" diff --git a/packages/system/cozyplane-kpr/values-talos.yaml b/packages/system/cozyplane-kpr/values-talos.yaml new file mode 100644 index 000000000..13a5c6c8e --- /dev/null +++ b/packages/system/cozyplane-kpr/values-talos.yaml @@ -0,0 +1,9 @@ +# Talos runs KubePrism (a node-local apiserver load balancer) on localhost:7445 — +# the real endpoint `apiServerURL` asks for; see values.yaml. A hostNetwork pod +# reaches it on localhost, before any ClusterIP proxy exists. +apiServerURL: "https://localhost:7445" + +# Applied as the SECOND valuesFile of the `cozyplane-kpr` component +# (packages/packagesources/networking.yaml): the Cozystack operator applies the +# first with strategy Overwrite and every later one with Merge, so this overlay +# only works as a file distinct from values.yaml. diff --git a/packages/system/cozyplane-kpr/values.yaml b/packages/system/cozyplane-kpr/values.yaml new file mode 100644 index 000000000..f7f41c4f7 --- /dev/null +++ b/packages/system/cozyplane-kpr/values.yaml @@ -0,0 +1,29 @@ +# cozyplane-kpr container image, built from kpr/ in this repository. +# Digest-pinned (no floating tag); built and pushed by release.yml's kpr-image +# job for amd64 and arm64, like the cozyplane image. docs/packaging.md has the +# procedure and how the pin is refreshed. +# It imports Cilium's LB control plane, so it is a large image and a SEPARATE +# component from the cozyplane agent — never co-mingled. +image: ghcr.io/lllamnyp/cozyplane-kpr@sha256:41a76cbcc1346806fa5b8020bd2bab0d0f13591467167391a9fa04f73ba62921 +imagePullPolicy: IfNotPresent +imagePullSecrets: [] + +# The apiserver endpoint cozyplane-kpr connects to. It must NOT be the +# kubernetes.default ClusterIP: with kube-proxy gone, that VIP is unserved until +# kpr itself is running (chicken-and-egg). Point it at a real endpoint. Empty +# uses the in-cluster config (only valid where some other proxy already serves +# the ClusterIP); on Talos, values-talos.yaml sets the KubePrism local endpoint. +apiServerURL: "" + +# The host cgroup2 root (bind-mounted into the pod) where socket-LB attaches, +# and the host bpffs root where the LB service/backend maps are pinned. +cgroupRoot: /host/cgroup2 +bpffsRoot: /sys/fs/bpf + +# externalTrafficPolicy: Cluster via DSR. Off, a Cluster-policy Service degrades +# to node-local delivery: a node with no ready backend serves nothing for that +# frontend. On, remote backends are reached by DSR, which needs EVERY node +# permitted to source the LB/external addresses on the wire -- an underlay +# property cozyplane cannot verify, and one that black-holes silently when the +# fabric denies it. Hence opt-in (docs/lb-ingress.md, DSR caveats). +clusterDSR: false