Skip to content

Commit 535627e

Browse files
feat(controller): add OCP version auto-detection for RAG configuration
Implements logic to automatically detect the OpenShift Cluster Version and configure the OLS RAG database paths accordingly. - Adds to query ClusterVersion API. - Implements version resolution logic: - Exact match for supported versions (e.g., 4.16, 4.18). - Fallback to latest for newer/unsupported versions. - Allows manual override via CR Spec. - Updates OpenStackLightspeed Status with detection results. - Moves version resolution before OLS Operator dependency check to provide immediate status feedback. JIRA: OSPRH-23918
1 parent b6cc1dc commit 535627e

14 files changed

Lines changed: 788 additions & 11 deletions

api/v1beta1/conditions.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const (
2626
// OpenShift Lightspeed Operator Status=True condition which indicates if OpenShift Lightspeed is installed and
2727
// operational and it can be used by OpenStack Lihgtspeed operator.
2828
OpenShiftLightspeedOperatorReadyCondition condition.Type = "OpenShiftLightspeedOperatorReady"
29+
30+
// OCPVersionCondition Status=True condition which indicates OCP version detection and resolution
31+
OCPVersionCondition condition.Type = "OCPVersionResolved"
2932
)
3033

3134
// Common Messages used by API objects.
@@ -44,4 +47,16 @@ const (
4447

4548
// OpenShiftLigthspeedOperatorReady
4649
OpenShiftLightspeedOperatorReady = "OpenShift Lightspeed operator is ready."
50+
51+
// OCPVersionDetected message when OCP version is detected and resolved successfully
52+
OCPVersionDetected = "OCP version detected and resolved successfully"
53+
54+
// OCPVersionFallback message when using 'latest' OCP documentation as fallback
55+
OCPVersionFallback = "Using 'latest' OCP documentation as fallback for unsupported cluster version"
56+
57+
// OCPVersionOverrideInvalid message when OCP version override is invalid
58+
OCPVersionOverrideInvalid = "OCP version override is invalid"
59+
60+
// OCPVersionDetectionFailed message when OCP version detection fails
61+
OCPVersionDetectionFailed = "Failed to detect OCP cluster version"
4762
)

api/v1beta1/openstacklightspeed_types.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ type OpenStackLightspeedSpec struct {
3737
// +kubebuilder:validation:Optional
3838
// ContainerImage for the OpenStack Lightspeed RAG container (will be set to environmental default if empty)
3939
RAGImage string `json:"ragImage"`
40+
41+
// +kubebuilder:validation:Optional
42+
// +kubebuilder:default=true
43+
// EnableOCPRAG enables automatic OCP documentation based on cluster version
44+
EnableOCPRAG bool `json:"enableOCPRAG,omitempty"`
45+
46+
// +kubebuilder:validation:Optional
47+
// OCPVersionOverride allows forcing a specific OCP version instead of auto-detection.
48+
// Format should be like "4.15", "4.16", etc.
49+
OCPVersionOverride string `json:"ocpVersionOverride,omitempty"`
4050
}
4151

4252
// OpenStackLightspeedCore defines the desired state of OpenStackLightspeed
@@ -106,12 +116,23 @@ type OpenStackLightspeedStatus struct {
106116

107117
// ObservedGeneration - the most recent generation observed for this object.
108118
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
119+
120+
// DetectedOCPVersion contains the auto-detected OCP cluster version
121+
DetectedOCPVersion string `json:"detectedOCPVersion,omitempty"`
122+
123+
// ActiveOCPVersion contains the OCP version being used for RAG configuration
124+
// Will be one of: "4.16", "4.18", "latest", or empty if OCP RAG is disabled
125+
ActiveOCPVersion string `json:"activeOCPVersion,omitempty"`
126+
127+
// OCPVersionFallback indicates if using 'latest' as fallback for unsupported version
128+
OCPVersionFallback bool `json:"ocpVersionFallback,omitempty"`
109129
}
110130

111131
// +kubebuilder:object:root=true
112132
// +kubebuilder:subresource:status
113133
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[0].status",description="Status"
114134
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[0].message",description="Message"
135+
// +kubebuilder:printcolumn:name="OCP Version",type="string",JSONPath=".status.activeOCPVersion"
115136

