feat(k8s): enable relative volume paths for kind deployments
Makes kind deployments use the same volume pattern as Docker Compose:
./data/{volume-name} relative to deployment directory.
Changes:
- Allow relative paths for kind (single host, like Docker Compose)
- Default kind volumes to ./data/ instead of provisioner-managed PVCs
- Update Caddy manifest to use hostPath /mnt/caddy-data
- Add caddy-data infrastructure volume support in kind mounts
This enables Caddy certificate persistence across cluster recreation
without requiring system-level directories like /opt/caddy-data.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
parent
d5e1a6652c
commit
79b7870a6a
|
|
@ -243,26 +243,12 @@ spec:
|
||||||
mountPath: /config
|
mountPath: /config
|
||||||
volumes:
|
volumes:
|
||||||
- name: caddy-data
|
- name: caddy-data
|
||||||
persistentVolumeClaim:
|
hostPath:
|
||||||
claimName: caddy-data-pvc
|
path: /mnt/caddy-data
|
||||||
|
type: DirectoryOrCreate
|
||||||
- name: caddy-config
|
- name: caddy-config
|
||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
metadata:
|
|
||||||
name: caddy-data-pvc
|
|
||||||
namespace: caddy-system
|
|
||||||
labels:
|
|
||||||
app.kubernetes.io/name: caddy-ingress-controller
|
|
||||||
app.kubernetes.io/instance: caddy-ingress
|
|
||||||
spec:
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteOnce
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 1Gi
|
|
||||||
---
|
|
||||||
apiVersion: networking.k8s.io/v1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: IngressClass
|
kind: IngressClass
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
||||||
|
|
@ -452,17 +452,21 @@ def init_operation(
|
||||||
volume_descriptors = {}
|
volume_descriptors = {}
|
||||||
configmap_descriptors = {}
|
configmap_descriptors = {}
|
||||||
for named_volume in named_volumes["rw"]:
|
for named_volume in named_volumes["rw"]:
|
||||||
if "k8s" in deployer_type:
|
if deployer_type == "k8s":
|
||||||
|
# Full k8s: use provisioner-managed volumes
|
||||||
volume_descriptors[named_volume] = None
|
volume_descriptors[named_volume] = None
|
||||||
else:
|
else:
|
||||||
|
# Docker Compose and kind: use relative paths
|
||||||
volume_descriptors[named_volume] = f"./data/{named_volume}"
|
volume_descriptors[named_volume] = f"./data/{named_volume}"
|
||||||
for named_volume in named_volumes["ro"]:
|
for named_volume in named_volumes["ro"]:
|
||||||
if "k8s" in deployer_type:
|
if deployer_type == "k8s":
|
||||||
|
# Full k8s: configmaps or provisioner-managed
|
||||||
if "config" in named_volume:
|
if "config" in named_volume:
|
||||||
configmap_descriptors[named_volume] = f"./configmaps/{named_volume}"
|
configmap_descriptors[named_volume] = f"./configmaps/{named_volume}"
|
||||||
else:
|
else:
|
||||||
volume_descriptors[named_volume] = None
|
volume_descriptors[named_volume] = None
|
||||||
else:
|
else:
|
||||||
|
# Docker Compose and kind: use relative paths
|
||||||
volume_descriptors[named_volume] = f"./data/{named_volume}"
|
volume_descriptors[named_volume] = f"./data/{named_volume}"
|
||||||
if volume_descriptors:
|
if volume_descriptors:
|
||||||
spec_file_content["volumes"] = volume_descriptors
|
spec_file_content["volumes"] = volume_descriptors
|
||||||
|
|
@ -509,10 +513,13 @@ def _create_deployment_file(deployment_dir: Path):
|
||||||
|
|
||||||
|
|
||||||
def _check_volume_definitions(spec):
|
def _check_volume_definitions(spec):
|
||||||
if spec.is_kubernetes_deployment():
|
# Kind allows relative paths (single host, like Docker Compose)
|
||||||
|
# Full k8s requires absolute paths (pods could run on any node)
|
||||||
|
if not spec.is_kubernetes_deployment() or spec.is_kind_deployment():
|
||||||
|
return
|
||||||
|
|
||||||
for volume_name, volume_path in spec.get_volumes().items():
|
for volume_name, volume_path in spec.get_volumes().items():
|
||||||
if volume_path:
|
if volume_path and not os.path.isabs(volume_path):
|
||||||
if not os.path.isabs(volume_path):
|
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Relative path {volume_path} for volume {volume_name} not "
|
f"Relative path {volume_path} for volume {volume_name} not "
|
||||||
f"supported for deployment type {spec.get_deployment_type()}"
|
f"supported for deployment type {spec.get_deployment_type()}"
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,18 @@ def _make_absolute_host_path(data_mount_path: Path, deployment_dir: Path) -> Pat
|
||||||
def _generate_kind_mounts(parsed_pod_files, deployment_dir, deployment_context):
|
def _generate_kind_mounts(parsed_pod_files, deployment_dir, deployment_context):
|
||||||
volume_definitions = []
|
volume_definitions = []
|
||||||
volume_host_path_map = _get_host_paths_for_volumes(deployment_context)
|
volume_host_path_map = _get_host_paths_for_volumes(deployment_context)
|
||||||
|
|
||||||
|
# Add infrastructure volumes (not defined in compose files)
|
||||||
|
for infra_volume in ["caddy-data"]:
|
||||||
|
if infra_volume in volume_host_path_map and volume_host_path_map[infra_volume]:
|
||||||
|
host_path = _make_absolute_host_path(
|
||||||
|
volume_host_path_map[infra_volume], deployment_dir
|
||||||
|
)
|
||||||
|
container_path = get_kind_pv_bind_mount_path(infra_volume)
|
||||||
|
volume_definitions.append(
|
||||||
|
f" - hostPath: {host_path}\n" f" containerPath: {container_path}\n"
|
||||||
|
)
|
||||||
|
|
||||||
# Note these paths are relative to the location of the pod files (at present)
|
# Note these paths are relative to the location of the pod files (at present)
|
||||||
# So we need to fix up to make them correct and absolute because kind assumes
|
# So we need to fix up to make them correct and absolute because kind assumes
|
||||||
# relative to the cwd.
|
# relative to the cwd.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue