Skip to content

Commit 7073acf

Browse files
authored
GMC: make "namespace" field of each resource in the CR optional (#70)
* make namespace optional under each resource, if it's not defined, get the namespace in the context Signed-off-by: KfreeZ <kefei.zhang@intel.com> * makes go-lint happy Signed-off-by: KfreeZ <kefei.zhang@intel.com> * 1. correct an error of setting wrong optional fiels; 2. increase UT coverage Signed-off-by: KfreeZ <kefei.zhang@intel.com> --------- Signed-off-by: KfreeZ <kefei.zhang@intel.com>
1 parent cff4ab2 commit 7073acf

File tree

7 files changed

+347
-159
lines changed

7 files changed

+347
-159
lines changed

microservices-connector/api/v1alpha3/gmconnector_types.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313

1414
// GMCTarget represents the structure to hold either a PredefinedType or a ServiceReference.
1515
type GMCTarget struct {
16-
NameSpace string `json:"nameSpace,omitempty"`
17-
1816
ServiceName string `json:"serviceName,omitempty"`
1917

18+
// +optional
19+
NameSpace string `json:"nameSpace,omitempty"`
20+
2021
// +optional
2122
Config map[string]string `json:"config,omitempty"`
2223

@@ -141,9 +142,10 @@ type Router struct {
141142

142143
type RouterConfig struct {
143144
Name string `json:"name"`
144-
NameSpace string `json:"nameSpace"`
145145
ServiceName string `json:"serviceName"`
146146
// +optional
147+
NameSpace string `json:"nameSpace"`
148+
// +optional
147149
Config map[string]string `json:"config"`
148150
}
149151

microservices-connector/config/crd/bases/gmc.opea.io_gmconnectors.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ spec:
150150
type: string
151151
required:
152152
- name
153-
- nameSpace
154153
- serviceName
155154
type: object
156155
required:

microservices-connector/config/samples/chatQnA.yaml

+90-23
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,100 @@ metadata:
77
labels:
88
app.kubernetes.io/name: gmconnector
99
app.kubernetes.io/managed-by: kustomize
10-
name: gmconnector-sample
11-
namespace: gmcsample
10+
name: chatqa
11+
namespace: chatqa
1212
spec:
13+
routerConfig:
14+
name: router
15+
serviceName: router-service
16+
config:
17+
no_proxy: ".chatqa.svc.cluster.local"
18+
http_proxy: "insert-your-http-proxy-here"
19+
https_proxy: "insert-your-https-proxy-here"
1320
nodes:
1421
root:
1522
routerType: Sequence
1623
steps:
17-
- name: embedding
18-
target:
19-
embedding:
20-
embedderService:
21-
modelId: BAAI/bge-base-en-v1.5
22-
name: someEmbedder
23-
- name: retrieving
24-
target:
25-
retrieving:
26-
vectorDbService:
27-
type: REDIS
24+
- name: Embedding
25+
internalService:
26+
serviceName: embedding-service
27+
config:
28+
no_proxy: ".chatqa.svc.cluster.local"
29+
http_proxy: "insert-your-http-proxy-here"
30+
https_proxy: "insert-your-https-proxy-here"
31+
tei_endpoint: "http://tei-embedding-service.chatqa.svc.cluster.local:6006"
32+
endpoint: /v1/embeddings
33+
- name: TeiEmbedding
34+
internalService:
35+
serviceName: tei-embedding-service
36+
config:
37+
no_proxy: ".chatqa.svc.cluster.local"
38+
http_proxy: "insert-your-http-proxy-here"
39+
https_proxy: "insert-your-https-proxy-here"
40+
gmcTokenSecret: gmc-tokens
41+
hostPath: /root/GMC/data/tei
42+
modelId: BAAI/bge-base-en-v1.5
43+
endpoint: /embed
44+
isDownstreamService: true
45+
- name: Retriever
2846
data: $response
29-
- name: reranking
30-
target:
31-
reranking:
32-
rerankerService:
33-
name: someReranker
34-
modelId: BAAI/bge-reranker-large
47+
internalService:
48+
serviceName: retriever-redis-server
49+
config:
50+
no_proxy: ".chatqa.svc.cluster.local"
51+
http_proxy: "insert-your-http-proxy-here"
52+
https_proxy: "insert-your-https-proxy-here"
53+
RedisUrl: redis://redis-vector-db.chatqa.svc.cluster.local:6379
54+
IndexName: rag-redis
55+
tei_endpoint: "http://tei-embedding-service.chatqa.svc.cluster.local:6006"
56+
endpoint: /v1/retrieval
57+
- name: VectorDB
58+
internalService:
59+
serviceName: redis-vector-db
60+
isDownstreamService: true
61+
- name: Reranking
3562
data: $response
36-
- name: llm
37-
target:
38-
lLM:
39-
runtimeService: tgiGaudi
63+
internalService:
64+
serviceName: reranking-service
65+
config:
66+
no_proxy: ".chatqa.svc.cluster.local"
67+
http_proxy: "insert-your-http-proxy-here"
68+
https_proxy: "insert-your-https-proxy-here"
69+
tei_reranking_endpoint: http://tei-reranking-service.chatqa.svc.cluster.local:8808
70+
gmcTokenSecret: gmc-tokens
71+
endpoint: /v1/reranking
72+
- name: TeiReranking
73+
internalService:
74+
serviceName: tei-reranking-service
75+
config:
76+
no_proxy: ".chatqa.svc.cluster.local"
77+
http_proxy: "insert-your-http-proxy-here"
78+
https_proxy: "insert-your-https-proxy-here"
79+
gmcTokenSecret: gmc-tokens
80+
hostPath: /root/GMC/data/rerank
81+
modelId: BAAI/bge-reranker-large
82+
endpoint: /rerank
83+
isDownstreamService: true
84+
- name: Llm
85+
data: $response
86+
internalService:
87+
serviceName: llm-service
88+
config:
89+
no_proxy: ".chatqa.svc.cluster.local"
90+
http_proxy: "insert-your-http-proxy-here"
91+
https_proxy: "insert-your-https-proxy-here"
92+
tgi_endpoint: http://tgi-service.chatqa.svc.cluster.local:9009
93+
gmcTokenSecret: gmc-tokens
94+
endpoint: /v1/chat/completions
95+
- name: Tgi
96+
internalService:
97+
serviceName: tgi-service
98+
config:
99+
no_proxy: ".chatqa.svc.cluster.local"
100+
http_proxy: "insert-your-http-proxy-here"
101+
https_proxy: "insert-your-https-proxy-here"
102+
gmcTokenSecret: gmc-tokens
103+
hostPath: /root/GMC/data/tgi
104+
modelId: Intel/neural-chat-7b-v3-3
105+
endpoint: /generate
106+
isDownstreamService: true

microservices-connector/config/samples/chatQnA_v2.yaml

-115
This file was deleted.

microservices-connector/config/samples/codegen.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ metadata:
1212
spec:
1313
routerConfig:
1414
name: router
15-
nameSpace: codegen
1615
serviceName: router-service
1716
config:
1817
no_proxy: ".codegen.svc.cluster.local"
@@ -25,7 +24,6 @@ spec:
2524
- name: Llm
2625
data: $response
2726
internalService:
28-
nameSpace: codegen
2927
serviceName: llm-service
3028
config:
3129
no_proxy: ".codegen.svc.cluster.local"
@@ -36,7 +34,6 @@ spec:
3634
endpoint: /v1/chat/completions
3735
- name: Tgi
3836
internalService:
39-
nameSpace: codegen
4037
serviceName: tgi-service
4138
config:
4239
no_proxy: ".codegen.svc.cluster.local"

microservices-connector/internal/controller/gmconnector_controller.go

+36-12
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,43 @@ func getKubeConfig() (*rest.Config, error) {
6464
return config, nil
6565
}
6666

67+
// This is for linting purpose, they are supposed to be removed after reading manifests from oneclick
68+
const (
69+
Embedding = "Embedding"
70+
TeiEmbedding = "TeiEmbedding"
71+
VectorDB = "VectorDB"
72+
Retriever = "Retriever"
73+
Reranking = "Reranking"
74+
TeiReranking = "TeiReranking"
75+
Tgi = "Tgi"
76+
Llm = "Llm"
77+
Router = "router"
78+
)
79+
6780
func reconcileResource(step string, ns string, svc string, svcCfg *map[string]string, retSvc *corev1.Service) error {
6881

6982
var tmpltFile string
7083

7184
fmt.Printf("get step %s config for %s@%s: %v\n", step, svc, ns, svcCfg)
7285

7386
//TODO add validation to rule out unexpected case like both embedding and retrieving
74-
if step == "Embedding" {
87+
if step == Embedding {
7588
tmpltFile = yaml_dir + "/Embedding.yaml"
76-
} else if step == "TeiEmbedding" {
89+
} else if step == TeiEmbedding {
7790
tmpltFile = yaml_dir + "/TeiEmbedding.yaml"
78-
} else if step == "VectorDB" {
91+
} else if step == VectorDB {
7992
tmpltFile = yaml_dir + "/VectorDB.yaml"
80-
} else if step == "Retriever" {
93+
} else if step == Retriever {
8194
tmpltFile = yaml_dir + "/Retriever.yaml"
82-
} else if step == "Reranking" {
95+
} else if step == Reranking {
8396
tmpltFile = yaml_dir + "/Reranking.yaml"
84-
} else if step == "TeiReranking" {
97+
} else if step == TeiReranking {
8598
tmpltFile = yaml_dir + "/TeiReranking.yaml"
86-
} else if step == "Tgi" {
99+
} else if step == Tgi {
87100
tmpltFile = yaml_dir + "/Tgi.yaml"
88-
} else if step == "Llm" {
101+
} else if step == Llm {
89102
tmpltFile = yaml_dir + "/Llm.yaml"
90-
} else if step == "router" {
103+
} else if step == Router {
91104
tmpltFile = yaml_dir + "/gmc-router.yaml"
92105
} else {
93106
return errors.New("unexpected target")
@@ -372,7 +385,12 @@ func (r *GMConnectorReconciler) Reconcile(ctx context.Context, req ctrl.Request)
372385
fmt.Println("reconcile resource for node:", step.StepName)
373386

374387
if step.Executor.ExternalService == "" {
375-
ns := step.Executor.InternalService.NameSpace
388+
var ns string
389+
if step.Executor.InternalService.NameSpace == "" {
390+
ns = req.Namespace
391+
} else {
392+
ns = step.Executor.InternalService.NameSpace
393+
}
376394
svcName := step.Executor.InternalService.ServiceName
377395
fmt.Println("trying to reconcile internal service [", svcName, "] in namespace ", ns)
378396

@@ -394,7 +412,13 @@ func (r *GMConnectorReconciler) Reconcile(ctx context.Context, req ctrl.Request)
394412

395413
//to start a router controller
396414
routerService := &corev1.Service{}
397-
err := r.Client.Get(ctx, types.NamespacedName{Namespace: graph.Spec.RouterConfig.NameSpace, Name: graph.Spec.RouterConfig.ServiceName}, routerService)
415+
var router_ns string
416+
if graph.Spec.RouterConfig.NameSpace == "" {
417+
router_ns = req.Namespace
418+
} else {
419+
router_ns = graph.Spec.RouterConfig.NameSpace
420+
}
421+
err := r.Client.Get(ctx, types.NamespacedName{Namespace: router_ns, Name: graph.Spec.RouterConfig.ServiceName}, routerService)
398422
if err == nil {
399423
fmt.Println("success to get router service ", graph.Spec.RouterConfig.ServiceName)
400424
} else {
@@ -408,7 +432,7 @@ func (r *GMConnectorReconciler) Reconcile(ctx context.Context, req ctrl.Request)
408432
graph.Spec.RouterConfig.Config = make(map[string]string)
409433
}
410434
graph.Spec.RouterConfig.Config["nodes"] = "'" + jsonString + "'"
411-
err = reconcileResource(graph.Spec.RouterConfig.Name, graph.Spec.RouterConfig.NameSpace, graph.Spec.RouterConfig.ServiceName, &graph.Spec.RouterConfig.Config, nil)
435+
err = reconcileResource(graph.Spec.RouterConfig.Name, router_ns, graph.Spec.RouterConfig.ServiceName, &graph.Spec.RouterConfig.Config, nil)
412436
if err != nil {
413437
return reconcile.Result{Requeue: true}, errors.Wrapf(err, "Failed to reconcile router service")
414438
}

0 commit comments

Comments
 (0)