From 801790ed05227d4974ea33015e58b9a055ed938d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Tue, 9 Nov 2021 20:03:05 +0100 Subject: [PATCH] Make filestore storage class configurable Also, use kustomize patches instead of vars. --- .env.sample | 1 + .env.test | 1 + .gitignore | 1 + src/runboat/k8s.py | 2 ++ src/runboat/kubefiles/ingress.yaml | 3 +- .../kubefiles/kustomization.yaml.jinja | 30 +++++++++---------- src/runboat/kubefiles/pvc.yaml | 1 - src/runboat/settings.py | 3 ++ tests/test_render_kubefiles.py | 28 +++++++++-------- 9 files changed, 40 insertions(+), 30 deletions(-) diff --git a/.env.sample b/.env.sample index dded35b..d5c57cc 100644 --- a/.env.sample +++ b/.env.sample @@ -5,6 +5,7 @@ RUNBOAT_BUILD_NAMESPACE=runboat-builds RUNBOAT_BUILD_DOMAIN=runboat-builds.odoo-community.org RUNBOAT_BUILD_ENV={"PGHOST": "postgres14.runboat-builds-db", "PGPORT": "5432", "PGUSER": "runboat-build"} RUNBOAT_BUILD_SECRET_ENV={"PGPASSWORD": "..."} +RUNBOAT_BUILD_TEMPLATE_VARS={"storageClassName": "my-storage-class"} RUNBOAT_GITHUB_TOKEN= RUNBOAT_LOG_CONFIG=log-config.yaml RUNBOAT_BASE_URL=https://runboat.odoo-community.org diff --git a/.env.test b/.env.test index bc5167f..3f6543d 100644 --- a/.env.test +++ b/.env.test @@ -5,6 +5,7 @@ RUNBOAT_BUILD_NAMESPACE=runboat-builds RUNBOAT_BUILD_DOMAIN=runboat.odoo-community.org RUNBOAT_BUILD_ENV={} RUNBOAT_BUILD_SECRET_ENV={"PGPASSWORD": "thepgpassword"} +RUNBOAT_BUILD_TEMPLATE_VARS={"storageClassName": "my-storage-class"} RUNBOAT_GITHUB_TOKEN= RUNBOAT_LOG_CONFIG=log-config.yaml RUNBOAT_BUILD_IMAGES={"15.0": "ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest"} diff --git a/.gitignore b/.gitignore index 6f63f68..2666983 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ tmp/ +src/runboat/kubefiles/kustomization.yaml # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/src/runboat/k8s.py b/src/runboat/k8s.py index 2b27d1b..66c322d 100644 --- a/src/runboat/k8s.py +++ b/src/runboat/k8s.py @@ -142,6 +142,7 @@ class DeploymentVars(BaseModel): image_tag: str build_env: dict[str, str] build_secret_env: dict[str, str] + build_template_vars: dict[str, str] def make_deployment_vars( @@ -169,6 +170,7 @@ def make_deployment_vars( image_tag=image_tag, build_env=settings.build_env or {}, build_secret_env=settings.build_secret_env or {}, + build_template_vars=settings.build_template_vars or {}, ) diff --git a/src/runboat/kubefiles/ingress.yaml b/src/runboat/kubefiles/ingress.yaml index a915c86..117ec8e 100644 --- a/src/runboat/kubefiles/ingress.yaml +++ b/src/runboat/kubefiles/ingress.yaml @@ -4,8 +4,7 @@ metadata: name: odoo spec: rules: - - host: $(HOSTNAME) - http: + - http: paths: - path: / pathType: Prefix diff --git a/src/runboat/kubefiles/kustomization.yaml.jinja b/src/runboat/kubefiles/kustomization.yaml.jinja index 71aaadb..86d5c09 100644 --- a/src/runboat/kubefiles/kustomization.yaml.jinja +++ b/src/runboat/kubefiles/kustomization.yaml.jinja @@ -52,22 +52,22 @@ configMapGenerator: - runboat-initialize.sh - runboat-cleanup.sh - runboat-start.sh - {%- if mode == 'deployment' %} - - name: vars - literals: - - HOSTNAME={{ build_slug }}.{{ build_domain }} - {%- endif %} generatorOptions: disableNameSuffixHash: true -{% if mode == 'deployment' -%} -vars: - - name: HOSTNAME - objref: - name: vars - kind: ConfigMap - apiVersion: v1 - fieldref: - fieldpath: data.HOSTNAME -{% endif %} +patches: + - target: + kind: PersistentVolumeClaim + name: odoo-data + patch: |- + - op: replace + path: /spec/storageClassName + value: {{ build_template_vars["storageClassName"] }} + - target: + kind: Ingress + name: odoo + patch: |- + - op: replace + path: /spec/rules/0/host + value: {{ build_slug }}.{{ build_domain }} diff --git a/src/runboat/kubefiles/pvc.yaml b/src/runboat/kubefiles/pvc.yaml index 0ad27ab..f78b347 100644 --- a/src/runboat/kubefiles/pvc.yaml +++ b/src/runboat/kubefiles/pvc.yaml @@ -3,7 +3,6 @@ kind: PersistentVolumeClaim metadata: name: odoo-data spec: - storageClassName: openebs-zfs-localpv-slow # TODO make this configurable accessModes: - ReadWriteOnce resources: diff --git a/src/runboat/settings.py b/src/runboat/settings.py index 538cfcf..bff321e 100644 --- a/src/runboat/settings.py +++ b/src/runboat/settings.py @@ -24,6 +24,9 @@ class Settings(BaseSettings): # A dictionary of secret environment variables to set in the build container and # jobs. build_secret_env: Optional[dict[str, str]] + # A dictionary of variables to be set in the jinja rendering context for the + # kubefiles. + build_template_vars: Optional[dict[str, str]] # A mapping of main branch names to container images used to run the builds. build_images: dict[str, str] = { "15.0": "ghcr.io/oca/oca-ci/py3.8-odoo15.0:latest", diff --git a/tests/test_render_kubefiles.py b/tests/test_render_kubefiles.py index b54ccbf..855e9a9 100644 --- a/tests/test_render_kubefiles.py +++ b/tests/test_render_kubefiles.py @@ -43,21 +43,25 @@ configMapGenerator: - runboat-initialize.sh - runboat-cleanup.sh - runboat-start.sh - - name: vars - literals: - - HOSTNAME=build-slug.runboat.odoo-community.org generatorOptions: disableNameSuffixHash: true -vars: - - name: HOSTNAME - objref: - name: vars - kind: ConfigMap - apiVersion: v1 - fieldref: - fieldpath: data.HOSTNAME +patches: + - target: + kind: PersistentVolumeClaim + name: odoo-data + patch: |- + - op: replace + path: /spec/storageClassName + value: my-storage-class + - target: + kind: Ingress + name: odoo + patch: |- + - op: replace + path: /spec/rules/0/host + value: build-slug.runboat.odoo-community.org """ @@ -76,4 +80,4 @@ def test_render_kubefiles(): assert (tmp_path / "kustomization.yaml").is_file() assert (tmp_path / "deployment.yaml").is_file() kustomization = (tmp_path / "kustomization.yaml").read_text() - assert kustomization == EXPECTED + assert kustomization.strip() == EXPECTED.strip()