@@ -12,30 +12,172 @@ function install_gmc() {
12
12
# Make sure you have to use image tag $VERSION for microservice-connector installation
13
13
echo " install microservice-connector, using repo $DOCKER_REGISTRY and tag $VERSION "
14
14
echo " using namespace $SYSTEM_NAMESPACE and $APP_NAMESPACE "
15
+
16
+ init_gmc
17
+
18
+ kubectl apply -f $( pwd) /config/crd/bases/gmc.opea.io_gmconnectors.yaml
19
+ kubectl apply -f $( pwd) /config/rbac/gmc-manager-rbac.yaml
20
+ kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $( pwd) /config/manifests
21
+ kubectl apply -f $( pwd) /config/manager/gmc-manager.yaml
22
+
23
+ # Wait until the gmc controller pod is ready
24
+ wait_until_pod_ready " gmc-controller" $SYSTEM_NAMESPACE " gmc-controller"
15
25
}
16
26
17
27
function validate_gmc() {
18
- echo " validate microservice-connector"
28
+ echo " validate chat-qna"
29
+ validate_chatqna
30
+
19
31
}
20
32
21
33
function cleanup_gmc() {
22
34
echo " clean up microservice-connector"
35
+ kubectl delete ns $APP_NAMESPACE
36
+ kubectl delete ns $SYSTEM_NAMESPACE
37
+ kubectl delete crd gmconnectors.gmc.opea.io
23
38
# clean up the images
24
39
docker rmi $DOCKER_REGISTRY /gmcrouter:$VERSION
25
40
docker rmi $DOCKER_REGISTRY /gmcmanager:$VERSION
26
41
}
27
42
43
+ function validate_chatqna() {
44
+
45
+ kubectl get pods -n $SYSTEM_NAMESPACE
46
+ # todo select gaudi or xeon
47
+ kubectl create ns $APP_NAMESPACE
48
+ sed -i " s|namespace: chatqa|namespace: $APP_NAMESPACE |g" $( pwd) /config/samples/chatQnA_xeon.yaml
49
+ kubectl apply -f $( pwd) /config/samples/chatQnA_xeon.yaml
50
+
51
+
52
+
53
+ output=$( kubectl get pods)
54
+ echo $output
55
+
56
+ # Wait until the router service is ready
57
+ echo " Waiting for the chatqa router service to be ready..."
58
+ wait_until_pod_ready " chatqna router" $APP_NAMESPACE " router-service"
59
+
60
+ # Wait until the tgi pod is ready
61
+ TGI_POD_NAME=$( kubectl get pods --namespace=$APP_NAMESPACE | grep ^tgi-service | awk ' {print $1}' )
62
+ kubectl describe pod $TGI_POD_NAME -n $APP_NAMESPACE
63
+ kubectl wait --for=condition=ready pod/$TGI_POD_NAME --namespace=$APP_NAMESPACE --timeout=300s
64
+
65
+
66
+ # deploy client pod for testing
67
+ kubectl create deployment client-test -n $APP_NAMESPACE --image=python:3.8.13 -- sleep infinity
68
+
69
+ # wait for client pod ready
70
+ wait_until_pod_ready " client-test" $APP_NAMESPACE " client-test"
71
+ # giving time to populating data
72
+ sleep 120
73
+ kubectl get pods -n $APP_NAMESPACE
74
+ # send request to chatqnA
75
+ export CLIENT_POD=$( kubectl get pod -n $APP_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name})
76
+ echo " $CLIENT_POD "
77
+ accessUrl=$( kubectl get gmc -n $APP_NAMESPACE -o jsonpath=" {.items[?(@.metadata.name=='chatqa')].status.accessUrl}" )
78
+ kubectl exec " $CLIENT_POD " -n $APP_NAMESPACE -- curl $accessUrl -X POST -d ' {"text":"What is the revenue of Nike in 2023?","parameters":{"max_new_tokens":17, "do_sample": true}}' -H ' Content-Type: application/json' > $LOG_PATH /curl_chatqna.log
79
+ exit_code=$?
80
+ if [ $exit_code -ne 0 ]; then
81
+ echo " chatqna failed, please check the logs in ${LOG_PATH} !"
82
+ exit 1
83
+ fi
84
+
85
+ echo " Checking response results, make sure the output is reasonable. "
86
+ local status=false
87
+ if [[ -f $LOG_PATH /curl_chatqna.log ]] && \
88
+ [[ $( grep -c " billion" $LOG_PATH /curl_chatqna.log) != 0 ]]; then
89
+ status=true
90
+ fi
91
+ if [ $status == false ]; then
92
+ echo " Response check failed, please check the logs in artifacts!"
93
+ exit 1
94
+ else
95
+ echo " Response check succeed!"
96
+ fi
97
+ }
98
+
99
+ function init_gmc() {
100
+ # Copy manifest into gmc
101
+ mkdir -p $( pwd) /config/manifests
102
+ cp $( dirname $( pwd) ) /manifests/ChatQnA/* .yaml -p $( pwd) /config/manifests/
103
+
104
+ # replace tag with for the gmc-router and gmc-manager image
105
+ sed -i " s|opea/\(.*\):latest|opea/\1:$VERSION |g" $( pwd) /config/gmcrouter/gmc-router.yaml
106
+ sed -i " s|opea/\(.*\):latest|opea/\1:$VERSION |g" $( pwd) /config/manager/gmc-manager.yaml
107
+ cp $( pwd) /config/gmcrouter/gmc-router.yaml -p $( pwd) /config/manifests/
108
+
109
+
110
+
111
+ # replace namespace for gmc-router and gmc-manager
112
+ sed -i " s|namespace: system|namespace: $SYSTEM_NAMESPACE |g" $( pwd) /config/manager/gmc-manager.yaml
113
+ sed -i " s|namespace: system|namespace: $SYSTEM_NAMESPACE |g" $( pwd) /config/rbac/gmc-manager-rbac.yaml
114
+ sed -i " s|name: system|name: $SYSTEM_NAMESPACE |g" $( pwd) /config/rbac/gmc-manager-rbac.yaml
115
+ # replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
116
+ find . -name ' *.yaml' -type f -exec sed -i " s#path: /mnt/models#path: $MOUNT_DIR #g" {} \;
117
+ # replace the repository "image: opea/*" with "image: $IMAGE_REPO/opea/"
118
+ find . -name ' *.yaml' -type f -exec sed -i " s#image: opea/*#image: $IMAGE_REPO /opea/#g" {} \;
119
+ # set huggingface token
120
+ # find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
121
+ find . -name ' *.yaml' -type f -exec sed -i " s#insert-your-huggingface-token-here#$( cat /home/$USER_ID /.cache/huggingface/token) #g" {} \;
122
+ # replace namespace "default" with real namespace
123
+ find . -name ' *.yaml' -type f -exec sed -i " s#default.svc#$APP_NAMESPACE .svc#g" {} \;
124
+ }
125
+
126
+
127
+ function wait_until_pod_ready() {
128
+ echo " Waiting for the $1 to be ready..."
129
+ max_retries=3000
130
+ retry_count=0
131
+ while ! is_pod_ready $2 $3 ; do
132
+ if [ $retry_count -ge $max_retries ]; then
133
+ echo " $1 is not ready after waiting for a significant amount of time"
134
+ exit 1
135
+ fi
136
+ echo " $1 is not ready yet. Retrying in 10 seconds..."
137
+ sleep 10
138
+ output=$( kubectl get pods -n $2 )
139
+ # Check if the command was successful
140
+ if [ $? -eq 0 ]; then
141
+ echo " Successfully retrieved $1 information:"
142
+ echo " $output "
143
+ else
144
+ echo " Failed to retrieve $1 information"
145
+ exit 1
146
+ fi
147
+ retry_count=$(( retry_count + 1 ))
148
+ done
149
+ }
150
+
151
+ function is_pod_ready() {
152
+ if [ " $2 " == " gmc-controller" ]; then
153
+ pod_status=$( kubectl get pods -n $1 -o jsonpath=' {.items[].status.conditions[?(@.type=="Ready")].status}' )
154
+ else
155
+ pod_status=$( kubectl get pods -n $1 -l app=$2 -o jsonpath=' {.items[].status.conditions[?(@.type=="Ready")].status}' )
156
+ fi
157
+ if [ " $pod_status " == " True" ]; then
158
+ return 0
159
+ else
160
+ return 1
161
+ fi
162
+ }
163
+
164
+
165
+
28
166
if [ $# -eq 0 ]; then
29
167
echo " Usage: $0 <function_name>"
30
168
exit 1
31
169
fi
32
170
33
171
case " $1 " in
34
172
install_gmc)
173
+ pushd microservices-connector
35
174
install_gmc
175
+ popd
36
176
;;
37
177
validate_gmc)
178
+ pushd microservices-connector
38
179
validate_gmc
180
+ popd
39
181
;;
40
182
cleanup_gmc)
41
183
cleanup_gmc
0 commit comments