116137
// OpenStackLightspeed is the Schema for the openstacklightspeeds API
117138
type OpenStackLightspeed struct {

bundle/manifests/lightspeed.openstack.org_openstacklightspeeds.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ spec:
2323
jsonPath: .status.conditions[0].message
2424
name: Message
2525
type: string
26+
- jsonPath: .status.activeOCPVersion
27+
name: OCP Version
28+
type: string
2629
name: v1beta1
2730
schema:
2831
openAPIV3Schema:
@@ -58,6 +61,11 @@ spec:
5861
description: Namespace where the CatalogSource containing the OLS
5962
operator is located
6063
type: string
64+
enableOCPRAG:
65+
default: true
66+
description: EnableOCPRAG enables automatic OCP documentation based
67+
on cluster version
68+
type: boolean
6169
feedbackDisabled:
6270
description: Disable feedback collection
6371
type: boolean
@@ -99,6 +107,11 @@ spec:
99107
description: Name of the model to use at the API endpoint provided
100108
in LLMEndpoint
101109
type: string
110+
ocpVersionOverride:
111+
description: |-
112+
OCPVersionOverride allows forcing a specific OCP version instead of auto-detection.
113+
Format should be like "4.15", "4.16", etc.
114+
type: string
102115
ragImage:
103116
description: ContainerImage for the OpenStack Lightspeed RAG container
104117
(will be set to environmental default if empty)
@@ -118,6 +131,11 @@ spec:
118131
status:
119132
description: OpenStackLightspeedStatus defines the observed state of OpenStackLightspeed
120133
properties:
134+
activeOCPVersion:
135+
description: |-
136+
ActiveOCPVersion contains the OCP version being used for RAG configuration
137+
Will be one of: "4.16", "4.18", "latest", or empty if OCP RAG is disabled
138+
type: string
121139
conditions:
122140
description: Conditions
123141
items:
@@ -160,11 +178,19 @@ spec:
160178
- type
161179
type: object
162180
type: array
181+
detectedOCPVersion:
182+
description: DetectedOCPVersion contains the auto-detected OCP cluster
183+
version
184+
type: string
163185
observedGeneration:
164186
description: ObservedGeneration - the most recent generation observed
165187
for this object.
166188
format: int64
167189
type: integer
190+
ocpVersionFallback:
191+
description: OCPVersionFallback indicates if using 'latest' as fallback
192+
for unsupported version
193+
type: boolean
168194
type: object
169195
type: object
170196
served: true

bundle/manifests/openstack-lightspeed-operator.clusterserviceversion.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ spec:
8181
spec:
8282
clusterPermissions:
8383
- rules:
84+
- apiGroups:
85+
- config.openshift.io
86+
resources:
87+
- clusterversions
88+
verbs:
89+
- get
90+
- list
8491
- apiGroups:
8592
- lightspeed.openstack.org
8693
resources:

config/crd/bases/lightspeed.openstack.org_openstacklightspeeds.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ spec:
2323
jsonPath: .status.conditions[0].message
2424
name: Message
2525
type: string
26+
- jsonPath: .status.activeOCPVersion
27+
name: OCP Version
28+
type: string
2629
name: v1beta1
2730
schema:
2831
openAPIV3Schema:
@@ -58,6 +61,11 @@ spec:
5861
description: Namespace where the CatalogSource containing the OLS
5962
operator is located
6063
type: string
64+
enableOCPRAG:
65+
default: true
66+
description: EnableOCPRAG enables automatic OCP documentation based
67+
on cluster version
68+
type: boolean
6169
feedbackDisabled:
6270
description: Disable feedback collection
6371
type: boolean
@@ -99,6 +107,11 @@ spec:
99107
description: Name of the model to use at the API endpoint provided
100108
in LLMEndpoint
101109
type: string
110+
ocpVersionOverride:
111+
description: |-
112+
OCPVersionOverride allows forcing a specific OCP version instead of auto-detection.
113+
Format should be like "4.15", "4.16", etc.
114+
type: string
102115
ragImage:
103116
description: ContainerImage for the OpenStack Lightspeed RAG container
104117
(will be set to environmental default if empty)
@@ -118,6 +131,11 @@ spec:
118131
status:
119132
description: OpenStackLightspeedStatus defines the observed state of OpenStackLightspeed
120133
properties:
134+
activeOCPVersion:
135+
description: |-
136+
ActiveOCPVersion contains the OCP version being used for RAG configuration
137+
Will be one of: "4.16", "4.18", "latest", or empty if OCP RAG is disabled
138+
type: string
121139
conditions:
122140
description: Conditions
123141
items:
@@ -160,11 +178,19 @@ spec:
160178
- type
161179
type: object
162180
type: array
181+
detectedOCPVersion:
182+
description: DetectedOCPVersion contains the auto-detected OCP cluster
183+
version
184+
type: string
163185
observedGeneration:
164186
description: ObservedGeneration - the most recent generation observed
165187
for this object.
166188
format: int64
167189
type: integer
190+
ocpVersionFallback:
191+
description: OCPVersionFallback indicates if using 'latest' as fallback
192+
for unsupported version
193+
type: boolean
168194
type: object
169195
type: object
170196
served: true

config/rbac/role.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ kind: ClusterRole
44
metadata:
55
name: manager-role
66
rules:
7+
- apiGroups:
8+
- config.openshift.io
9+
resources:
10+
- clusterversions
11+
verbs:
12+
- get
13+
- list
714
- apiGroups:
815
- lightspeed.openstack.org
916
resources:

internal/controller/funcs.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,38 @@ func GetOLSConfig(ctx context.Context, helper *common_helper.Helper) (uns.Unstru
137137
"OLSConfig")
138138
}
139139

