Skip to content

Commit 9f675fc

Browse files
feat(controller): address PR #73 review comments for OCP RAG
- Rename fields to include RAG (OCPRAGVersionOverride, ActiveOCPRAGVersion) - Default EnableOCPRAG to false (standard image doesn't include OCP docs) - Simplify status: remove DetectedOCPVersion, OCPVersionFallback, print column - Remove priority field from RAG configs (not in OLSConfig API) - Remove override validation to support custom RAG images - Add ClusterVersion watch for OCP upgrade detection - Improve error handling and add design decision comments - Update tests for new return types and removed validations Addresses feedback from @lpiwowar and @Akrog. JIRA: OSPRH-23918
1 parent c47bf63 commit 9f675fc

14 files changed

Lines changed: 246 additions & 347 deletions

api/v1beta1/conditions.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/*
22
Copyright 2025.
3+
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.
56
You may obtain a copy of the License at
7+
68
http://www.apache.org/licenses/LICENSE-2.0
9+
710
Unless required by applicable law or agreed to in writing, software
811
distributed under the License is distributed on an "AS IS" BASIS,
912
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,12 +26,15 @@ const (
2326
// is configured and operational
2427
OpenStackLightspeedReadyCondition condition.Type = "OpenStackLightspeedReady"
2528

26-
// OpenShift Lightspeed Operator Status=True condition which indicates if OpenShift Lightspeed is installed and
27-
// operational and it can be used by OpenStack Lihgtspeed operator.
29+
// OpenShiftLightspeedOperatorReadyCondition Status=True condition which indicates if OpenShift Lightspeed is installed and
30+
// operational and it can be used by OpenStack Lightspeed operator.
2831
OpenShiftLightspeedOperatorReadyCondition condition.Type = "OpenShiftLightspeedOperatorReady"
2932

30-
// OCPVersionCondition Status=True condition which indicates OCP version detection and resolution
31-
OCPVersionCondition condition.Type = "OCPVersionResolved"
33+
// OCPRAGCondition Status=True condition which indicates the OCP RAG version resolution status
34+
OCPRAGCondition condition.Type = "OCPRAGReady"
35+
36+
// OCPVersionCondition - DEPRECATED: Use OCPRAGCondition instead (keeping for backward compatibility)
37+
OCPVersionCondition condition.Type = "OCPRAGReady"
3238
)
3339

3440
// Common Messages used by API objects.
@@ -45,18 +51,27 @@ const (
4551
// OpenShiftLightspeedOperatorWaiting
4652
OpenShiftLightspeedOperatorWaiting = "Waiting for the OpenShift Lightspeed operator to deploy."
4753

48-
// OpenShiftLigthspeedOperatorReady
54+
// OpenShiftLightspeedOperatorReady
4955
OpenShiftLightspeedOperatorReady = "OpenShift Lightspeed operator is ready."
5056

51-
// OCPVersionDetected message when OCP version is detected and resolved successfully
52-
OCPVersionDetected = "OCP version detected and resolved successfully"
57+
// OCPRAGDisabledMessage
58+
OCPRAGDisabledMessage = "OCP RAG is disabled"
5359

54-
// OCPVersionFallback message when using 'latest' OCP documentation as fallback
55-
OCPVersionFallback = "Using 'latest' OCP documentation as fallback for unsupported cluster version"
60+
// OCPRAGVersionResolvedMessage
61+
OCPRAGVersionResolvedMessage = "OCP RAG version resolved: %s"
5662

57-
// OCPVersionOverrideInvalid message when OCP version override is invalid
58-
OCPVersionOverrideInvalid = "OCP version override is invalid"
63+
// OCPRAGVersionFallbackMessage
64+
OCPRAGVersionFallbackMessage = "Cluster version %s is not explicitly supported. Using 'latest' OCP documentation. Supported versions: %v"
5965

60-
// OCPVersionDetectionFailed message when OCP version detection fails
66+
// OCPRAGDetectionFailedMessage
67+
OCPRAGDetectionFailedMessage = "Failed to detect OCP cluster version"
68+
69+
// OCPRAGOverrideInvalidMessage
70+
OCPRAGOverrideInvalidMessage = "Invalid OCP RAG version override"
71+
72+
// OCPVersionDetectionFailed - DEPRECATED: Use OCPRAGDetectionFailedMessage
6173
OCPVersionDetectionFailed = "Failed to detect OCP cluster version"
74+
75+
// OCPVersionOverrideInvalid - DEPRECATED: Use OCPRAGOverrideInvalidMessage
76+
OCPVersionOverrideInvalid = "Invalid OCP RAG version override"
6277
)

api/v1beta1/openstacklightspeed_types.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ type OpenStackLightspeedSpec struct {
3939
RAGImage string `json:"ragImage"`
4040

4141
// +kubebuilder:validation:Optional
42-
// +kubebuilder:default=true
42+
// +kubebuilder:default=false
4343
// EnableOCPRAG enables automatic OCP documentation based on cluster version
4444
EnableOCPRAG bool `json:"enableOCPRAG,omitempty"`
4545

4646
// +kubebuilder:validation:Optional
4747
// OCPVersionOverride allows forcing a specific OCP version instead of auto-detection.
4848
// Format should be like "4.15", "4.16", etc.
49-
OCPVersionOverride string `json:"ocpVersionOverride,omitempty"`
49+
OCPRAGVersionOverride string `json:"ocpVersionOverride,omitempty"`
5050
}
5151

5252
// OpenStackLightspeedCore defines the desired state of OpenStackLightspeed
@@ -117,22 +117,15 @@ type OpenStackLightspeedStatus struct {
117117
// ObservedGeneration - the most recent generation observed for this object.
118118
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
119119

120-
// DetectedOCPVersion contains the auto-detected OCP cluster version
121-
DetectedOCPVersion string `json:"detectedOCPVersion,omitempty"`
122-
123120
// ActiveOCPVersion contains the OCP version being used for RAG configuration
124121
// 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"`
122+
ActiveOCPRAGVersion string `json:"activeOCPVersion,omitempty"`
129123
}
130124

131125
// +kubebuilder:object:root=true
132126
// +kubebuilder:subresource:status
133127
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[0].status",description="Status"
134128
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[0].message",description="Message"
135-
// +kubebuilder:printcolumn:name="OCP Version",type="string",JSONPath=".status.activeOCPVersion"
136129

137130
// OpenStackLightspeed is the Schema for the openstacklightspeeds API
138131
type OpenStackLightspeed struct {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ spec:
8888
verbs:
8989
- get
9090
- list
91+
- watch
9192
- apiGroups:
9293
- lightspeed.openstack.org
9394
resources:

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ spec:
2323
jsonPath: .status.conditions[0].message
2424
name: Message
2525
type: string
26-
- jsonPath: .status.activeOCPVersion
27-
name: OCP Version
28-
type: string
2926
name: v1beta1
3027
schema:
3128
openAPIV3Schema:
@@ -62,7 +59,7 @@ spec:
6259
operator is located
6360
type: string
6461
enableOCPRAG:
65-
default: true
62+
default: false
6663
description: EnableOCPRAG enables automatic OCP documentation based
6764
on cluster version
6865
type: boolean
@@ -178,19 +175,11 @@ spec:
178175
- type
179176
type: object
180177
type: array
181-
detectedOCPVersion:
182-
description: DetectedOCPVersion contains the auto-detected OCP cluster
183-
version
184-
type: string
185178
observedGeneration:
186179
description: ObservedGeneration - the most recent generation observed
187180
for this object.
188181
format: int64
189182
type: integer
190-
ocpVersionFallback:
191-
description: OCPVersionFallback indicates if using 'latest' as fallback
192-
for unsupported version
193-
type: boolean
194183
type: object
195184
type: object
196185
served: true

config/rbac/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rules:
1111
verbs:
1212
- get
1313
- list
14+
- watch
1415
- apiGroups:
1516
- lightspeed.openstack.org
1617
resources:

internal/controller/funcs.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,15 @@ 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-
{
140+
// BuildRAGConfigs builds the RAG configuration array.
141+
// OpenStack RAG is always included first.
142+
// OCP RAG is added if ocpVersion is provided.
143+
func BuildRAGConfigs(instance *apiv1beta1.OpenStackLightspeed, ocpVersion string) []interface{} {
144+
rags := []interface{}{
145+
// OpenStack RAG
146+
map[string]interface{}{
147147
"image": instance.Spec.RAGImage,
148148
"indexPath": OpenStackLightspeedVectorDBPath,
149-
"priority": 1,
150149
},
151150
}
152151

@@ -156,7 +155,6 @@ func BuildRAGConfigs(instance *apiv1beta1.OpenStackLightspeed, ocpVersion string
156155
"image": instance.Spec.RAGImage,
157156
"indexPath": GetOCPVectorDBPath(ocpVersion),
158157
"indexID": GetOCPIndexName(ocpVersion),
159-
"priority": 2,
160158
})
161159
}
162160

@@ -168,7 +166,6 @@ func PatchOLSConfig(
168166
helper *common_helper.Helper,
169167
instance *apiv1beta1.OpenStackLightspeed,
170168
olsConfig *uns.Unstructured,
171-
ocpVersion string,
172169
) error {
173170
// Patch the Providers section
174171
providersPatch := []interface{}{
@@ -215,13 +212,9 @@ func PatchOLSConfig(
215212

216213
// Patch the RAG section
217214
// 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
222-
}
215+
ragConfigs := BuildRAGConfigs(instance, instance.Status.ActiveOCPRAGVersion)
223216

224-
if err := uns.SetNestedSlice(olsConfig.Object, ragSlice, "spec", "ols", "rag"); err != nil {
217+
if err := uns.SetNestedSlice(olsConfig.Object, ragConfigs, "spec", "ols", "rag"); err != nil {
225218
return err
226219
}
227220

internal/controller/ocp_version.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,17 @@ func DetectOCPVersion(ctx context.Context, helper *common_helper.Helper) (string
6666
}
6767

6868
// Extract version from status.desired.version
69+
// NOTE: We intentionally use desired.version rather than history[0].version because:
70+
// - During OCP upgrades, desired.version reflects the target version
71+
// - Users troubleshooting upgrade issues need docs for the NEW version
72+
// - This provides proactive access to relevant documentation
6973
version, found, err := uns.NestedString(clusterVersion.Object, "status", "desired", "version")
70-
if !found || err != nil {
74+
if err != nil {
7175
return "", fmt.Errorf("failed to extract version from ClusterVersion: %w", err)
7276
}
77+
if !found {
78+
return "", fmt.Errorf("version field not found in ClusterVersion status.desired.version")
79+
}
7380

7481
// Parse version to get major.minor (e.g., "4.15.0" -> "4.15")
7582
majorMinor, err := ParseMajorMinorVersion(version)
@@ -139,12 +146,7 @@ func ResolveOCPVersion(detectedVersion, overrideVersion string, enableOCPRAG boo
139146

140147
// Use override if provided
141148
if overrideVersion != "" {
142-
// Check if override is a supported version
143-
if IsSupportedOCPVersion(overrideVersion) {
144-
return overrideVersion, false, nil
145-
}
146-
return "", false, fmt.Errorf("override version %s is not supported, must be one of: %v",
147-
overrideVersion, SupportedOCPVersions)
149+
return overrideVersion, false, nil
148150
}
149151

150152
// Use detected version

0 commit comments

Comments
 (0)