From 3560fa4833a30c6511f7ca6ff3ba285231f56a71 Mon Sep 17 00:00:00 2001 From: illomi7 Date: Mon, 29 Apr 2024 10:52:03 +0200 Subject: [PATCH] trino 0.2.0: Add support for statefulset and persistance on trino helm chart --- charts/trino/Chart.yaml | 4 +- charts/trino/templates/_helpers.tpl | 8 +++ ...ator.yaml => application-coordinator.yaml} | 59 +++++++++++++++++-- ...nt-worker.yaml => application-worker.yaml} | 56 +++++++++++++++++- charts/trino/values.schema.json | 23 ++++++++ charts/trino/values.yaml | 36 ++++++++++- 6 files changed, 177 insertions(+), 9 deletions(-) rename charts/trino/templates/{deployment-coordinator.yaml => application-coordinator.yaml} (65%) rename charts/trino/templates/{deployment-worker.yaml => application-worker.yaml} (68%) create mode 100644 charts/trino/values.schema.json diff --git a/charts/trino/Chart.yaml b/charts/trino/Chart.yaml index 932fbc3..0a093e1 100644 --- a/charts/trino/Chart.yaml +++ b/charts/trino/Chart.yaml @@ -15,9 +15,9 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.44 +version: 0.2.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. -appVersion: '444' +appVersion: '445' diff --git a/charts/trino/templates/_helpers.tpl b/charts/trino/templates/_helpers.tpl index 93afcfb..ebb1d25 100644 --- a/charts/trino/templates/_helpers.tpl +++ b/charts/trino/templates/_helpers.tpl @@ -35,10 +35,18 @@ Create chart name and version as used by the chart label. {{ template "trino.fullname" . }}-coordinator {{- end -}} +{{- define "trino.coordinator.svcName" -}} +{{ template "trino.coordinator" . }}-headless +{{- end -}} + {{- define "trino.worker" -}} {{ template "trino.fullname" . }}-worker {{- end -}} +{{- define "trino.worker.svcName" -}} +{{ template "trino.worker" . }}-headless +{{- end -}} + {{- define "trino.connectors" -}} {{ template "trino.fullname" . }}-connectors {{- end -}} diff --git a/charts/trino/templates/deployment-coordinator.yaml b/charts/trino/templates/application-coordinator.yaml similarity index 65% rename from charts/trino/templates/deployment-coordinator.yaml rename to charts/trino/templates/application-coordinator.yaml index fb28b35..7e74fc9 100644 --- a/charts/trino/templates/deployment-coordinator.yaml +++ b/charts/trino/templates/application-coordinator.yaml @@ -1,5 +1,5 @@ apiVersion: apps/v1 -kind: Deployment +kind: {{ .Values.server.kind }} metadata: name: {{ template "trino.coordinator" . }} labels: @@ -9,11 +9,15 @@ metadata: heritage: {{ .Release.Service }} component: coordinator spec: + selector: matchLabels: app: {{ template "trino.name" . }} release: {{ .Release.Name }} component: coordinator + {{ if (eq .Values.server.kind "StatefulSet") }} + serviceName: {{ template "trino.coordinator.svcName" . }} + {{ end }} template: metadata: labels: @@ -27,8 +31,7 @@ spec: {{- end }} {{- with .Values.securityContext }} securityContext: - runAsUser: {{ .runAsUser }} - runAsGroup: {{ .runAsGroup }} + fsGroup: {{ .runAsGroup }} {{- end }} volumes: - name: config-volume @@ -41,16 +44,33 @@ spec: - name: config-jmx-exporter configMap: name: {{ template "trino.jmx-exporter" . }} - {{ end }} + {{ end }} + {{ if or (not .Values.worker.persistence.enabled) (not (eq .Values.server.kind "StatefulSet")) }} + - name: trino-data + emptyDir: {} + {{ end }} containers: - name: {{ .Chart.Name }}-coordinator image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + + {{- with .Values.securityContext }} + securityContext: + runAsUser: {{ .runAsUser }} + runAsGroup: {{ .runAsGroup }} + {{- end }} volumeMounts: - mountPath: {{ .Values.server.config.path }} name: config-volume - mountPath: {{ .Values.server.config.path }}/catalog name: connectors-config-volume + - name: trino-data + mountPath: {{ .Values.coordinator.persistence.path }} + {{- if .Values.coordinator.persistence.subPath }} + subPath: {{ .Values.coordinator.persistence.subPath }} + {{- else if .Values.coordinator.persistence.subPathExpr }} + subPathExpr: {{ .Values.coordinator.persistence.subPathExpr }} + {{- end }} ports: - name: http containerPort: {{ .Values.service.port }} @@ -123,3 +143,34 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + + {{ if and (.Values.worker.persistence.enabled ) (eq .Values.server.kind "StatefulSet") }} + + {{ if .Values.coordinator.persistentVolumeClaimRetentionPolicy.enabled }} + persistentVolumeClaimRetentionPolicy: + whenDeleted: {{ .Values.coordinator.persistentVolumeClaimRetentionPolicy.whenDeleted }} + whenScaled: {{ .Values.coordinator.persistentVolumeClaimRetentionPolicy.whenScaled }} + {{ end }} + + volumeClaimTemplates: + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: trino-data + labels: + app: {{ template "trino.name" . }} + chart: {{ template "trino.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + component: coordinator + spec: + storageClassName: {{ .Values.worker.persistence.storageClass | quote }} + accessModes: + {{ range .Values.coordinator.persistence.accessModes }} + - {{ . | quote }} + {{ end }} + resources: + requests: + storage: {{ .Values.coordinator.persistence.size | quote }} + {{ end }} + diff --git a/charts/trino/templates/deployment-worker.yaml b/charts/trino/templates/application-worker.yaml similarity index 68% rename from charts/trino/templates/deployment-worker.yaml rename to charts/trino/templates/application-worker.yaml index 0db59e3..9446e92 100644 --- a/charts/trino/templates/deployment-worker.yaml +++ b/charts/trino/templates/application-worker.yaml @@ -1,6 +1,6 @@ {{- if gt (int .Values.server.workers) 0 }} apiVersion: apps/v1 -kind: Deployment +kind: {{ .Values.server.kind }} metadata: name: {{ template "trino.worker" . }} labels: @@ -11,6 +11,9 @@ metadata: component: worker spec: replicas: {{ .Values.server.workers }} + {{ if (eq .Values.server.kind "StatefulSet") }} + serviceName: {{ template "trino.worker.svcName" . }} + {{ end }} selector: matchLabels: app: {{ template "trino.name" . }} @@ -27,6 +30,10 @@ spec: imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} + {{- with .Values.securityContext }} + securityContext: + fsGroup: {{ .runAsGroup }} + {{- end }} volumes: - name: config-volume configMap: @@ -39,16 +46,32 @@ spec: configMap: name: {{ template "trino.jmx-exporter" . }} {{ end }} + {{ if or (not .Values.worker.persistence.enabled) (not (eq .Values.server.kind "StatefulSet")) }} + - name: trino-data + emptyDir: {} + {{ end }} terminationGracePeriodSeconds: {{ .Values.server.gracefulShutdown.gracePeriodSeconds }} containers: - name: {{ .Chart.Name }}-worker image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- with .Values.securityContext }} + securityContext: + runAsUser: {{ .runAsUser }} + runAsGroup: {{ .runAsGroup }} + {{- end }} volumeMounts: - mountPath: {{ .Values.server.config.path }} name: config-volume - mountPath: {{ .Values.server.config.path }}/catalog name: connectors-config-volume + - name: trino-data + mountPath: {{ .Values.worker.persistence.path }} + {{- if .Values.worker.persistence.subPath }} + subPath: {{ .Values.worker.persistence.subPath }} + {{- else if .Values.worker.persistence.subPathExpr }} + subPathExpr: {{ .Values.worker.persistence.subPathExpr }} + {{- end }} ports: - name: http containerPort: {{ .Values.service.port }} @@ -129,4 +152,35 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + + + {{ if and (.Values.worker.persistence.enabled ) (eq .Values.server.kind "StatefulSet") }} + + {{ if .Values.worker.persistentVolumeClaimRetentionPolicy.enabled }} + persistentVolumeClaimRetentionPolicy: + whenDeleted: { { .Values.worker.persistentVolumeClaimRetentionPolicy.whenDeleted } } + whenScaled: { { .Values.worker.persistentVolumeClaimRetentionPolicy.whenScaled } } + {{ end }} + + volumeClaimTemplates: + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: trino-data + labels: + app: {{ template "trino.name" . }} + chart: {{ template "trino.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + component: worker + spec: + storageClassName: {{ .Values.worker.persistence.storageClass | quote }} + accessModes: + {{ range .Values.worker.persistence.accessModes }} + - {{ . | quote }} + {{ end }} + resources: + requests: + storage: {{ .Values.worker.persistence.size | quote }} + {{ end }} {{- end }} diff --git a/charts/trino/values.schema.json b/charts/trino/values.schema.json new file mode 100644 index 0000000..f8680b4 --- /dev/null +++ b/charts/trino/values.schema.json @@ -0,0 +1,23 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "server": { + "type": "object", + "title": "Server settings", + "form": true, + "properties": { + "kind": { + "type": "string", + "title": "Workload Kind", + "form": true, + "description": "Allowed values: `Deployment`or `StatefulSet`", + "enum": [ + "Deployment", + "StatefulSet" + ] + } + } + } + } +} \ No newline at end of file diff --git a/charts/trino/values.yaml b/charts/trino/values.yaml index 7a67338..7e5c512 100644 --- a/charts/trino/values.yaml +++ b/charts/trino/values.yaml @@ -3,12 +3,13 @@ # Declare variables to be passed into your templates. image: - repository: trinodb/trino + repository: trinodb/trino pullPolicy: IfNotPresent - tag: 444 + tag: 445 imagePullSecrets: [] server: + kind: Deployment workers: 2 node: environment: production @@ -64,12 +65,43 @@ coordinator: tolerations: [] affinity: {} resources: {} + persistence: + enabled: false + path: /data + subPath: "" + subPathExpr: "" + storageClass: "" + accessModes: + - ReadWriteOnce + size: 8Gi + dataSource: { } + existingClaim: "" + persistentVolumeClaimRetentionPolicy: + enabled: false + whenScaled: Retain + whenDeleted: Retain worker: nodeSelector: {} tolerations: [] affinity: {} resources: {} + persistence: + enabled: false + path: /data + subPath: "" + subPathExpr: "" + storageClass: "" + accessModes: + - ReadWriteOnce + size: 8Gi + selector: { } + dataSource: { } + existingClaim: "" + persistentVolumeClaimRetentionPolicy: + enabled: false + whenScaled: Retain + whenDeleted: Retain exporters: jmx: