1import type { KindClusterConfig, LocalClusterProps } from "../LocalCluster.ts";
2
3/**
4 * containerd patch enabling the per-registry `hosts.toml` directory that
5 * points `localhost:<registryPort>` at the local registry container. The
6 * default on kind v0.27+ node images; kept for older ones
7 * (https://kind.sigs.k8s.io/docs/user/local-registry/).
8 */
9export const REGISTRY_CONTAINERD_PATCH = `[plugins."io.containerd.grpc.v1.cri".registry]
10 config_path = "/etc/containerd/certs.d"`;
11
12/** The kind config fields of a `LocalCluster`'s props. */
13export const kindConfigOf = ({
14 nodes,
15 networking,
16 featureGates,
17 runtimeConfig,
18 kubeadmConfigPatches,
19 kubeadmConfigPatchesJSON6902,
20 containerdConfigPatches,
21 containerdConfigPatchesJSON6902,
22}: Partial<LocalClusterProps>): KindClusterConfig => ({
23 nodes,
24 networking,
25 featureGates,
26 runtimeConfig,
27 kubeadmConfigPatches,
28 kubeadmConfigPatchesJSON6902,
29 containerdConfigPatches,
30 containerdConfigPatchesJSON6902,
31});
32
33/**
34 * The kind cluster config `LocalCluster` passes to `kind create cluster`:
35 * the kind fields with the kind/apiVersion header and the registry
36 * containerd patch added. kind reads YAML, and JSON is valid YAML.
37 */
38export const kindClusterConfig = (config: KindClusterConfig) => ({
39 kind: "Cluster",
40 apiVersion: "kind.x-k8s.io/v1alpha4",
41 ...JSON.parse(JSON.stringify(config)),
42 containerdConfigPatches: [
43 ...(config.containerdConfigPatches ?? []),
44 REGISTRY_CONTAINERD_PATCH,
45 ],
46});