Skip to content

Commit caf597e

Browse files
committed
OLS-2106: Operator connects Openshift RAG by default to LSC backend
1 parent 679ff0e commit caf597e

File tree

13 files changed

+208
-113
lines changed

13 files changed

+208
-113
lines changed

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ func main() {
429429
OpenShiftMCPServerImage: imagesMap["openshift-mcp-server-image"],
430430
DataverseExporterImage: imagesMap["dataverse-exporter-image"],
431431
LightspeedCoreImage: imagesMap["lightspeed-core"],
432+
OcpRagImage: imagesMap["ocp-rag-image"],
432433
UseLCore: useLCore,
433434
Namespace: namespace,
434435
PrometheusAvailable: prometheusAvailable,

internal/controller/appserver/deployment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func GenerateOLSDeployment(r reconciler.Reconciler, cr *olsv1alpha1.OLSConfig) (
291291

292292
// RAG volume
293293
if len(cr.Spec.OLSConfig.RAG) > 0 {
294-
ragVolume := generateRAGVolume()
294+
ragVolume := utils.GenerateRAGVolume()
295295
volumes = append(volumes, ragVolume)
296296
}
297297

@@ -308,7 +308,7 @@ func GenerateOLSDeployment(r reconciler.Reconciler, cr *olsv1alpha1.OLSConfig) (
308308
)
309309

310310
if len(cr.Spec.OLSConfig.RAG) > 0 {
311-
ragVolumeMounts := generateRAGVolumeMount()
311+
ragVolumeMounts := utils.GenerateRAGVolumeMount()
312312
volumeMounts = append(volumeMounts, ragVolumeMounts)
313313
}
314314

@@ -343,7 +343,7 @@ func GenerateOLSDeployment(r reconciler.Reconciler, cr *olsv1alpha1.OLSConfig) (
343343

344344
initContainers := []corev1.Container{}
345345
if len(cr.Spec.OLSConfig.RAG) > 0 {
346-
ragInitContainers := GenerateRAGInitContainers(cr)
346+
ragInitContainers := utils.GenerateRAGInitContainers(cr)
347347
initContainers = append(initContainers, ragInitContainers...)
348348
}
349349

internal/controller/appserver/rag.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

internal/controller/lcore/assets_test.go

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ func TestBuildLlamaStackYAML_SupportedProvider(t *testing.T) {
3535
}
3636

3737
// Build the YAML
38-
ctx := context.Background()
39-
yamlOutput, err := buildLlamaStackYAML(nil, ctx, cr)
38+
yamlOutput, err := buildLlamaStackYAML(createTestReconciler(), context.Background(), cr)
4039
if err != nil {
4140
t.Fatalf("buildLlamaStackYAML returned error for supported provider: %v", err)
4241
}
@@ -89,8 +88,7 @@ func TestBuildLlamaStackYAML_UnsupportedProvider(t *testing.T) {
8988
}
9089

9190
// Build the YAML - should return error
92-
ctx := context.Background()
93-
yamlOutput, err := buildLlamaStackYAML(nil, ctx, cr)
91+
yamlOutput, err := buildLlamaStackYAML(createTestReconciler(), context.Background(), cr)
9492

9593
// Verify error is returned
9694
if err == nil {
@@ -104,10 +102,10 @@ func TestBuildLlamaStackYAML_UnsupportedProvider(t *testing.T) {
104102
}
105103
if err.Error() != "" && len(err.Error()) > 0 {
106104
// Check if error message contains expected text
107-
if !contains(err.Error(), expectedErrMsg) {
105+
if !strings.Contains(err.Error(), expectedErrMsg) {
108106
t.Errorf("Error message '%s' doesn't contain expected text '%s'", err.Error(), expectedErrMsg)
109107
}
110-
if !contains(err.Error(), providerType) {
108+
if !strings.Contains(err.Error(), providerType) {
111109
t.Errorf("Error message '%s' doesn't mention provider type '%s'", err.Error(), providerType)
112110
}
113111
}
@@ -142,8 +140,7 @@ func TestBuildLlamaStackYAML_OpenAICompatibleProviders(t *testing.T) {
142140
}
143141

144142
// Build the YAML - should succeed
145-
ctx := context.Background()
146-
yamlOutput, err := buildLlamaStackYAML(nil, ctx, cr)
143+
yamlOutput, err := buildLlamaStackYAML(createTestReconciler(), context.Background(), cr)
147144

148145
// Verify no error is returned
149146
if err != nil {
@@ -262,8 +259,7 @@ func TestBuildLlamaStackYAML_AzureProvider(t *testing.T) {
262259
}
263260

264261
// Build the YAML
265-
ctx := context.Background()
266-
yamlOutput, err := buildLlamaStackYAML(testReconciler, ctx, cr)
262+
yamlOutput, err := buildLlamaStackYAML(testReconciler, context.Background(), cr)
267263
if err != nil {
268264
t.Fatalf("buildLlamaStackYAML returned error for Azure provider: %v", err)
269265
}
@@ -344,24 +340,7 @@ func TestBuildLlamaStackYAML_AzureProvider(t *testing.T) {
344340
t.Logf("Successfully validated Llama Stack YAML with Azure provider (%d bytes)", len(yamlOutput))
345341
}
346342

347-
// Helper function to check if a string contains a substring
348-
func contains(s, substr string) bool {
349-
return len(s) >= len(substr) && (s == substr || len(s) > len(substr) && findSubstring(s, substr))
350-
}
351-
352-
func findSubstring(s, substr string) bool {
353-
for i := 0; i <= len(s)-len(substr); i++ {
354-
if s[i:i+len(substr)] == substr {
355-
return true
356-
}
357-
}
358-
return false
359-
}
360-
361-
func TestBuildLCoreConfigYAML(t *testing.T) {
362-
// Use a proper CR from test fixtures instead of nil
363-
cr := utils.GetDefaultOLSConfigCR()
364-
343+
func createTestReconciler() *utils.TestReconciler {
365344
// Create a fake client and reconciler for the test
366345
scheme := runtime.NewScheme()
367346
_ = olsv1alpha1.AddToScheme(scheme)
@@ -370,15 +349,19 @@ func TestBuildLCoreConfigYAML(t *testing.T) {
370349
WithScheme(scheme).
371350
Build()
372351
logger := zap.New(zap.UseDevMode(true))
373-
testReconciler := utils.NewTestReconciler(
352+
return utils.NewTestReconciler(
374353
fakeClient,
375354
logger,
376355
scheme,
377356
"test-namespace",
378357
)
358+
}
359+
360+
func TestBuildLCoreConfigYAML(t *testing.T) {
361+
// Use a proper CR from test fixtures instead of nil
362+
cr := utils.GetDefaultOLSConfigCR()
379363

380-
ctx := context.Background()
381-
yamlOutput, err := buildLCoreConfigYAML(testReconciler, ctx, cr)
364+
yamlOutput, err := buildLCoreConfigYAML(createTestReconciler(), context.Background(), cr)
382365
if err != nil {
383366
t.Fatalf("buildLCoreConfigYAML returned error: %v", err)
384367
}

internal/controller/lcore/config.go

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -374,23 +374,47 @@ func buildLlamaStackToolRuntime(_ reconciler.Reconciler, _ *olsv1alpha1.OLSConfi
374374
}
375375
}
376376

377-
func buildLlamaStackVectorDB(_ reconciler.Reconciler, _ *olsv1alpha1.OLSConfig) []interface{} {
378-
return []interface{}{
379-
map[string]interface{}{
380-
"provider_id": "faiss",
377+
func buildLlamaStackVectorIO(r reconciler.Reconciler, cr *olsv1alpha1.OLSConfig) []interface{} {
378+
vectorIOs := []interface{}{}
379+
// Use RAG configuration from OLSConfig if available
380+
if len(cr.Spec.OLSConfig.RAG) > 0 {
381+
for _, rag := range cr.Spec.OLSConfig.RAG {
382+
id := "byok_rag_" + sanitizeID(rag.Image)
383+
vectorIOs = append(vectorIOs, map[string]interface{}{
384+
"provider_id": id,
385+
"provider_type": "inline::faiss",
386+
"config": map[string]interface{}{
387+
"kvstore": map[string]interface{}{
388+
"db_path": "/rag-data/" + id + "/faiss_store.db",
389+
"type": "kv_sqlight",
390+
},
391+
"persistence": map[string]interface{}{
392+
"backend": "kv_default",
393+
"namespace": "vector_io::faiss",
394+
},
395+
},
396+
})
397+
}
398+
}
399+
if !cr.Spec.OLSConfig.ByokRAGOnly {
400+
// OCP RAG database
401+
vectorIOs = append(vectorIOs, map[string]interface{}{
402+
"provider_id": "ocp-rag",
381403
"provider_type": "inline::faiss",
382404
"config": map[string]interface{}{
383405
"kvstore": map[string]interface{}{
384-
"backend": "sql_default",
385-
"table_name": "vector_store",
406+
"db_path": "/rag-data/ocp/vector_db/ocp_product_docs/" + r.GetOpenShiftMajor() + "." + r.GetOpenshiftMinor() + "/faiss_store.db",
407+
"type": "kv_sqlight",
386408
},
387409
"persistence": map[string]interface{}{
388410
"backend": "kv_default",
389-
"namespace": "vector_persistence",
411+
"namespace": "vector_io::faiss",
390412
},
391413
},
392-
},
414+
})
393415
}
416+
417+
return vectorIOs
394418
}
395419

396420
func buildLlamaStackServerConfig(_ reconciler.Reconciler, _ *olsv1alpha1.OLSConfig) map[string]interface{} {
@@ -428,26 +452,19 @@ func buildLlamaStackVectorDBs(_ reconciler.Reconciler, cr *olsv1alpha1.OLSConfig
428452
vectorDB := map[string]interface{}{
429453
"embedding_model": "sentence-transformers/all-mpnet-base-v2",
430454
"embedding_dimension": 768,
431-
"provider_id": "faiss",
455+
"provider_id": "byok_rag_" + sanitizeID(rag.Image),
456+
"vector_db_id": "byok_rag_" + sanitizeID(rag.Image),
432457
}
433-
434-
// Use IndexID if specified, otherwise generate a default
435-
if rag.IndexID != "" {
436-
vectorDB["vector_db_id"] = rag.IndexID
437-
} else {
438-
// Generate a simple ID from the image name
439-
vectorDB["vector_db_id"] = "rag_" + sanitizeID(rag.Image)
440-
}
441-
442458
vectorDBs = append(vectorDBs, vectorDB)
443459
}
444-
} else {
445-
// Default fallback if no RAG configured
460+
}
461+
if !cr.Spec.OLSConfig.ByokRAGOnly {
462+
// OCP RAG database
446463
vectorDBs = append(vectorDBs, map[string]interface{}{
447-
"vector_db_id": "my_knowledge_base",
464+
"vector_db_id": "ocp-rag",
448465
"embedding_model": "sentence-transformers/all-mpnet-base-v2",
449466
"embedding_dimension": 768,
450-
"provider_id": "faiss",
467+
"provider_id": "ocp-rag",
451468
})
452469
}
453470

@@ -478,7 +495,7 @@ func buildLlamaStackModels(_ reconciler.Reconciler, cr *olsv1alpha1.OLSConfig) [
478495
"model_id": "sentence-transformers/all-mpnet-base-v2",
479496
"model_type": "embedding",
480497
"provider_id": "sentence-transformers",
481-
"provider_model_id": "sentence-transformers/all-mpnet-base-v2",
498+
"provider_model_id": "/rag-data/ocp/embeddings_model",
482499
"metadata": map[string]interface{}{
483500
"embedding_dimension": 768,
484501
},
@@ -595,7 +612,7 @@ func buildLlamaStackYAML(r reconciler.Reconciler, ctx context.Context, cr *olsv1
595612
"safety": buildLlamaStackSafety(r, cr), // Required by agents provider
596613
// "telemetry": buildLlamaStackTelemetry(r, cr), // Telemetry and tracing
597614
"tool_runtime": buildLlamaStackToolRuntime(r, cr), // Required for RAG
598-
"vector_io": buildLlamaStackVectorDB(r, cr), // Required for RAG
615+
"vector_io": buildLlamaStackVectorIO(r, cr), // Required for RAG
599616
}
600617

601618
// Add top-level fields

internal/controller/lcore/deployment.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ func GenerateLCoreDeployment(r reconciler.Reconciler, cr *olsv1alpha1.OLSConfig)
293293
// PostgreSQL CA ConfigMap volume (for TLS certificate verification)
294294
volumes = append(volumes, utils.GetPostgresCAConfigVolume())
295295

296+
// RAG volume
297+
volumes = append(volumes, utils.GenerateRAGVolume())
298+
296299
// llama-stack container volume mounts
297300
llamaStackVolumeMounts := []corev1.VolumeMount{
298301
{
@@ -315,6 +318,9 @@ func GenerateLCoreDeployment(r reconciler.Reconciler, cr *olsv1alpha1.OLSConfig)
315318
utils.GetPostgresCAVolumeMount("/etc/certs/postgres-ca"),
316319
}
317320

321+
// RAG volume mount
322+
llamaStackVolumeMounts = append(llamaStackVolumeMounts, utils.GenerateRAGVolumeMount())
323+
318324
// User provided CA certificates - create both volumes and volume mounts in single pass
319325
_ = utils.ForEachExternalConfigMap(cr, func(name, source string) error {
320326
var volumeName, llamaStackMountPath string
@@ -501,6 +507,16 @@ func GenerateLCoreDeployment(r reconciler.Reconciler, cr *olsv1alpha1.OLSConfig)
501507
Resources: *lightspeedStackResources,
502508
}
503509

510+
initContainers := []corev1.Container{}
511+
ocpRagDirName := "ocp"
512+
ocpRagDir := path.Join(utils.RAGVolumeMountPath, ocpRagDirName)
513+
initContainers = append(initContainers, utils.GenerateRAGInitContainer(ocpRagDirName, r.GetOcpRagImage(), ocpRagDir, cr))
514+
515+
if len(cr.Spec.OLSConfig.RAG) > 0 {
516+
ragInitContainers := utils.GenerateRAGInitContainers(cr)
517+
initContainers = append(initContainers, ragInitContainers...)
518+
}
519+
504520
deployment := appsv1.Deployment{
505521
ObjectMeta: metav1.ObjectMeta{
506522
Name: "lightspeed-stack-deployment",
@@ -528,7 +544,8 @@ func GenerateLCoreDeployment(r reconciler.Reconciler, cr *olsv1alpha1.OLSConfig)
528544
llamaStackContainer,
529545
lightspeedStackContainer,
530546
},
531-
Volumes: volumes,
547+
Volumes: volumes,
548+
InitContainers: initContainers,
532549
},
533550
},
534551
RevisionHistoryLimit: &revisionHistoryLimit,

0 commit comments

Comments
 (0)