Skip to content

Commit

Permalink
Add helm chart for 3 components
Browse files Browse the repository at this point in the history
ChatHistory/PromptRegistry and mongodb.

Co-authored-by: Shaohe Feng <shaohe.feng@intel.com>
Signed-off-by: Dolpher Du <dolpher.du@intel.com>
  • Loading branch information
yongfengdu and shaohef committed Sep 26, 2024
1 parent 325126e commit 62badf2
Show file tree
Hide file tree
Showing 26 changed files with 1,128 additions and 0 deletions.
23 changes: 23 additions & 0 deletions helm-charts/common/chathistory-usvc/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
15 changes: 15 additions & 0 deletions helm-charts/common/chathistory-usvc/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

apiVersion: v2
name: chathistory-usvc
description: The Helm chart for deploying chat history as microservice
type: application
version: 1.0.0
# The chat history microservice server version
appVersion: "v1.0"
dependencies:
- name: mongodb
version: 1.0.0
repository: file://../mongodb
condition: autodependency.enabled
53 changes: 53 additions & 0 deletions helm-charts/common/chathistory-usvc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# chathistory-usvc

Helm chart for deploying chathistory-usvc microservice.

chathistory-usvc will use redis and tei service, please specify the endpoints.

## (Option1): Installing the chart separately

First, you need to install the tei and redis-vector-db chart, please refer to the [tei](../tei) and [redis-vector-db](../redis-vector-db) for more information.

After you've deployted the tei and redis-vector-db chart successfully, please run `kubectl get svc` to get the service endpoint and URL respectively, i.e. `http://tei`, `redis://redis-vector-db:6379`.

To install chathistory-usvc chart, run the following:

```console
cd GenAIInfra/helm-charts/common/chathistory-usvc
export REDIS_URL="redis://redis-vector-db:6379"
export TEI_EMBEDDING_ENDPOINT="http://tei"
helm dependency update
helm install chathistory-usvc . --set REDIS_URL=${REDIS_URL} --set TEI_EMBEDDING_ENDPOINT=${TEI_EMBEDDING_ENDPOINT}
```

## (Option2): Installing the chart with dependencies automatically

```console
cd GenAIInfra/helm-charts/common/chathistory-usvc
helm dependency update
helm install chathistory-usvc . --set autodependency.enabled=true
```

## Verify

To verify the installation, run the command `kubectl get pod` to make sure all pods are running.

Then run the command `kubectl port-forward svc/chathistory-usvc 6007:6007` to expose the chathistory-usvc service for access.

Open another terminal and run the following command to verify the service if working:

```console
curl http://localhost:6007/v1/dataprep \
-X POST \
-H "Content-Type: multipart/form-data" \
-F "files=@./README.md"
```

## Values

| Key | Type | Default | Description |
| ---------------------- | ------ | ----------------------- | ----------- |
| image.repository | string | `"opea/dataprep-redis"` | |
| service.port | string | `"6007"` | |
| REDIS_URL | string | `""` | |
| TEI_EMBEDDING_ENDPOINT | string | `""` | |
62 changes: 62 additions & 0 deletions helm-charts/common/chathistory-usvc/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "chathistory-usvc.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "chathistory-usvc.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "chathistory-usvc.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "chathistory-usvc.labels" -}}
helm.sh/chart: {{ include "chathistory-usvc.chart" . }}
{{ include "chathistory-usvc.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "chathistory-usvc.selectorLabels" -}}
app.kubernetes.io/name: {{ include "chathistory-usvc.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "chathistory-usvc.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "chathistory-usvc.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
30 changes: 30 additions & 0 deletions helm-charts/common/chathistory-usvc/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "chathistory-usvc.fullname" . }}-config
labels:
{{- include "chathistory-usvc.labels" . | nindent 4 }}
data:
{{- if .Values.MONGO_HOST }}
MONGO_HOST: {{ .Values.MONGO_HOST | quote}}
{{- else }}
MONGO_HOST: "{{ .Release.Name }}-mongodb"
{{- end }}
{{- if .Values.MONGO_PORT }}
MONGO_PORT: {{ .Values.MONGO_PORT | quote }}
{{- else }}
MONGO_PORT: "27017"
{{- end }}
DB_NAME: {{ .Values.DB_NAME | quote }}
COLLECTION_NAME: {{ .Values.COLLECTION_NAME | quote }}
http_proxy: {{ .Values.global.http_proxy | quote }}
https_proxy: {{ .Values.global.https_proxy | quote }}
{{- if and (not .Values.MONGO_HOST) (or .Values.global.http_proxy .Values.global.https_proxy) }}
no_proxy: "{{ .Release.Name }}-mongodb,{{ .Values.global.no_proxy }}"
{{- else }}
no_proxy: {{ .Values.global.no_proxy | quote }}
{{- end }}
LOGFLAG: {{ .Values.LOGFLAG | quote }}
88 changes: 88 additions & 0 deletions helm-charts/common/chathistory-usvc/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "chathistory-usvc.fullname" . }}
labels:
{{- include "chathistory-usvc.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "chathistory-usvc.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "chathistory-usvc.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Release.Name }}
envFrom:
- configMapRef:
name: {{ include "chathistory-usvc.fullname" . }}-config
{{- if .Values.global.extraEnvConfig }}
- configMapRef:
name: {{ .Values.global.extraEnvConfig }}
optional: true
{{- end }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: port
containerPort: 6012
protocol: TCP
volumeMounts:
- mountPath: /tmp
name: tmp
{{- if .Values.livenessProbe }}
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
{{- end }}
{{- if .Values.readinessProbe }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
{{- end }}
{{- if .Values.startupProbe }}
startupProbe:
{{- toYaml .Values.startupProbe | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: tmp
emptyDir: {}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.evenly_distributed }}
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
{{- include "chathistory-usvc.selectorLabels" . | nindent 14 }}
{{- end }}
18 changes: 18 additions & 0 deletions helm-charts/common/chathistory-usvc/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

apiVersion: v1
kind: Service
metadata:
name: {{ include "chathistory-usvc.fullname" . }}
labels:
{{- include "chathistory-usvc.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: 6012
protocol: TCP
name: port
selector:
{{- include "chathistory-usvc.selectorLabels" . | nindent 4 }}
32 changes: 32 additions & 0 deletions helm-charts/common/chathistory-usvc/templates/tests/test-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

apiVersion: v1
kind: Pod
metadata:
name: {{ include "chathistory-usvc.fullname" . }}-testpod
labels:
{{- include "chathistory-usvc.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
#"helm.sh/hook-delete-policy": "hook-succeeded, hook-failure"
spec:
containers:
- name: curl
image: python:3.10.14
command: ['bash', '-c']
args:
- |
set -x
max_retry=20;
for ((i=1; i<=max_retry; i++)); do
curl -X 'POST' \
http://{{ include "chathistory-usvc.fullname" . }}:{{ .Values.service.port }}/v1/chathistory/create \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"data": {"messages": "test Messages", "user": "test"}}' && break;
curlcode=$?
if [[ $curlcode -eq 7 ]]; then sleep 10; else echo "curl failed with code $curlcode"; exit 1; fi;
done;
if [ $i -gt $max_retry ]; then echo "test failed with maximum retry"; exit 1; fi
restartPolicy: Never
Loading

0 comments on commit 62badf2

Please sign in to comment.