Skip to content

Commit

Permalink
Add clickhouse deployment and setup clickhouse migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
langchain-infra committed Dec 19, 2023
1 parent c3fe2ca commit 3f14a94
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 11 deletions.
8 changes: 8 additions & 0 deletions charts/langsmith/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ Template containing common environment variables that are used by several servic
{{- end -}}
{{- end -}}

{{- define "clickhouse.serviceAccountName" -}}
{{- if .Values.clickhouse.serviceAccount.create -}}
{{ default (printf "%s-%s" (include "langsmith.fullname" .) .Values.clickhouse.name) .Values.clickhouse.serviceAccount.name | trunc 63 | trimSuffix "-" }}
{{- else -}}
{{ default "default" .Values.clickhouse.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{- define "frontend.serviceAccountName" -}}
{{- if .Values.frontend.serviceAccount.create -}}
{{ default (printf "%s-%s" (include "langsmith.fullname" .) .Values.frontend.name) .Values.frontend.serviceAccount.name | trunc 63 | trimSuffix "-" }}
Expand Down
22 changes: 22 additions & 0 deletions charts/langsmith/templates/backend/run-migrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ spec:
{{- toYaml .Values.backend.migrations.resources | nindent 12 }}
securityContext:
{{- toYaml .Values.backend.migrations.securityContext | nindent 12 }}
- name: {{ .Values.backend.name }}-clickhouse
command:
- migrate
- -source
- file://clickhouse/migrations
- -database
- "clickhouse://{{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}:{{ .Values.clickhouse.containerNativePort }}?username=clickhouse_admin&password=password&database=default&x-multi-statement=true&x-migrations-table-engine=MergeTree"
- up
env:
{{- include "langsmith.commonEnv" . | nindent 12 }}
{{- with .Values.backend.migrations.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ include "langsmith.fullname" . }}-config
image: "{{ .Values.images.backendImage.repository }}:{{ .Values.images.backendImage.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.images.backendImage.pullPolicy }}
resources:
{{- toYaml .Values.backend.migrations.resources | nindent 12 }}
securityContext:
{{- toYaml .Values.backend.migrations.securityContext | nindent 12 }}
{{- with .Values.backend.migrations.sidecars }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
26 changes: 26 additions & 0 deletions charts/langsmith/templates/clickhouse/config-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
labels:
{{- include "langsmith.labels" . | nindent 4 }}
annotations:
{{- include "langsmith.annotations" . | nindent 4 }}
data:
users.xml: |
<clickhouse>
<profiles>
<default>
<readonly>0</readonly>
</default>
</profiles>
<users>
<default>
<password></password>
<access_management>1</access_management>
<named_collection_control>1</named_collection_control>
<show_named_collections>1</show_named_collections>
<show_named_collections_secrets>1</show_named_collections_secrets>
</default>
</users>
</clickhouse>
16 changes: 16 additions & 0 deletions charts/langsmith/templates/clickhouse/service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.clickhouse.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "clickhouse.serviceAccountName" . }}
labels:
{{- include "langsmith.labels" . | nindent 4 }}
{{- with.Values.clickhouse.serviceAccount.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- include "langsmith.annotations" . | nindent 4 }}
{{- with.Values.clickhouse.serviceAccount.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
12 changes: 8 additions & 4 deletions charts/langsmith/templates/clickhouse/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ metadata:
spec:
type: {{ .Values.clickhouse.service.type }}
ports:
- name: clickhouse
port: {{ .Values.clickhouse.service.port }}
targetPort: clickhouse
- name: ch
port: {{ .Values.clickhouse.service.httpPort }}
targetPort: ch
protocol: TCP
- name: ch-native
port: {{ .Values.clickhouse.service.nativePort }}
targetPort: ch-native
protocol: TCP
selector:
{{- include "langsmith.selectorLabels" . | nindent 4 }}
app.kubernetes.io/name: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
app.kubernetes.io/component: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
{{- end }}
29 changes: 22 additions & 7 deletions charts/langsmith/templates/clickhouse/stateful-set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
selector:
matchLabels:
{{- include "langsmith.selectorLabels" . | nindent 6 }}
app.kubernetes.io/name: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
app.kubernetes.io/component: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
template:
metadata:
{{- with .Values.clickhouse.statefulSet.annotations }}
Expand All @@ -31,7 +31,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "langsmith.labels" . | nindent 8 }}
app.kubernetes.io/name: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
app.kubernetes.io/component: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
spec:
{{- with .Values.images.imagePullSecrets }}
imagePullSecrets:
Expand All @@ -43,11 +43,18 @@ spec:
- name: {{ .Values.clickhouse.name }}
image: "{{ .Values.images.clickhouseImage.repository }}:{{ .Values.images.clickhouseImage.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.images.clickhouseImage.pullPolicy }}
env:
- name: CLICKHOUSE_DB
value: default
- name: CLICKHOUSE_USER
value: clickhouse_admin
- name: CLICKHOUSE_PASSWORD
value: password
ports:
- name: clickhouse
- name: ch
containerPort: {{ .Values.clickhouse.containerHttpPort }}
protocol: TCP
- name: clickhouse-native
- name: ch-native
containerPort: {{ .Values.clickhouse.containerNativePort }}
protocol: TCP
startupProbe:
Expand Down Expand Up @@ -78,8 +85,9 @@ spec:
volumeMounts:
- mountPath: /var/lib/clickhouse
name: data
- mountPath: /var/lib/clickhouse
name: config
- mountPath: /etc/clickhouse-server/users.d/users.xml
name: clickhouse-conf
subPath: users.xml
{{- with .Values.clickhouse.statefulSet.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand All @@ -92,14 +100,21 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: clickhouse-conf
configMap:
name: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
items:
- key: users.xml
path: users.xml
volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
labels:
{{- include "langsmith.labels" . | nindent 10 }}
app.kubernetes.io/name: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
app.kubernetes.io/component: {{ include "langsmith.fullname" . }}-{{ .Values.clickhouse.name }}
spec:
accessModes:
- ReadWriteOnce
Expand Down
2 changes: 2 additions & 0 deletions charts/langsmith/templates/frontend/config-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
name: {{ include "langsmith.fullname" . }}-{{ .Values.frontend.name }}
labels:
{{- include "langsmith.labels" . | nindent 4 }}
annotations:
{{- include "langsmith.annotations" . | nindent 4 }}
data:
nginx.conf: |
server {
Expand Down
5 changes: 5 additions & 0 deletions charts/langsmith/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ clickhouse:
nativePort: 9000
labels: {}
annotations: {}
serviceAccount:
create: true
name: ""
labels: { }

Check failure on line 145 in charts/langsmith/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test

145:14 [braces] too many spaces inside empty braces
annotations: { }

Check failure on line 146 in charts/langsmith/values.yaml

View workflow job for this annotation

GitHub Actions / lint-test

146:19 [braces] too many spaces inside empty braces

frontend:
name: "frontend"
Expand Down

0 comments on commit 3f14a94

Please sign in to comment.