-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathlcore_deployment.go
More file actions
709 lines (646 loc) · 23.1 KB
/
Copy pathlcore_deployment.go
File metadata and controls
709 lines (646 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
/*
Copyright 2026.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package controller
import (
"context"
"fmt"
"path"
"slices"
"strconv"
"strings"
common_helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
apiv1beta1 "github.com/openstack-lightspeed/operator/api/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
)
// buildLCorePodTemplateSpec builds the pod template spec for the LCore deployment.
// This function is used by CreateOrPatch to generate the desired pod spec.
func buildLCorePodTemplateSpec(h *common_helper.Helper, ctx context.Context, instance *apiv1beta1.OpenStackLightspeed) (corev1.PodTemplateSpec, error) {
// Build shared volumes
volumes := []corev1.Volume{
buildOGXConfigVolume(VolumeDefaultMode),
buildLightspeedStackConfigVolume(VolumeDefaultMode),
buildVectorDBScriptsVolume(),
}
// Shared volumes - CA bundle covers all cluster CAs
sharedMounts := []corev1.VolumeMount{}
addCABundleVolumesAndMounts(&volumes, &sharedMounts)
addVectorDBDataVolumesAndMounts(&volumes, &sharedMounts)
// Llama cache emptydir
llamaCacheMounts := []corev1.VolumeMount{}
addLlamaCacheVolumesAndMounts(&volumes, &llamaCacheMounts)
// Build env vars
llamaEnvVars, err := buildLlamaStackEnvVars(h, ctx, instance)
if err != nil {
return corev1.PodTemplateSpec{}, fmt.Errorf("failed to build llama-stack env vars: %w", err)
}
lsEnvVars := buildLightspeedStackEnvVars(instance)
// Llama Stack container mounts: its config + shared + cache + vector_store_db data
llamaStackMounts := []corev1.VolumeMount{}
llamaStackMounts = append(llamaStackMounts, sharedMounts...)
llamaStackMounts = append(llamaStackMounts, llamaCacheMounts...)
llamaStackContainer := corev1.Container{
Name: "llama-stack",
Image: apiv1beta1.OpenStackLightspeedDefaultValues.LCoreImageURL,
Command: []string{"llama", "stack", "run", VectorDBVolumeOGXConfigPath},
Ports: []corev1.ContainerPort{{Name: "llama-stack", ContainerPort: LlamaStackContainerPort}},
VolumeMounts: llamaStackMounts,
Env: llamaEnvVars,
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt32(LlamaStackContainerPort),
},
},
InitialDelaySeconds: 5,
PeriodSeconds: 10,
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceMemory: resource.MustParse("8Gi"),
},
},
ImagePullPolicy: corev1.PullIfNotPresent,
}
// Data collection volumes (shared folder + exporter config)
dataCollectionEnabled := isDataCollectionEnabled(instance)
if dataCollectionEnabled {
addDataCollectorVolumes(&volumes, VolumeDefaultMode)
}
// Lightspeed Stack container mounts: its config + shared + TLS (only API container needs TLS)
lightspeedStackMounts := []corev1.VolumeMount{}
lightspeedStackMounts = append(lightspeedStackMounts, sharedMounts...)
tlsMounts := []corev1.VolumeMount{}
addTLSVolumesAndMounts(&volumes, &tlsMounts, VolumeDefaultMode)
lightspeedStackMounts = append(lightspeedStackMounts, tlsMounts...)
// Mount shared data folder on lightspeed-service-api for feedback/transcripts
if dataCollectionEnabled {
lightspeedStackMounts = append(lightspeedStackMounts, corev1.VolumeMount{
Name: UserDataVolumeName,
MountPath: LCoreUserDataMountPath,
})
}
lightspeedStackContainer := corev1.Container{
Name: "lightspeed-service-api",
Image: apiv1beta1.OpenStackLightspeedDefaultValues.LCoreImageURL,
Args: []string{"-c", VectorDBVolumeLightspeedStackConfigPath},
Ports: []corev1.ContainerPort{{Name: "https", ContainerPort: OpenStackLightspeedAppServerContainerPort}},
VolumeMounts: lightspeedStackMounts,
Env: lsEnvVars,
LivenessProbe: buildLightspeedStackLivenessProbe(),
ReadinessProbe: buildLightspeedStackReadinessProbe(),
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("250m"),
corev1.ResourceMemory: resource.MustParse("512Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
},
},
ImagePullPolicy: corev1.PullIfNotPresent,
}
containers := []corev1.Container{llamaStackContainer, lightspeedStackContainer}
// Add dataverse exporter sidecar when data collection is enabled
if dataCollectionEnabled {
exporterContainer := corev1.Container{
Name: DataverseExporterContainerName,
Image: apiv1beta1.OpenStackLightspeedDefaultValues.ExporterImageURL,
ImagePullPolicy: corev1.PullAlways,
Args: []string{
"--mode", "openshift",
"--config", path.Join(ExporterConfigMountPath, ExporterConfigFilename),
"--log-level", instance.Spec.Logging.DataverseExporterLogLevel,
"--data-dir", LCoreUserDataMountPath,
},
VolumeMounts: []corev1.VolumeMount{
{
Name: UserDataVolumeName,
MountPath: LCoreUserDataMountPath,
},
{
Name: ExporterConfigVolumeName,
MountPath: ExporterConfigMountPath,
ReadOnly: true,
},
{
Name: CABundleVolumeName,
MountPath: CABundleMountPath,
SubPath: CABundleKey,
ReadOnly: true,
},
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("50m"),
corev1.ResourceMemory: resource.MustParse("64Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("200Mi"),
},
},
}
containers = append(containers, exporterContainer)
}
// Build configmap resource version annotations for change detection
annotations, err := buildConfigMapAnnotations(h, ctx)
if err != nil {
return corev1.PodTemplateSpec{}, err
}
initContainers, err := buildInitContainers(ctx, h, instance)
if err != nil {
return corev1.PodTemplateSpec{}, err
}
return corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: generateAppServerSelectorLabels(),
Annotations: annotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: OpenStackLightspeedAppServerServiceAccountName,
InitContainers: initContainers,
Containers: containers,
Volumes: volumes,
},
}, nil
}
// buildInitContainers returns the configuration for initContainers that run
// before the main OGX and Lightspeed Stack containers in the Lightspeed Stack
// deployment. These initContainers are responsible for generating the final OGX
// and Lightspeed Stack configuration files, incorporating information from
// the provided vector database images. For details on their logic, see:
// (1) assets/vector_database_collect.sh and (2) assets/vector_database_build.py.
func buildInitContainers(
ctx context.Context,
helper *common_helper.Helper,
instance *apiv1beta1.OpenStackLightspeed,
) ([]corev1.Container, error) {
ocp_version, err := DetectOCPVersion(ctx, helper)
if err != nil {
return []corev1.Container{}, err
}
securityContext := &corev1.SecurityContext{
RunAsNonRoot: &[]bool{true}[0],
AllowPrivilegeEscalation: &[]bool{false}[0],
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
}
resourceRequirements := corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
corev1.ResourceMemory: resource.MustParse("256Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
}
var containers []corev1.Container
containers = append(containers, corev1.Container{
Name: "vector-database-collect",
Image: instance.Spec.RAGImage,
Command: []string{
"sh", VectorDBScriptsMountPath + "/" + VectorDBCollectScriptKey,
"--vector-db-path", VectorDBVolumeMountPath,
"--enable-ocp-rag", strconv.FormatBool(instance.Spec.EnableOCPRAG),
"--ocp-version", ocp_version,
},
SecurityContext: securityContext,
Resources: resourceRequirements,
VolumeMounts: []corev1.VolumeMount{
{
Name: VectorDBVolumeName,
MountPath: VectorDBVolumeMountPath,
},
{
Name: VectorDBScriptsVolumeName,
MountPath: VectorDBScriptsMountPath,
ReadOnly: true,
},
},
})
configBuildCmd := []string{
"python3", VectorDBScriptsMountPath + "/" + VectorDBBuildScriptKey,
"--vector-db-path", VectorDBVolumeMountPath,
"--ogx-config-path", OGXConfigInitContainerMountPath,
"--lightspeed-stack-path", LightspeedStackInitContainerMountPath,
}
devConfig, _ := parseDevConfig(instance)
if devConfig.OKPRagOnly {
configBuildCmd = append(configBuildCmd, "--okp-rag-only")
}
containers = append(containers, corev1.Container{
Name: "vector-database-config-build",
Image: apiv1beta1.OpenStackLightspeedDefaultValues.LCoreImageURL,
Command: configBuildCmd,
SecurityContext: securityContext,
Resources: resourceRequirements,
VolumeMounts: []corev1.VolumeMount{
{
Name: VectorDBVolumeName,
MountPath: VectorDBVolumeMountPath,
},
{
Name: VectorDBScriptsVolumeName,
MountPath: VectorDBScriptsMountPath,
ReadOnly: true,
},
{
Name: OGXConfigVolumeName,
MountPath: OGXConfigInitContainerMountPath,
SubPath: OGXConfigCMKey,
},
{
Name: LightspeedStackConfig,
MountPath: LightspeedStackInitContainerMountPath,
SubPath: LightspeedStackConfigCMKey,
},
},
})
return containers, nil
}
// buildLightspeedStackConfigVolume returns the volume for the lightspeed-stack config.
func buildLightspeedStackConfigVolume(volumeDefaultMode int32) corev1.Volume {
return corev1.Volume{
Name: LightspeedStackConfig,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: LCoreConfigCmName,
},
DefaultMode: toPtr(volumeDefaultMode),
},
},
}
}
// buildOGXConfigVolume returns the volume for the OGX config.
func buildOGXConfigVolume(volumeDefaultMode int32) corev1.Volume {
return corev1.Volume{
Name: OGXConfigVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: LlamaStackConfigCmName,
},
DefaultMode: toPtr(volumeDefaultMode),
},
},
}
}
// buildVectorDBScriptsVolume returns the volume for the Vector DB scripts.
func buildVectorDBScriptsVolume() corev1.Volume {
return corev1.Volume{
Name: VectorDBScriptsVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: VectorDBScriptsConfigMapName,
},
DefaultMode: toPtr(VolumeExecutableMode),
},
},
}
}
func addVectorDBDataVolumesAndMounts(volumes *[]corev1.Volume, mounts *[]corev1.VolumeMount) {
*volumes = append(*volumes, corev1.Volume{
Name: VectorDBVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
})
*mounts = append(*mounts, corev1.VolumeMount{
Name: VectorDBVolumeName,
MountPath: VectorDBVolumeMountPath,
})
}
// addTLSVolumesAndMounts adds the service-ca TLS certificate volume and mount.
func addTLSVolumesAndMounts(volumes *[]corev1.Volume, mounts *[]corev1.VolumeMount, volumeDefaultMode int32) {
*volumes = append(*volumes, corev1.Volume{
Name: "tls-certs",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: OpenStackLightspeedCertsSecretName,
DefaultMode: toPtr(volumeDefaultMode),
},
},
})
*mounts = append(*mounts, corev1.VolumeMount{
Name: "tls-certs",
MountPath: OpenStackLightspeedAppCertsMountRoot + "/lightspeed-tls",
ReadOnly: true,
})
}
// addLlamaCacheVolumesAndMounts adds an emptydir volume for llama-stack cache.
func addLlamaCacheVolumesAndMounts(volumes *[]corev1.Volume, mounts *[]corev1.VolumeMount) {
*volumes = append(*volumes, corev1.Volume{
Name: "llama-cache",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
})
*mounts = append(*mounts, corev1.VolumeMount{
Name: "llama-cache",
MountPath: "/tmp/llama-stack",
})
}
// addDataCollectorVolumes adds the shared data EmptyDir and exporter config volumes.
func addDataCollectorVolumes(volumes *[]corev1.Volume, volumeDefaultMode int32) {
*volumes = append(*volumes, corev1.Volume{
Name: UserDataVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
})
*volumes = append(*volumes, corev1.Volume{
Name: ExporterConfigVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: ExporterConfigCmName,
},
DefaultMode: toPtr(volumeDefaultMode),
},
},
})
}
// addCABundleVolumesAndMounts adds the CA bundle volume and mount.
// The CA bundle is always present (created by reconcileCABundleConfigMap)
// and mounted at the RHEL system CA path so applications find it automatically.
func addCABundleVolumesAndMounts(volumes *[]corev1.Volume, mounts *[]corev1.VolumeMount) {
*volumes = append(*volumes, corev1.Volume{
Name: CABundleVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: CABundleConfigMapName,
},
DefaultMode: toPtr(VolumeDefaultMode),
},
},
})
*mounts = append(*mounts, corev1.VolumeMount{
Name: CABundleVolumeName,
MountPath: CABundleMountPath,
SubPath: CABundleKey,
ReadOnly: true,
})
}
// buildLlamaStackEnvVars builds environment variables for llama-stack,
// primarily provider API keys read from Kubernetes secrets.
func buildLlamaStackEnvVars(h *common_helper.Helper, ctx context.Context, instance *apiv1beta1.OpenStackLightspeed) ([]corev1.EnvVar, error) {
envVars := []corev1.EnvVar{}
{
provider := buildProvider(instance)
if provider.CredentialsSecret == "" {
return envVars, nil
}
envVarName := providerNameToEnvVarName(provider.Name)
if provider.Type == AzureOpenAIProviderName {
// Azure supports both API key and client credentials authentication.
// Read the secret to determine which fields are present.
secret := &corev1.Secret{}
err := h.GetClient().Get(ctx, types.NamespacedName{
Name: provider.CredentialsSecret,
Namespace: h.GetBeforeObject().GetNamespace(),
}, secret)
if err != nil {
return nil, fmt.Errorf("failed to get Azure provider secret %s: %w", provider.CredentialsSecret, err)
}
// API key (always include - required by LiteLLM's Pydantic validation)
if _, ok := secret.Data["apitoken"]; ok {
envVars = append(envVars, corev1.EnvVar{
Name: envVarName + "_API_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: provider.CredentialsSecret,
},
Key: "apitoken",
},
},
})
} else {
// Provide an empty default so the env var exists
envVars = append(envVars, corev1.EnvVar{
Name: envVarName + "_API_KEY",
Value: "",
})
}
// Client credentials fields for Azure AD authentication
for _, field := range []struct {
secretKey string
envSuffix string
}{
{"client_id", "_CLIENT_ID"},
{"tenant_id", "_TENANT_ID"},
{"client_secret", "_CLIENT_SECRET"},
} {
if _, ok := secret.Data[field.secretKey]; ok {
envVars = append(envVars, corev1.EnvVar{
Name: envVarName + field.envSuffix,
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: provider.CredentialsSecret,
},
Key: field.secretKey,
},
},
})
} else {
envVars = append(envVars, corev1.EnvVar{
Name: envVarName + field.envSuffix,
Value: "",
})
}
}
} else {
// Non-Azure providers: single API_KEY from the "apitoken" key
envVars = append(envVars, corev1.EnvVar{
Name: envVarName + "_API_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: provider.CredentialsSecret,
},
Key: "apitoken",
},
},
})
// For vLLM providers, also set the URL environment variable
// The vLLM adapter checks for VLLM_URL as a fallback if URL is not in config
if provider.Type == RHOAIVLLMProviderName || provider.Type == RHELAIVLLMProviderName {
if provider.URL != "" {
envVars = append(envVars, corev1.EnvVar{
Name: "VLLM_URL",
Value: provider.URL,
})
}
}
}
}
// Postgres password for ${env.POSTGRES_PASSWORD} substitution in llama-stack config
envVars = append(envVars, buildPostgresPasswordEnvVar())
// Logging configuration - set both for compatibility with llama-stack and OGX
ogxLogLevel := getOGXLogLevel(instance)
envVars = append(envVars, corev1.EnvVar{
Name: "LLAMA_STACK_LOGGING",
Value: ogxLogLevel,
})
envVars = append(envVars, corev1.EnvVar{
Name: "OGX_LOGGING",
Value: ogxLogLevel,
})
envVars = append(envVars, corev1.EnvVar{
Name: "VECTOR_DB_DATA_PATH",
Value: VectorDBVolumeMountPath,
})
if isOKPEnabled(instance) {
envVars = append(envVars, corev1.EnvVar{
Name: "RH_SERVER_OKP",
Value: fmt.Sprintf("http://%s.%s.svc:%d", OKPServiceName, instance.GetNamespace(), OKPServicePort),
})
// FIXME(lucasagomes): Llama-Stack expects HF_HOME to be set when OKP is enabled because it uses the
// Hugging Face Hub client to fetch the embedding model for OKP. Ideally we would include the model it
// downloads in the container image to avoid this.
envVars = append(envVars, corev1.EnvVar{
Name: "HF_HOME",
Value: "/tmp/huggingface",
})
}
return envVars, nil
}
// buildPostgresPasswordEnvVar returns the POSTGRES_PASSWORD env var sourced from the postgres secret.
func buildPostgresPasswordEnvVar() corev1.EnvVar {
return corev1.EnvVar{
Name: "POSTGRES_PASSWORD",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: PostgresSecretName,
},
Key: OpenStackLightspeedComponentPasswordFileName,
},
},
}
}
// buildLightspeedStackEnvVars builds environment variables for the lightspeed-stack container.
func buildLightspeedStackEnvVars(instance *apiv1beta1.OpenStackLightspeed) []corev1.EnvVar {
envVars := []corev1.EnvVar{
{
Name: "LIGHTSPEED_STACK_LOG_LEVEL",
Value: instance.Spec.Logging.LightspeedStackLogLevel,
},
buildPostgresPasswordEnvVar(),
}
if isOKPEnabled(instance) {
envVars = append(envVars, corev1.EnvVar{
Name: "RH_SERVER_OKP",
Value: fmt.Sprintf("http://%s.%s.svc:%d", OKPServiceName, instance.GetNamespace(), OKPServicePort),
})
}
return envVars
}
// buildLightspeedStackLivenessProbe returns the liveness probe for the lightspeed-stack container.
func buildLightspeedStackLivenessProbe() *corev1.Probe {
return &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt32(OpenStackLightspeedAppServerContainerPort),
},
},
InitialDelaySeconds: 30,
PeriodSeconds: 10,
TimeoutSeconds: 5,
FailureThreshold: 3,
}
}
// buildLightspeedStackReadinessProbe returns the readiness probe for the lightspeed-stack container.
func buildLightspeedStackReadinessProbe() *corev1.Probe {
return &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt32(OpenStackLightspeedAppServerContainerPort),
},
},
InitialDelaySeconds: 30,
PeriodSeconds: 10,
TimeoutSeconds: 5,
FailureThreshold: 3,
}
}
// getOGXLogLevel returns the log level for OGX/llama-stack container.
// Supports either standard levels (INFO, DEBUG, WARNING, ERROR, CRITICAL) or fine-grained control.
// Examples: "INFO" -> "all=info", "DEBUG" -> "all=debug", "core=debug,providers=info" -> "core=debug,providers=info"
// Defaults to "all=info" if not specified.
func getOGXLogLevel(instance *apiv1beta1.OpenStackLightspeed) string {
logLevel := instance.Spec.Logging.OGXLogLevel
// If it's a simple level (INFO, DEBUG, etc.), convert to "all=<level>" format
// Otherwise, pass through for fine-grained control (e.g., "core=debug,providers=info")
upperLogLevel := strings.ToUpper(logLevel)
allowedLogLevels := []string{"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}
if slices.Contains(allowedLogLevels, upperLogLevel) {
return fmt.Sprintf("all=%s", strings.ToLower(logLevel))
}
return logLevel
}
// buildConfigMapAnnotations builds annotations with configmap resource versions
// so that changes to the configmaps trigger a deployment rollout.
func buildConfigMapAnnotations(h *common_helper.Helper, ctx context.Context) (map[string]string, error) {
annotations := make(map[string]string)
lcoreVersion, err := getConfigMapResourceVersion(ctx, h, LCoreConfigCmName, h.GetBeforeObject().GetNamespace())
if err != nil {
// ConfigMap may not exist yet during initial creation
if !errors.IsNotFound(err) {
return nil, fmt.Errorf("failed to get LCore configmap resource version: %w", err)
}
} else {
annotations[LCoreConfigMapResourceVersionAnnotation] = lcoreVersion
}
llamaVersion, err := getConfigMapResourceVersion(ctx, h, LlamaStackConfigCmName, h.GetBeforeObject().GetNamespace())
if err != nil {
if !errors.IsNotFound(err) {
return nil, fmt.Errorf("failed to get Llama Stack configmap resource version: %w", err)
}
} else {
annotations[LlamaStackConfigMapResourceVersionAnnotation] = llamaVersion
}
vectorDBScriptsVersion, err := getConfigMapResourceVersion(ctx, h, VectorDBScriptsConfigMapName, h.GetBeforeObject().GetNamespace())
if err != nil {
if !errors.IsNotFound(err) {
return nil, fmt.Errorf("failed to get Vector DB scripts configmap resource version: %w", err)
}
} else {
annotations[VectorDBScriptsConfigMapVersionAnnotation] = vectorDBScriptsVersion
}
caBundleVersion, err := getConfigMapResourceVersion(ctx, h, CABundleConfigMapName, h.GetBeforeObject().GetNamespace())
if err != nil {
if !errors.IsNotFound(err) {
return nil, fmt.Errorf("failed to get CA bundle configmap resource version: %w", err)
}
} else {
annotations[CABundleConfigMapVersionAnnotation] = caBundleVersion
}
return annotations, nil
}