140+
// BuildRAGConfigs builds the RAG configuration array with priorities.
141+
// OpenStack RAG is always included with priority 1.
142+
// OCP RAG is added with priority 2 if ocpVersion is provided.
143+
func BuildRAGConfigs(instance *apiv1beta1.OpenStackLightspeed, ocpVersion string) []map[string]interface{} {
144+
rags := []map[string]interface{}{
145+
// OpenStack RAG - Priority 1
146+
{
147+
"image": instance.Spec.RAGImage,
148+
"indexPath": OpenStackLightspeedVectorDBPath,
149+
"priority": 1,
150+
},
151+
}
152+
153+
// Add OCP RAG if enabled
154+
if ocpVersion != "" {
155+
rags = append(rags, map[string]interface{}{
156+
"image": instance.Spec.RAGImage,
157+
"indexPath": GetOCPVectorDBPath(ocpVersion),
158+
"indexID": GetOCPIndexName(ocpVersion),
159+
"priority": 2,
160+
})
161+
}
162+
163+
return rags
164+
}
165+
140166
// PatchOLSConfig patches OLSConfig with information from OpenStackLightspeed instance.
141167
func PatchOLSConfig(
142168
helper *common_helper.Helper,
143169
instance *apiv1beta1.OpenStackLightspeed,
144170
olsConfig *uns.Unstructured,
171+
ocpVersion string,
145172
) error {
146173
// Patch the Providers section
147174
providersPatch := []interface{}{
@@ -187,17 +214,14 @@ func PatchOLSConfig(
187214
}
188215

189216
// Patch the RAG section
190-
// NOTE(lucasagomes): We don't need indexID here because the tag on our RAG images
191-
// already matches the indexID that the Vector DB used when it was built. OLS leverages
192-
// that to set the right index.
193-
openstackRAG := []interface{}{
194-
map[string]interface{}{
195-
"image": instance.Spec.RAGImage,
196-
"indexPath": OpenStackLightspeedVectorDBPath,
197-
},
217+
// Build RAG array with priorities using BuildRAGConfigs
218+
ragConfigs := BuildRAGConfigs(instance, ocpVersion)
219+
ragSlice := make([]interface{}, len(ragConfigs))
220+
for i, rag := range ragConfigs {
221+
ragSlice[i] = rag
198222
}
199223

200-
if err := uns.SetNestedSlice(olsConfig.Object, openstackRAG, "spec", "ols", "rag"); err != nil {
224+
if err := uns.SetNestedSlice(olsConfig.Object, ragSlice, "spec", "ols", "rag"); err != nil {
201225
return err
202226
}
203227

0 commit comments

Comments
 (0)