Use a PVC for the Odoo filestore

This commit is contained in:
Stéphane Bidoul 2021-11-09 19:45:30 +01:00
parent 4263c5bcee
commit db51e28dbd
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
8 changed files with 36 additions and 4 deletions

View file

@ -188,6 +188,7 @@ def _render_kubefiles(deployment_vars: DeploymentVars) -> Generator[Path, None,
async def _kubectl(args: list[str]) -> None: async def _kubectl(args: list[str]) -> None:
_logger.debug("kubectl %s", " ".join(args))
proc = await asyncio.create_subprocess_exec( proc = await asyncio.create_subprocess_exec(
"kubectl", *args, stdout=subprocess.DEVNULL "kubectl", *args, stdout=subprocess.DEVNULL
) )
@ -198,9 +199,10 @@ async def _kubectl(args: list[str]) -> None:
async def deploy(deployment_vars: DeploymentVars) -> None: async def deploy(deployment_vars: DeploymentVars) -> None:
with _render_kubefiles(deployment_vars) as tmp_path: with _render_kubefiles(deployment_vars) as tmp_path:
# Dry-run first to avoid creaing some resources when the creation of the # Dry-run first to avoid creating some resources when the creation of the
# deployment fails. In such cases, we would have resource leak as the existence # deployment itself fails. In such cases, we would have resource leak as the
# of deployment is how the controller knows it has something to manage. # existence of deployment is how the controller knows it has something to
# manage.
await _kubectl( await _kubectl(
[ [
"apply", "apply",
@ -220,12 +222,13 @@ async def deploy(deployment_vars: DeploymentVars) -> None:
async def delete_resources(build_name: str) -> None: async def delete_resources(build_name: str) -> None:
# TODO delete all resources with runboat/build label
await _kubectl( await _kubectl(
[ [
"-n", "-n",
settings.build_namespace, settings.build_namespace,
"delete", "delete",
"configmap,deployment,ingress,job,secret,service", "configmap,deployment,ingress,job,secret,service,pvc",
"-l", "-l",
f"runboat/build={build_name}", f"runboat/build={build_name}",
"--wait=false", "--wait=false",
@ -234,6 +237,7 @@ async def delete_resources(build_name: str) -> None:
async def delete_job(build_name: str, job_kind: DeploymentMode) -> None: async def delete_job(build_name: str, job_kind: DeploymentMode) -> None:
# TODO delete all resources with runboat/build and runboat/job-kind label
await _kubectl( await _kubectl(
[ [
"-n", "-n",

View file

@ -23,6 +23,8 @@ spec:
volumeMounts: volumeMounts:
- name: runboat-scripts - name: runboat-scripts
mountPath: /runboat mountPath: /runboat
- name: odoo-data
mountPath: /opt/odoo-data
envFrom: envFrom:
- secretRef: - secretRef:
name: odoosecretenv name: odoosecretenv
@ -45,3 +47,6 @@ spec:
- name: runboat-scripts - name: runboat-scripts
configMap: configMap:
name: runboat-scripts name: runboat-scripts
- name: odoo-data
persistentVolumeClaim:
claimName: odoo-data

View file

@ -13,6 +13,8 @@ spec:
volumeMounts: volumeMounts:
- name: runboat-scripts - name: runboat-scripts
mountPath: /runboat mountPath: /runboat
- name: odoo-data
mountPath: /opt/odoo-data
envFrom: envFrom:
- secretRef: - secretRef:
name: odoosecretenv name: odoosecretenv
@ -30,6 +32,9 @@ spec:
- name: runboat-scripts - name: runboat-scripts
configMap: configMap:
name: runboat-scripts name: runboat-scripts
- name: odoo-data
persistentVolumeClaim:
claimName: odoo-data
restartPolicy: Never restartPolicy: Never
backoffLimit: 0 backoffLimit: 0
activeDeadlineSeconds: 1200 activeDeadlineSeconds: 1200

View file

@ -1,9 +1,11 @@
resources: resources:
{%- if mode == 'deployment' %} {%- if mode == 'deployment' %}
- pvc.yaml
- deployment.yaml - deployment.yaml
- service.yaml - service.yaml
- ingress.yaml - ingress.yaml
{%- elif mode == "initialize" %} {%- elif mode == "initialize" %}
- pvc.yaml
- initialize.yaml - initialize.yaml
{%- elif mode == "cleanup" %} {%- elif mode == "cleanup" %}
- cleanup.yaml - cleanup.yaml

View file

@ -0,0 +1,13 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: odoo-data
spec:
storageClassName: openebs-zfs-localpv-slow # TODO make this configurable
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi
limits:
storage: 100Mi

View file

@ -16,6 +16,7 @@ dropdb --if-exists $PGDATABASE
ADDONS=$(addons --addons-dir ${ADDONS_DIR} --include "${INCLUDE}" --exclude "${EXCLUDE}" list) ADDONS=$(addons --addons-dir ${ADDONS_DIR} --include "${INCLUDE}" --exclude "${EXCLUDE}" list)
unbuffer $(which odoo || which openerp-server) \ unbuffer $(which odoo || which openerp-server) \
--data-dir=/opt/odoo-data \
-d ${PGDATABASE} \ -d ${PGDATABASE} \
-i ${ADDONS:-base} \ -i ${ADDONS:-base} \
--stop-after-init --stop-after-init

View file

@ -11,4 +11,5 @@ bash /runboat/runboat-clone-and-install.sh
oca_wait_for_postgres oca_wait_for_postgres
unbuffer $(which odoo || which openerp-server) \ unbuffer $(which odoo || which openerp-server) \
--data-dir=/opt/odoo-data \
-d ${PGDATABASE} -d ${PGDATABASE}

View file

@ -2,6 +2,7 @@ from runboat.k8s import DeploymentMode, _render_kubefiles, make_deployment_vars
EXPECTED = """\ EXPECTED = """\
resources: resources:
- pvc.yaml
- deployment.yaml - deployment.yaml
- service.yaml - service.yaml
- ingress.yaml - ingress.yaml