Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prefect-server): support sqlite database #418

Merged
merged 9 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions charts/prefect-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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)
15 changes: 14 additions & 1 deletion charts/prefect-server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion charts/prefect-server/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
16 changes: 16 additions & 0 deletions charts/prefect-server/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion charts/prefect-server/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.secret.create }}
{{- if and .Values.secret.create (not .Values.sqlite.enabled) }}
apiVersion: v1
kind: Secret
metadata:
Expand Down
75 changes: 75 additions & 0 deletions charts/prefect-server/tests/database_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions charts/prefect-server/tests/server_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -600,4 +602,4 @@ tests:
- template: hpa.yaml
equal:
path: .spec.metrics[1].resource.target.averageUtilization
value: 80
value: 80
36 changes: 36 additions & 0 deletions charts/prefect-server/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions charts/prefect-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading