diff --git a/charts/prefect-server/README.md b/charts/prefect-server/README.md index f796ce8..87d49f5 100644 --- a/charts/prefect-server/README.md +++ b/charts/prefect-server/README.md @@ -109,6 +109,29 @@ prefect-server: postgresql+asyncpg://{username}:{password}@{hostname}/{database}?ssl=verify-ca ``` +## SQLite Configuration + +SQLite can be used as an alternative to PostgreSQL. As mentioned in the +[documentation on hosting Prefect](https://docs-3.prefect.io/v3/manage/self-host), +SQLite is only recommended for lightweight, single-server deployments. + +To use SQLite for the database, provide the following configuration values: + +```yaml +postgresql: + enabled: false +sqlite: + enabled: true +``` + +More configuration options are available in [`values.yaml`](./values.yaml). + +By default, a PersistentVolumeClaim persists the SQLite database file between +Pod restarts. + +Note that enabling SQLite enforces 1 replica in the Deployment, and disables +the HorizontalPodAutoscaler. + ## Maintainers | Name | Email | Url | @@ -227,6 +250,10 @@ prefect-server: | serviceAccount.annotations | object | `{}` | additional service account annotations (evaluated as a template) | | serviceAccount.create | bool | `true` | specifies whether a ServiceAccount should be created | | serviceAccount.name | string | `""` | the name of the ServiceAccount to use. if not set and create is true, a name is generated using the common.names.fullname template | +| sqlite.enabled | bool | `false` | enable use of the embedded SQLite database | +| sqlite.persistence.enabled | bool | `true` | enable SQLite data persistence using PVC | +| sqlite.persistence.size | string | `"1Gi"` | size for the PVC | +| sqlite.persistence.storageClassName | string | `""` | storage class name for the PVC | ---------------------------------------------- Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1) diff --git a/charts/prefect-server/templates/deployment.yaml b/charts/prefect-server/templates/deployment.yaml index 73e15ca..5aa42d5 100644 --- a/charts/prefect-server/templates/deployment.yaml +++ b/charts/prefect-server/templates/deployment.yaml @@ -14,7 +14,7 @@ metadata: {{- end }} spec: revisionHistoryLimit: {{ .Values.server.revisionHistoryLimit }} - replicas: {{ .Values.server.replicaCount }} + replicas: {{ .Values.sqlite.enabled | ternary 1 .Values.server.replicaCount }} selector: matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }} app.kubernetes.io/component: server @@ -99,10 +99,14 @@ spec: - name: PREFECT_UI_STATIC_DIRECTORY value: {{ .Values.server.uiConfig.prefectUiStaticDirectory | quote }} - name: PREFECT_API_DATABASE_CONNECTION_URL + {{- if .Values.sqlite.enabled }} + value: "sqlite+aiosqlite:////data/prefect.db" + {{- else }} valueFrom: secretKeyRef: name: {{ include "server.postgres-string-secret-name" . }} key: connection-string + {{- end }} {{- if .Values.server.env }} {{- include "common.tplvalues.render" (dict "value" .Values.server.env "context" $) | nindent 12 }} {{- end }} @@ -145,6 +149,10 @@ spec: - mountPath: {{ .Values.server.uiConfig.prefectUiStaticDirectory }} name: scratch subPathExpr: ui-build + {{- if .Values.sqlite.enabled }} + - mountPath: /data + name: sqlite-storage + {{- end }} {{- if .Values.server.extraVolumeMounts }} {{- include "common.tplvalues.render" (dict "value" .Values.server.extraVolumeMounts "context" $) | nindent 12 }} {{- end }} @@ -154,6 +162,11 @@ spec: volumes: - name: scratch emptyDir: {} + {{- if .Values.sqlite.enabled }} + - name: sqlite-storage + persistentVolumeClaim: + claimName: {{ template "common.names.fullname" . }}-sqlite + {{- end }} {{- if .Values.server.extraVolumes }} {{- include "common.tplvalues.render" (dict "value" .Values.server.extraVolumes "context" $) | nindent 8 }} {{- end }} diff --git a/charts/prefect-server/templates/hpa.yaml b/charts/prefect-server/templates/hpa.yaml index d926b15..e76968f 100644 --- a/charts/prefect-server/templates/hpa.yaml +++ b/charts/prefect-server/templates/hpa.yaml @@ -1,4 +1,4 @@ -{{- if and .Values.server.autoscaling.enabled .Values.server.resources.requests }} +{{- if and .Values.server.autoscaling.enabled .Values.server.resources.requests (not .Values.sqlite.enabled) }} apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: diff --git a/charts/prefect-server/templates/pvc.yaml b/charts/prefect-server/templates/pvc.yaml new file mode 100644 index 0000000..2028f89 --- /dev/null +++ b/charts/prefect-server/templates/pvc.yaml @@ -0,0 +1,16 @@ +{{- if and .Values.sqlite.enabled .Values.sqlite.persistence.enabled }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ template "common.names.fullname" . }}-sqlite + namespace: {{.Release.Namespace}} +spec: + {{- with .Values.sqlite.persistence.storageClassName }} + storageClassName: {{.}} + {{- end }} + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{.Values.sqlite.persistence.size}} +{{- end }} diff --git a/charts/prefect-server/templates/secret.yaml b/charts/prefect-server/templates/secret.yaml index a863efd..66a65b3 100644 --- a/charts/prefect-server/templates/secret.yaml +++ b/charts/prefect-server/templates/secret.yaml @@ -1,4 +1,4 @@ -{{- if .Values.secret.create }} +{{- if and .Values.secret.create (not .Values.sqlite.enabled) }} apiVersion: v1 kind: Secret metadata: diff --git a/charts/prefect-server/tests/database_test.yaml b/charts/prefect-server/tests/database_test.yaml index 60ed1db..5a646b9 100644 --- a/charts/prefect-server/tests/database_test.yaml +++ b/charts/prefect-server/tests/database_test.yaml @@ -8,6 +8,81 @@ envSecretPath: &envSecretPath .spec.template.spec.containers[?(@.name == "prefec defaultSecretName: &defaultSecretName prefect-server-postgresql-connection tests: + # SQLite embedded database tests + + - it: Should correctly configure SQLite connection string + set: + postgresql: + enabled: false + sqlite: + enabled: true + asserts: + - template: deployment.yaml + contains: + path: .spec.template.spec.containers[0].env + content: + name: PREFECT_API_DATABASE_CONNECTION_URL + value: sqlite+aiosqlite:////data/prefect.db + + - it: Should correctly configure SQLite storage settings + set: + postgresql: + enabled: false + sqlite: + enabled: true + asserts: + - template: deployment.yaml + contains: + path: .spec.template.spec.volumes + content: + name: sqlite-storage + persistentVolumeClaim: + claimName: prefect-server-sqlite + - template: deployment.yaml + contains: + path: .spec.template.spec.containers[0].volumeMounts + content: + mountPath: /data + name: sqlite-storage + - template: pvc.yaml + containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: prefect-server-sqlite + namespace: prefect + + - it: Should not allow an HPA + set: + postgresql: + enabled: false + sqlite: + enabled: true + server: + autoscaling: + enabled: true + asserts: + - template: hpa.yaml + not: true + containsDocument: + apiVersion: autoscaling/v2 + kind: HorizontalPodAutoscaler + name: prefect-server + namespace: prefect + + - it: Should not allow more than 1 replica + set: + postgresql: + enabled: false + sqlite: + enabled: true + server: + replicaCount: 5 + asserts: + - template: deployment.yaml + equal: + path: .spec.replicas + value: 1 + # Bundled PostgreSQL chart tests - it: Should produce the expected secret name and content with the defaults diff --git a/charts/prefect-server/tests/server_test.yaml b/charts/prefect-server/tests/server_test.yaml index a7249b5..c8fe886 100644 --- a/charts/prefect-server/tests/server_test.yaml +++ b/charts/prefect-server/tests/server_test.yaml @@ -462,9 +462,11 @@ tests: mountPath: /app/config asserts: - template: deployment.yaml - equal: - path: .spec.template.spec.containers[0].volumeMounts[3].name - value: config + contains: + path: .spec.template.spec.containers[0].volumeMounts + content: + name: config + mountPath: /app/config - it: Should set extra arguments set: @@ -600,4 +602,4 @@ tests: - template: hpa.yaml equal: path: .spec.metrics[1].resource.target.averageUtilization - value: 80 \ No newline at end of file + value: 80 diff --git a/charts/prefect-server/values.schema.json b/charts/prefect-server/values.schema.json index 2cf6b01..ee5a707 100644 --- a/charts/prefect-server/values.schema.json +++ b/charts/prefect-server/values.schema.json @@ -441,6 +441,42 @@ } } }, + "sqlite": { + "type": "object", + "title": "SQLite", + "description": "sqlite configuration", + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "enable sqlite database" + }, + "persistence": { + "type": "object", + "title": "Persistence", + "description": "persistence settings for sqlite", + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "enable sqlite database persistence" + }, + "size": { + "type": "string", + "title": "Size", + "description": "size of the persistent volume claim" + }, + "storageClassName": { + "type": "string", + "title": "Storage class name", + "description": "storage class name for the persistent volume claim" + } + } + } + } + }, "serviceAccount": { "type": "object", "title": "Service Account", diff --git a/charts/prefect-server/values.yaml b/charts/prefect-server/values.yaml index e175355..0874adb 100644 --- a/charts/prefect-server/values.yaml +++ b/charts/prefect-server/values.yaml @@ -315,6 +315,20 @@ secret: # -- database for the PostgreSQL connection string database: "" +# SQLite configuration +# Recommended for lightweight, single-server deployments. +sqlite: + # -- enable use of the embedded SQLite database + enabled: false + + persistence: + # -- enable SQLite data persistence using PVC + enabled: true + # -- size for the PVC + size: 1Gi + # -- storage class name for the PVC + storageClassName: "" + # PostgreSQL subchart - default overrides postgresql: # -- enable use of bitnami/postgresql subchart