From 9b13138199b9162ab47867eee8d11806966ce2de Mon Sep 17 00:00:00 2001 From: everpcpc Date: Fri, 29 Mar 2024 18:12:41 +0800 Subject: [PATCH] feat(query): support workload type deployment --- .github/workflows/ci.yml | 12 +- charts/databend-meta/Chart.yaml | 2 +- charts/databend-query/Chart.yaml | 2 +- .../databend-query/templates/configmap.yaml | 5 +- .../databend-query/templates/deployment.yaml | 124 ++++++++++++++++++ charts/databend-query/templates/service.yaml | 2 + .../databend-query/templates/statefulset.yaml | 3 + charts/databend-query/values.yaml | 12 +- examples/query-cluster-as-deployment.yaml | 2 + 9 files changed, 150 insertions(+), 14 deletions(-) create mode 100644 charts/databend-query/templates/deployment.yaml create mode 100644 examples/query-cluster-as-deployment.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01adaab..146cfe7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,11 @@ concurrency: jobs: k3d: + strategy: + matrix: + workload: + - StatefulSet + - Deployment runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -59,7 +64,7 @@ jobs: --set bootstrap=true \ --set replicaCount=3 \ --set persistence.size=1Gi \ - --wait + --wait --timeout 1m0s kubectl get pods -n databend-meta - name: Install MinIO @@ -68,7 +73,7 @@ jobs: helm upgrade --install minio minio/minio \ --namespace minio --create-namespace \ --values tests/minio.yaml \ - --wait + --wait --timeout 1m0s - name: Install Databend Query shell: bash @@ -82,7 +87,8 @@ jobs: helm upgrade --install cluster1 . \ --namespace tenant1 --create-namespace \ --values ../../tests/query-with-minio.yaml \ - --wait + --set workload={{ matrix.workload }} \ + --wait --timeout 1m0s kubectl get pods -n tenant1 - name: Checking Cluster Status diff --git a/charts/databend-meta/Chart.yaml b/charts/databend-meta/Chart.yaml index b325b9a..83cfb2c 100644 --- a/charts/databend-meta/Chart.yaml +++ b/charts/databend-meta/Chart.yaml @@ -32,7 +32,7 @@ version: 0.7.3 # 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. # It is recommended to use it with quotes. -appVersion: "v1.2.279" +appVersion: "v1.2.371" dependencies: - name: common diff --git a/charts/databend-query/Chart.yaml b/charts/databend-query/Chart.yaml index f85179f..d4507fa 100644 --- a/charts/databend-query/Chart.yaml +++ b/charts/databend-query/Chart.yaml @@ -31,7 +31,7 @@ version: 0.8.3 # 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. # It is recommended to use it with quotes. -appVersion: "v1.2.279" +appVersion: "v1.2.371" dependencies: - name: common diff --git a/charts/databend-query/templates/configmap.yaml b/charts/databend-query/templates/configmap.yaml index 337c3e6..605fe8b 100644 --- a/charts/databend-query/templates/configmap.yaml +++ b/charts/databend-query/templates/configmap.yaml @@ -9,9 +9,6 @@ data: config.toml: |- # databend query config [query] - max_active_sessions = {{ .Values.config.query.maxActiveSessions | default 1024 }} - wait_timeout_mills = {{ .Values.config.query.waitTimeoutMills | default 5000 }} - tenant_id = {{ .Values.config.query.tenantId | default .Release.Name | quote }} cluster_id = {{ .Values.config.query.clusterId | quote }} @@ -83,7 +80,7 @@ data: {{- end }} {{- end }} - {{- if .Values.cache.enabled }} + {{- if .Values.cache.enabled && eq (lower .Values.workload) "statefulset" }} [cache] data_cache_storage = "disk" [cache.disk] diff --git a/charts/databend-query/templates/deployment.yaml b/charts/databend-query/templates/deployment.yaml new file mode 100644 index 0000000..2e8ef8c --- /dev/null +++ b/charts/databend-query/templates/deployment.yaml @@ -0,0 +1,124 @@ +{{- if eq (lower .Values.workload) "deployment" }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "databend-query.fullname" . }} + labels: + {{- include "databend-query.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "databend-query.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "databend-query.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "databend-query.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + initContainers: + {{- if .Values.initContainers }} + {{- include "common.tplvalues.render" (dict "value" .Values.initContainers "context" $) | trim | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + command: + - /databend-query + - -c + - /etc/databend-query/config.toml + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + {{- range $key, $val := .Values.service.ports }} + - name: {{ $key }} + containerPort: {{ $val}} + {{- end }} + livenessProbe: + httpGet: + path: /v1/health + port: admin + readinessProbe: + httpGet: + path: /v1/health + port: admin + initialDelaySeconds: 5 + periodSeconds: 15 + failureThreshold: 3 + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: QUERY_METRIC_API_ADDRESS + value: "$(POD_IP):{{ .Values.service.ports.metric | default 7070 }}" + - name: QUERY_ADMIN_API_ADDRESS + value: "$(POD_IP):{{ .Values.service.ports.admin | default 8080 }}" + - name: QUERY_FLIGHT_API_ADDRESS + value: "$(POD_IP):{{ .Values.service.ports.flight | default 9090 }}" + - name: QUERY_HTTP_HANDLER_HOST + value: 0.0.0.0 + - name: QUERY_HTTP_HANDLER_PORT + value: {{ .Values.service.ports.http | default 8000 | quote }} + - name: QUERY_FLIGHT_SQL_HANDLER_HOST + value: 0.0.0.0 + - name: QUERY_FLIGHT_SQL_HANDLER_PORT + value: {{ .Values.service.ports.flightsql | default 8900 | quote }} + - name: QUERY_MYSQL_HANDLER_HOST + value: 0.0.0.0 + - name: QUERY_MYSQL_HANDLER_PORT + value: {{ .Values.service.ports.mysql | default 3307 | quote }} + - name: QUERY_CLICKHOUSE_HTTP_HANDLER_HOST + value: 0.0.0.0 + - name: QUERY_CLICKHOUSE_HTTP_HANDLER_PORT + value: {{ .Values.service.ports.ckhttp |default 8124 | quote }} + {{- with .Values.envs }} + {{- toYaml . | nindent 12 }} + {{- end }} + volumeMounts: + - name: config + # Note: subPath volume mount will not receive ConfigMap update. + mountPath: /etc/databend-query + {{- if .Values.sidecars }} + {{- include "common.tplvalues.render" (dict "value" .Values.sidecars "context" $) | nindent 8 }} + {{- end }} + volumes: + - name: config + configMap: + name: {{ include "databend-query.fullname" .}} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/charts/databend-query/templates/service.yaml b/charts/databend-query/templates/service.yaml index 615705f..4e93f94 100644 --- a/charts/databend-query/templates/service.yaml +++ b/charts/databend-query/templates/service.yaml @@ -19,4 +19,6 @@ spec: {{- end }} selector: {{- include "databend-query.selectorLabels" . | nindent 4 }} + {{- if eq (lower .Values.workload) "statefulset" }} statefulset.kubernetes.io/pod-name: {{ include "databend-query.fullname" . }}-0 + {{- end }} diff --git a/charts/databend-query/templates/statefulset.yaml b/charts/databend-query/templates/statefulset.yaml index b029145..9bfbb68 100644 --- a/charts/databend-query/templates/statefulset.yaml +++ b/charts/databend-query/templates/statefulset.yaml @@ -1,3 +1,5 @@ +{{- if eq (lower .Values.workload) "statefulset" }} +--- apiVersion: apps/v1 kind: StatefulSet metadata: @@ -136,3 +138,4 @@ spec: requests: storage: {{ .Values.cache.maxBytes | quote }} {{- end }} +{{- end }} diff --git a/charts/databend-query/values.yaml b/charts/databend-query/values.yaml index 6721c33..5bd6fe8 100644 --- a/charts/databend-query/values.yaml +++ b/charts/databend-query/values.yaml @@ -4,6 +4,9 @@ replicaCount: 1 +# could be StatefulSet or Deployment +workload: StatefulSet + image: repository: datafuselabs/databend-query pullPolicy: IfNotPresent @@ -50,15 +53,15 @@ serviceMonitor: config: # [query] query: - maxActiveSessions: 256 - waitTimeoutMills: 5000 - tenantId: "" clusterId: default managementMode: false jwtKeyFile: "" + extra: + max_active_sessions: 256 + # NOTE: user `root` is already built-in, will be ignored if defined here users: [] # - name: databend @@ -67,8 +70,6 @@ config: # authType: double_sha1_password # authString: 3081f32caef285c232d066033c89a78d88a6d8a5 # databend - extra: {} - # [log] log: file: @@ -115,6 +116,7 @@ config: access_key_id: "" access_key_secret: "" +# NOTE: only for StatefulSet cache: enabled: false path: "/var/lib/databend/cache" diff --git a/examples/query-cluster-as-deployment.yaml b/examples/query-cluster-as-deployment.yaml new file mode 100644 index 0000000..aa7b926 --- /dev/null +++ b/examples/query-cluster-as-deployment.yaml @@ -0,0 +1,2 @@ +replicaCount: 3 +workload: Deployment