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

Add helm chart for 3 components #458

Merged
merged 2 commits into from
Oct 9, 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
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
54 changes: 54 additions & 0 deletions helm-charts/common/chathistory-usvc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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 mongodb chart, please refer to the [mongodb](../mongodb) for more information.

After you've deployted the mongodb chart successfully, run `kubectl get svc` to get the service endpoint and URL respectively, i.e. `mongodb:27017`.

To install chathistory-usvc chart, run the following:

```console
cd GenAIInfra/helm-charts/common/chathistory-usvc
export MONGO_HOST="mongodb"
export MONGO_PORT="27017"
helm dependency update
helm install chathistory-usvc . --set MONGO_HOST=${MONGO_HOST} --set MONGO_PORT=${MONGO_PORT}
```

## (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 6012:6012` to expose the chathistory-usvc service for access.

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

```console
curl -X 'POST' \
http://localhost:6012/v1/chathistory/create \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"data": {"messages": "test Messages", "user": "test"}}'
```

## Values

| Key | Type | Default | Description |
| ---------------- | ------ | --------------------------------- | ----------- |
| image.repository | string | `"opea/chathistory-mongo-server"` | |
| service.port | string | `"6012"` | |
| MONGO_HOST | string | `""` | |
| MONGO_PORT | 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 }}
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 -sS --fail-with-body \
-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