Skip to content

Commit

Permalink
Include instance configurations in Helm values (#790)
Browse files Browse the repository at this point in the history
* change how helm is configured

* up

* fix

* fix

* fix

* f

* f

* f

* up

* u

* up

* Update lapis-ingress.yaml

* fix lapis urls

* up

* add docs

* add values file arg to deploy.py

* fix

* up
  • Loading branch information
theosanderson committed Jan 19, 2024
1 parent a7cf2b3 commit 812c2f5
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 157 deletions.
10 changes: 9 additions & 1 deletion deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CLUSTER_NAME = 'testCluster'
HELM_RELEASE_NAME = 'preview'
HELM_CHART_DIR = ROOT_DIR / 'kubernetes' / 'loculus'
HELM_VALUES_FILE = HELM_CHART_DIR / 'values.yaml'

WEBSITE_PORT_MAPPING = '-p 3000:30081@agent:0'
BACKEND_PORT_MAPPING = '-p 8079:30082@agent:0'
Expand All @@ -37,6 +38,8 @@
helm_parser.add_argument('--uninstall', action='store_true', help='Uninstall installation')
helm_parser.add_argument('--enablePreprocessing', action='store_true',
help='Include deployment of preprocessing pipelines')
helm_parser.add_argument('--values', help='Values file for helm chart',
default=HELM_VALUES_FILE)

upgrade_parser = subparsers.add_parser('upgrade', help='Upgrade helm installation')

Expand Down Expand Up @@ -112,6 +115,7 @@ def handle_helm():

parameters = [
'helm', 'install', HELM_RELEASE_NAME, HELM_CHART_DIR,
'-f', args.values,
'--set', "environment=local",
'--set', f"branch={branch}",
'--set', f"dockerconfigjson={docker_config_json}",
Expand All @@ -136,7 +140,11 @@ def get_docker_config_json():


def handle_helm_upgrade():
subprocess.run(['helm', 'upgrade', HELM_RELEASE_NAME, HELM_CHART_DIR], check=True)
parameters = [
'helm', 'upgrade', HELM_RELEASE_NAME, HELM_CHART_DIR,
'-f', args.values
]
subprocess.run(parameters, check=True)


if __name__ == '__main__':
Expand Down
23 changes: 22 additions & 1 deletion kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ The Helm variable `environment` reflects those purposes:
* `local`: Running locally with ports
* `server`: Running on a server with domain name

## Deploying on a Kubernetes cluster

### Prerequisites

Install [helm](https://helm.sh/) and use [traefik](https://traefik.io/traefik/) for ingress.

Create a long-lived managed database: [to be documented as part of: https://github.com/loculus-project/loculus/issues/793]

Create your own configuration, by copying the `loculus/values.yaml` file and editing it as appropriate.

### Deployment

Install the Helm chart:

```
helm install loculus kubernetes/loculus -f my-values.yaml
```

# Local development/testing with k3d

## Prerequisites

Install [k3d](https://k3d.io/v5.6.0/) and [helm](https://helm.sh/).
Expand All @@ -20,7 +40,7 @@ Install [k3d](https://k3d.io/v5.6.0/) and [helm](https://helm.sh/).

Start the [backend](/backend/README.md) and the [website](/website/README.md) locally.

### The `deploy.py` script
#### The `deploy.py` script

The `deploy.py` script wraps the most important `k3d` and `helm` commands.
Check the help for more information:
Expand Down Expand Up @@ -75,6 +95,7 @@ You can also delete the cluster with:
../deploy.py cluster --delete
```

With helm based commands you can customise the values yaml file with `--values [file.yaml]`.
## Argo CD

ArgoCD will aim to build preview instances for any open PR with the `preview` label. It may take 5 minutes for an instance to appear. The preview will appear at `[branch_name].preview.k3s.loculus.org`. Very long branch names, and some special characters, are not supported.
Expand Down
128 changes: 0 additions & 128 deletions kubernetes/loculus/config.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions kubernetes/loculus/templates/_common-metadata.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fields:
{{- define "loculus.generateWebsiteConfig" }}
{{- $commonMetadata := (include "loculus.commonMetadata" . | fromYaml).fields }}
instances:
{{- range $key, $instance := .instances }}
{{- range $key, $instance := $.Values.instances }}
{{ $key }}:
schema:
{{- with $instance.schema }}
Expand Down Expand Up @@ -65,7 +65,7 @@ fields:
{{/* Generate backend config from passed config object */}}
{{- define "loculus.generateBackendConfig" }}
instances:
{{- range $key, $instance := .instances }}
{{- range $key, $instance := $.Values.instances }}
{{ $key }}:
schema:
{{- with $instance.schema }}
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/loculus/templates/_lapis-urls.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{/* generates internal LAPIS urls from given config object */}}
{{ define "loculus.generateInternalLapisUrls"}}
{{ range $key, $_ := .instances }}
{{ range $key, $_ := $.Values.instances }}
"{{ $key -}}": "http://{{ template "loculus.lapisServiceName" $key }}:8080"
{{ end }}
{{ end }}
Expand Down
1 change: 0 additions & 1 deletion kubernetes/loculus/templates/ingressroute.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- if eq .Values.environment "server" }}
{{- $backendHost := printf "backend.%s" .Values.host }}
{{- $configFile := .Files.Get "config.yaml" | fromYaml }}
{{- $keycloakHost := printf "authentication.%s" .Values.host }}

apiVersion: traefik.containo.us/v1alpha1
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/loculus/templates/lapis-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- $lapisHost := printf "lapis.%s" .Values.host }}
{{- $configFile := .Files.Get "config.yaml" | fromYaml }}
{{- range $key, $_ := $configFile.instances }}
{{- range $key, $_ := $.Values.instances }}

---
apiVersion: traefik.containo.us/v1alpha1
Expand Down
4 changes: 1 addition & 3 deletions kubernetes/loculus/templates/lapis-service.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{{- $configFile := .Files.Get "config.yaml" | fromYaml }}

{{- range $key, $_ := $configFile.instances }}
{{- range $key, $_ := $.Values.instances }}
---
apiVersion: v1
kind: Service
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/loculus/templates/lapis-silo-database-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{{- $configFile := .Files.Get "config.yaml" | fromYaml }}
{{- $commonMetadata := (include "loculus.commonMetadata" . | fromYaml).fields }}
{{- $importScriptLines := .Files.Lines "silo_import_job.sh" }}

{{- range $key, $instance := $configFile.instances }}
{{- range $key, $instance := $.Values.instances }}
---
apiVersion: v1
kind: ConfigMap
Expand Down
4 changes: 1 addition & 3 deletions kubernetes/loculus/templates/lapis-silo-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{{- $configFile := .Files.Get "config.yaml" | fromYaml }}

{{- range $key, $_ := $configFile.instances }}
{{- range $key, $_ := $.Values.instances }}
---
apiVersion: apps/v1
kind: Deployment
Expand Down
4 changes: 1 addition & 3 deletions kubernetes/loculus/templates/lapis-silo-import-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{{- $configFile := .Files.Get "config.yaml" | fromYaml }}

{{- $keycloakTokenUrl := "http://loculus-keycloak-service:8083/realms/loculusRealm/protocol/openid-connect/token" }}


{{- range $key, $_ := $configFile.instances }}
{{- range $key, $_ := $.Values.instances }}
---
apiVersion: batch/v1
kind: CronJob
Expand Down
4 changes: 1 addition & 3 deletions kubernetes/loculus/templates/lapis-silo-shared-data.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{{- $configFile := .Files.Get "config.yaml" | fromYaml }}

{{- range $key, $_ := $configFile.instances }}
{{- range $key, $_ := $.Values.instances }}
---
apiVersion: v1
kind: PersistentVolumeClaim
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/loculus/templates/loculus-backend-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ metadata:
namespace: {{ .Values.namespace }}
data:
backend_config.json: |
{{ .Files.Get "config.yaml" | fromYaml | include "loculus.generateBackendConfig" | fromYaml | toJson }}
{{ include "loculus.generateBackendConfig" . | fromYaml | toJson }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{- $dockerTag := include "loculus.dockerTag" .Values }}
{{ $configFile := .Files.Get "config.yaml" | fromYaml }}
{{ $backendHost := .Values.disableBackend | ternary
"http://host.k3d.internal:8079"
"http://loculus-backend-service:8079"
Expand Down Expand Up @@ -28,7 +27,7 @@ spec:
component: loculus-preprocessing
spec:
containers:
{{- range $key, $_ := $configFile.instances }}
{{- range $key, $_ := $.Values.instances }}
- name: preprocessing-{{ $key }}
image: ghcr.io/loculus-project/preprocessing-dummy:{{ $dockerTag }}
imagePullPolicy: Always
Expand Down
7 changes: 3 additions & 4 deletions kubernetes/loculus/templates/loculus-website-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{{- $keycloakHost := printf "authentication.%s" .Values.host }}
{{- $config := .Files.Get "config.yaml" | fromYaml }}
{{- $lapisHost := (
eq .Values.environment "server" | ternary
(printf "https://lapis.%s" .Values.host)
"http://localhost:8080"
) }}
{{- $externalLapisUrlConfig := dict
"host" $lapisHost
"config" $config
"config" $.Values
}}

---
Expand All @@ -18,7 +17,7 @@ metadata:
namespace: {{ .Values.namespace }}
data:
website_config.json: |
{{ .Files.Get "config.yaml" | fromYaml | include "loculus.generateWebsiteConfig" | fromYaml | toJson }}
{{ include "loculus.generateWebsiteConfig" . | fromYaml | toJson }}
runtime_config.json: |
{
Expand All @@ -28,7 +27,7 @@ data:
{{- else }}
"backendUrl": "http://localhost:8079",
{{- end }}
"lapisUrls": {{- include "loculus.generateInternalLapisUrls" $config | fromYaml | toJson }},
"lapisUrls": {{- include "loculus.generateInternalLapisUrls" . | fromYaml | toJson }},
"keycloakUrl": "http://loculus-keycloak-service:8083"
},
"public": {
Expand Down
129 changes: 129 additions & 0 deletions kubernetes/loculus/values.yaml

Large diffs are not rendered by default.

0 comments on commit 812c2f5

Please sign in to comment.