From 73b5b6566bfbe0b6b395f2c75d4ac1421f57b30c Mon Sep 17 00:00:00 2001 From: Lianhao Lu Date: Mon, 5 Aug 2024 04:56:23 +0000 Subject: [PATCH] helm: Enhance dataprep to support local embedding and getfile - By setting TEI_EMBEDDING_ENDPOINT to empty and EMBED_MODEL to non-empty, data-prep can support local embedding. - Support getfile and delete URL Signed-off-by: Lianhao Lu --- helm-charts/common/data-prep/README.md | 35 +++++++++++++++++-- .../common/data-prep/templates/NOTES.txt | 16 --------- .../common/data-prep/templates/configmap.yaml | 5 +-- .../data-prep/templates/deployment.yaml | 6 ++++ .../common/data-prep/templates/service.yaml | 8 +++-- .../data-prep/templates/tests/test-pod.yaml | 34 ++++++++++++++++++ helm-charts/common/data-prep/values.yaml | 17 ++++++++- manifests/common/data-prep.yaml | 15 ++++++++ 8 files changed, 111 insertions(+), 25 deletions(-) delete mode 100644 helm-charts/common/data-prep/templates/NOTES.txt create mode 100644 helm-charts/common/data-prep/templates/tests/test-pod.yaml diff --git a/helm-charts/common/data-prep/README.md b/helm-charts/common/data-prep/README.md index e333320d2..c9162554c 100644 --- a/helm-charts/common/data-prep/README.md +++ b/helm-charts/common/data-prep/README.md @@ -4,14 +4,43 @@ Helm chart for deploying data-prep microservice. data-prep will use redis and tei service, please specify the endpoints. -## Installing the Chart +## (Option1): Installing the chart separately: -To install the chart, run the following: +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 data-prep chart, run the following: ```console +cd GenAIInfra/helm-charts/common/data-prep export REDIS_URL="redis://redis-vector-db:6379" export TEI_EMBEDDING_ENDPOINT="http://tei" -helm install dataprep data-prep --set REDIS_URL=${REDIS_URL} --set TEI_EMBEDDING_ENDPOINT=${TEI_EMBEDDING_ENDPOINT} +helm dependency update +helm install data-prep . --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/data-prep +helm dependency update +helm install data-prep . --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/data-prep 6007:6007` to expose the data-prep 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 diff --git a/helm-charts/common/data-prep/templates/NOTES.txt b/helm-charts/common/data-prep/templates/NOTES.txt deleted file mode 100644 index cd551e381..000000000 --- a/helm-charts/common/data-prep/templates/NOTES.txt +++ /dev/null @@ -1,16 +0,0 @@ -1. Get the application URL by running these commands: -{{- if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "data-prep.fullname" . }}) - export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") - echo http://$NODE_IP:$NODE_PORT -{{- else if contains "LoadBalancer" .Values.service.type }} - NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "data-prep.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "data-prep.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo http://$SERVICE_IP:{{ .Values.service.port }} -{{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "data-prep.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") - export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") - echo "Visit http://127.0.0.1:8080 to use your application" - kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT -{{- end }} diff --git a/helm-charts/common/data-prep/templates/configmap.yaml b/helm-charts/common/data-prep/templates/configmap.yaml index 9ec3e76ab..aee2aa6d8 100644 --- a/helm-charts/common/data-prep/templates/configmap.yaml +++ b/helm-charts/common/data-prep/templates/configmap.yaml @@ -10,15 +10,16 @@ metadata: data: {{- if .Values.TEI_EMBEDDING_ENDPOINT }} TEI_ENDPOINT: {{ .Values.TEI_EMBEDDING_ENDPOINT | quote}} - {{- else }} + {{- else if not .Values.EMBED_MODEL }} TEI_ENDPOINT: "http://{{ .Release.Name }}-tei" {{- end }} + EMBED_MODEL: {{ .Values.EMBED_MODEL | quote }} {{- if .Values.REDIS_URL }} REDIS_URL: {{ .Values.REDIS_URL | quote}} {{- else }} REDIS_URL: "redis://{{ .Release.Name }}-redis-vector-db:6379" {{- end }} - INDEX_NAME: "rag-redis" + INDEX_NAME: {{ .Values.INDEX_NAME | quote }} HUGGINGFACEHUB_API_TOKEN: {{ .Values.global.HUGGINGFACEHUB_API_TOKEN | quote}} HF_HOME: "/tmp/.cache/huggingface" http_proxy: {{ .Values.global.http_proxy | quote }} diff --git a/helm-charts/common/data-prep/templates/deployment.yaml b/helm-charts/common/data-prep/templates/deployment.yaml index b7305ee2e..68603577a 100644 --- a/helm-charts/common/data-prep/templates/deployment.yaml +++ b/helm-charts/common/data-prep/templates/deployment.yaml @@ -45,6 +45,12 @@ spec: - name: data-prep containerPort: 6007 protocol: TCP + # The following need to be modified after GenAIComps bug #282 is resolved. + # https://github.com/opea-project/GenAIComps/issues/282 + - containerPort: 6008 + protocol: TCP + - containerPort: 6009 + protocol: TCP volumeMounts: - mountPath: /tmp name: tmp diff --git a/helm-charts/common/data-prep/templates/service.yaml b/helm-charts/common/data-prep/templates/service.yaml index 7b8ab7dfc..072127dfc 100644 --- a/helm-charts/common/data-prep/templates/service.yaml +++ b/helm-charts/common/data-prep/templates/service.yaml @@ -10,9 +10,11 @@ metadata: spec: type: {{ .Values.service.type }} ports: - - port: {{ .Values.service.port }} - targetPort: 6007 + {{- range .Values.service.ports }} + - port: {{ .port }} + targetPort: {{ .targetPort }} protocol: TCP - name: data-prep + name: {{ .name }} + {{- end }} selector: {{- include "data-prep.selectorLabels" . | nindent 4 }} diff --git a/helm-charts/common/data-prep/templates/tests/test-pod.yaml b/helm-charts/common/data-prep/templates/tests/test-pod.yaml new file mode 100644 index 000000000..56233eddd --- /dev/null +++ b/helm-charts/common/data-prep/templates/tests/test-pod.yaml @@ -0,0 +1,34 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v1 +kind: Pod +metadata: + name: {{ include "data-prep.fullname" . }}-testpod + labels: + {{- include "data-prep.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test + #"helm.sh/hook-delete-policy": "hook-succeeded, hook-failure" +spec: + containers: + - name: curl + #image: alpine/curl + image: python:3.10.14 + command: ['bash', '-c'] + args: + - | + echo "test file" > /tmp/file1.txt; + {{- with index .Values.service.ports 0 }} + export port={{.port}}; + {{- end }} + max_retry=20; + for ((i=1; i<=max_retry; i++)); do + curl http://{{ include "data-prep.fullname" . }}:$port/v1/dataprep -sS --fail-with-body \ + -X POST \ + -H "Content-Type: multipart/form-data" \ + -F "files=@/tmp/file1.txt" && break; + sleep 10; + done; + if [ $i -gt $max_retry ]; then echo "dataprep test failed."; exit 1; fi + restartPolicy: Never diff --git a/helm-charts/common/data-prep/values.yaml b/helm-charts/common/data-prep/values.yaml index 21d49365d..af4366563 100644 --- a/helm-charts/common/data-prep/values.yaml +++ b/helm-charts/common/data-prep/values.yaml @@ -38,8 +38,19 @@ securityContext: service: type: ClusterIP + # The following need to be modified after GenAIComps bug #282 is resolved. + # https://github.com/opea-project/GenAIComps/issues/282 + ports: # The default port for data prep service is 6007 - port: 6007 + - port: 6007 + targetPort: 6007 + name: data-prep + - port: 6008 + targetPort: 6008 + name: data-prep-get + - port: 6009 + targetPort: 6009 + name: data-prep-delete resources: {} # We usually recommend not to specify default resources and to leave this as a conscious @@ -83,8 +94,12 @@ affinity: {} # text embedding inference service URL, e.g. http://: TEI_EMBEDDING_ENDPOINT: "" +# local embedder's model +EMBED_MODEL: "" + # redis DB service URL, e.g. redis://: REDIS_URL: "" +INDEX_NAME: "rag-redis" global: http_proxy: "" diff --git a/manifests/common/data-prep.yaml b/manifests/common/data-prep.yaml index 9e1ca6724..bf5a2d395 100644 --- a/manifests/common/data-prep.yaml +++ b/manifests/common/data-prep.yaml @@ -15,6 +15,7 @@ metadata: app.kubernetes.io/managed-by: Helm data: TEI_ENDPOINT: "http://data-prep-tei" + EMBED_MODEL: "" REDIS_URL: "redis://data-prep-redis-vector-db:6379" INDEX_NAME: "rag-redis" HUGGINGFACEHUB_API_TOKEN: "insert-your-huggingface-token-here" @@ -47,6 +48,14 @@ spec: targetPort: 6007 protocol: TCP name: data-prep + - port: 6008 + targetPort: 6008 + protocol: TCP + name: data-prep-get + - port: 6009 + targetPort: 6009 + protocol: TCP + name: data-prep-delete selector: app.kubernetes.io/name: data-prep app.kubernetes.io/instance: data-prep @@ -103,6 +112,12 @@ spec: - name: data-prep containerPort: 6007 protocol: TCP + # The following need to be modified after GenAIComps bug #282 is resolved. + # https://github.com/opea-project/GenAIComps/issues/282 + - containerPort: 6008 + protocol: TCP + - containerPort: 6009 + protocol: TCP volumeMounts: - mountPath: /tmp name: tmp