From db51e28dbdb7acdff1d3b93e93e96ec697c44bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Tue, 9 Nov 2021 19:45:30 +0100 Subject: [PATCH] Use a PVC for the Odoo filestore --- src/runboat/k8s.py | 12 ++++++++---- src/runboat/kubefiles/deployment.yaml | 5 +++++ src/runboat/kubefiles/initialize.yaml | 5 +++++ src/runboat/kubefiles/kustomization.yaml.jinja | 2 ++ src/runboat/kubefiles/pvc.yaml | 13 +++++++++++++ src/runboat/kubefiles/runboat-initialize.sh | 1 + src/runboat/kubefiles/runboat-start.sh | 1 + tests/test_render_kubefiles.py | 1 + 8 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/runboat/kubefiles/pvc.yaml diff --git a/src/runboat/k8s.py b/src/runboat/k8s.py index 35abbaa..2b27d1b 100644 --- a/src/runboat/k8s.py +++ b/src/runboat/k8s.py @@ -188,6 +188,7 @@ def _render_kubefiles(deployment_vars: DeploymentVars) -> Generator[Path, None, async def _kubectl(args: list[str]) -> None: + _logger.debug("kubectl %s", " ".join(args)) proc = await asyncio.create_subprocess_exec( "kubectl", *args, stdout=subprocess.DEVNULL ) @@ -198,9 +199,10 @@ async def _kubectl(args: list[str]) -> None: async def deploy(deployment_vars: DeploymentVars) -> None: with _render_kubefiles(deployment_vars) as tmp_path: - # Dry-run first to avoid creaing some resources when the creation of the - # deployment fails. In such cases, we would have resource leak as the existence - # of deployment is how the controller knows it has something to manage. + # Dry-run first to avoid creating some resources when the creation of the + # deployment itself fails. In such cases, we would have resource leak as the + # existence of deployment is how the controller knows it has something to + # manage. await _kubectl( [ "apply", @@ -220,12 +222,13 @@ async def deploy(deployment_vars: DeploymentVars) -> None: async def delete_resources(build_name: str) -> None: + # TODO delete all resources with runboat/build label await _kubectl( [ "-n", settings.build_namespace, "delete", - "configmap,deployment,ingress,job,secret,service", + "configmap,deployment,ingress,job,secret,service,pvc", "-l", f"runboat/build={build_name}", "--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: + # TODO delete all resources with runboat/build and runboat/job-kind label await _kubectl( [ "-n", diff --git a/src/runboat/kubefiles/deployment.yaml b/src/runboat/kubefiles/deployment.yaml index e46afc6..7e28f42 100644 --- a/src/runboat/kubefiles/deployment.yaml +++ b/src/runboat/kubefiles/deployment.yaml @@ -23,6 +23,8 @@ spec: volumeMounts: - name: runboat-scripts mountPath: /runboat + - name: odoo-data + mountPath: /opt/odoo-data envFrom: - secretRef: name: odoosecretenv @@ -45,3 +47,6 @@ spec: - name: runboat-scripts configMap: name: runboat-scripts + - name: odoo-data + persistentVolumeClaim: + claimName: odoo-data diff --git a/src/runboat/kubefiles/initialize.yaml b/src/runboat/kubefiles/initialize.yaml index e3348f5..ea0404a 100644 --- a/src/runboat/kubefiles/initialize.yaml +++ b/src/runboat/kubefiles/initialize.yaml @@ -13,6 +13,8 @@ spec: volumeMounts: - name: runboat-scripts mountPath: /runboat + - name: odoo-data + mountPath: /opt/odoo-data envFrom: - secretRef: name: odoosecretenv @@ -30,6 +32,9 @@ spec: - name: runboat-scripts configMap: name: runboat-scripts + - name: odoo-data + persistentVolumeClaim: + claimName: odoo-data restartPolicy: Never backoffLimit: 0 activeDeadlineSeconds: 1200 diff --git a/src/runboat/kubefiles/kustomization.yaml.jinja b/src/runboat/kubefiles/kustomization.yaml.jinja index ccdec8d..71aaadb 100644 --- a/src/runboat/kubefiles/kustomization.yaml.jinja +++ b/src/runboat/kubefiles/kustomization.yaml.jinja @@ -1,9 +1,11 @@ resources: {%- if mode == 'deployment' %} + - pvc.yaml - deployment.yaml - service.yaml - ingress.yaml {%- elif mode == "initialize" %} + - pvc.yaml - initialize.yaml {%- elif mode == "cleanup" %} - cleanup.yaml diff --git a/src/runboat/kubefiles/pvc.yaml b/src/runboat/kubefiles/pvc.yaml new file mode 100644 index 0000000..0ad27ab --- /dev/null +++ b/src/runboat/kubefiles/pvc.yaml @@ -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 diff --git a/src/runboat/kubefiles/runboat-initialize.sh b/src/runboat/kubefiles/runboat-initialize.sh index 1e056cf..2dac4df 100755 --- a/src/runboat/kubefiles/runboat-initialize.sh +++ b/src/runboat/kubefiles/runboat-initialize.sh @@ -16,6 +16,7 @@ dropdb --if-exists $PGDATABASE ADDONS=$(addons --addons-dir ${ADDONS_DIR} --include "${INCLUDE}" --exclude "${EXCLUDE}" list) unbuffer $(which odoo || which openerp-server) \ + --data-dir=/opt/odoo-data \ -d ${PGDATABASE} \ -i ${ADDONS:-base} \ --stop-after-init diff --git a/src/runboat/kubefiles/runboat-start.sh b/src/runboat/kubefiles/runboat-start.sh index 278d29c..68827ae 100755 --- a/src/runboat/kubefiles/runboat-start.sh +++ b/src/runboat/kubefiles/runboat-start.sh @@ -11,4 +11,5 @@ bash /runboat/runboat-clone-and-install.sh oca_wait_for_postgres unbuffer $(which odoo || which openerp-server) \ + --data-dir=/opt/odoo-data \ -d ${PGDATABASE} diff --git a/tests/test_render_kubefiles.py b/tests/test_render_kubefiles.py index 5e2c914..b54ccbf 100644 --- a/tests/test_render_kubefiles.py +++ b/tests/test_render_kubefiles.py @@ -2,6 +2,7 @@ from runboat.k8s import DeploymentMode, _render_kubefiles, make_deployment_vars EXPECTED = """\ resources: + - pvc.yaml - deployment.yaml - service.yaml - ingress.yaml