Add persistent volumes
This commit is contained in:
parent
3aea931b97
commit
5e6d1e35bc
@ -18,7 +18,7 @@ from typing import Any, List, Set
|
|||||||
|
|
||||||
from stack_orchestrator.opts import opts
|
from stack_orchestrator.opts import opts
|
||||||
from stack_orchestrator.deploy.k8s.helpers import named_volumes_from_pod_files, volume_mounts_for_service, volumes_for_pod_files
|
from stack_orchestrator.deploy.k8s.helpers import named_volumes_from_pod_files, volume_mounts_for_service, volumes_for_pod_files
|
||||||
from stack_orchestrator.deploy.k8s.helpers import parsed_pod_files_map_from_file_names
|
from stack_orchestrator.deploy.k8s.helpers import parsed_pod_files_map_from_file_names, get_node_pv_mount_path
|
||||||
|
|
||||||
|
|
||||||
class ClusterInfo:
|
class ClusterInfo:
|
||||||
@ -54,7 +54,8 @@ class ClusterInfo:
|
|||||||
access_modes=["ReadWriteOnce"],
|
access_modes=["ReadWriteOnce"],
|
||||||
resources=client.V1ResourceRequirements(
|
resources=client.V1ResourceRequirements(
|
||||||
requests={"storage": "2Gi"}
|
requests={"storage": "2Gi"}
|
||||||
)
|
),
|
||||||
|
volume_name=volume_name
|
||||||
)
|
)
|
||||||
pvc = client.V1PersistentVolumeClaim(
|
pvc = client.V1PersistentVolumeClaim(
|
||||||
metadata=client.V1ObjectMeta(name=volume_name,
|
metadata=client.V1ObjectMeta(name=volume_name,
|
||||||
@ -64,6 +65,24 @@ class ClusterInfo:
|
|||||||
result.append(pvc)
|
result.append(pvc)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_pvs(self):
|
||||||
|
result = []
|
||||||
|
volumes = named_volumes_from_pod_files(self.parsed_pod_yaml_map)
|
||||||
|
for volume_name in volumes:
|
||||||
|
spec = client.V1PersistentVolumeSpec(
|
||||||
|
storage_class_name="manual",
|
||||||
|
access_modes=["ReadWriteOnce"],
|
||||||
|
capacity={"storage": "2Gi"},
|
||||||
|
host_path=client.V1HostPathVolumeSource(path=get_node_pv_mount_path(volume_name))
|
||||||
|
)
|
||||||
|
pv = client.V1PersistentVolume(
|
||||||
|
metadata=client.V1ObjectMeta(name=volume_name,
|
||||||
|
labels={"volume-label": volume_name}),
|
||||||
|
spec=spec,
|
||||||
|
)
|
||||||
|
result.append(pv)
|
||||||
|
return result
|
||||||
|
|
||||||
# to suit the deployment, and also annotate the container specs to point at said volumes
|
# to suit the deployment, and also annotate the container specs to point at said volumes
|
||||||
def get_deployment(self):
|
def get_deployment(self):
|
||||||
containers = []
|
containers = []
|
||||||
|
@ -52,11 +52,22 @@ class K8sDeployer(Deployer):
|
|||||||
self.connect_api()
|
self.connect_api()
|
||||||
# Ensure the referenced containers are copied into kind
|
# Ensure the referenced containers are copied into kind
|
||||||
load_images_into_kind(self.kind_cluster_name, self.cluster_info.image_set)
|
load_images_into_kind(self.kind_cluster_name, self.cluster_info.image_set)
|
||||||
|
|
||||||
|
# Create the host-path-mounted PVs for this deployment
|
||||||
|
pvs = self.cluster_info.get_pvs()
|
||||||
|
for pv in pvs:
|
||||||
|
if opts.o.debug:
|
||||||
|
print(f"Sending this pv: {pv}")
|
||||||
|
pv_resp = self.core_api.create_persistent_volume(body=pv)
|
||||||
|
if opts.o.debug:
|
||||||
|
print("PVs created:")
|
||||||
|
print(f"{pv_resp}")
|
||||||
|
|
||||||
# Figure out the PVCs for this deployment
|
# Figure out the PVCs for this deployment
|
||||||
pvcs = self.cluster_info.get_pvcs()
|
pvcs = self.cluster_info.get_pvcs()
|
||||||
for pvc in pvcs:
|
for pvc in pvcs:
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Sending this: {pvc}")
|
print(f"Sending this pvc: {pvc}")
|
||||||
pvc_resp = self.core_api.create_namespaced_persistent_volume_claim(body=pvc, namespace=self.k8s_namespace)
|
pvc_resp = self.core_api.create_namespaced_persistent_volume_claim(body=pvc, namespace=self.k8s_namespace)
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print("PVCs created:")
|
print("PVCs created:")
|
||||||
@ -65,7 +76,7 @@ class K8sDeployer(Deployer):
|
|||||||
deployment = self.cluster_info.get_deployment()
|
deployment = self.cluster_info.get_deployment()
|
||||||
# Create the k8s objects
|
# Create the k8s objects
|
||||||
if opts.o.debug:
|
if opts.o.debug:
|
||||||
print(f"Sending this: {deployment}")
|
print(f"Sending this deployment: {deployment}")
|
||||||
deployment_resp = self.apps_api.create_namespaced_deployment(
|
deployment_resp = self.apps_api.create_namespaced_deployment(
|
||||||
body=deployment, namespace=self.k8s_namespace
|
body=deployment, namespace=self.k8s_namespace
|
||||||
)
|
)
|
||||||
|
@ -74,6 +74,10 @@ def named_volumes_from_pod_files(parsed_pod_files):
|
|||||||
return named_volumes
|
return named_volumes
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_pv_mount_path(volume_name: str):
|
||||||
|
return f"/mnt/{volume_name}"
|
||||||
|
|
||||||
|
|
||||||
def volume_mounts_for_service(parsed_pod_files, service):
|
def volume_mounts_for_service(parsed_pod_files, service):
|
||||||
result = []
|
result = []
|
||||||
# Find the service
|
# Find the service
|
||||||
|
Loading…
Reference in New Issue
Block a user