-
Notifications
You must be signed in to change notification settings - Fork 5
OKP: Filter by product version #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lpiwowar
merged 1 commit into
openstack-k8s-operators:main
from
umago:okp-version-detection
Jul 8, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| 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 ( | ||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/go-logr/logr" | ||
| ) | ||
|
|
||
| // ocpVersionBound maps an OCP version upper bound to a RHOSO version. | ||
| type ocpVersionBound struct { | ||
| maxOCPVersion string | ||
| rhosoVersion string | ||
| } | ||
|
|
||
| // ocpToRHOSOVersionMap maps OCP version upper bounds to RHOSO versions. | ||
| // Entries must be in ascending order of maxOCPVersion. | ||
| // Versions above the highest bound fall back to OKPDefaultRHOSOVersion. | ||
| // Add a new entry here when a new RHOSO version's content becomes available in the knowledge base. | ||
| var ocpToRHOSOVersionMap = []ocpVersionBound{ | ||
| {"4.21", "18.0"}, | ||
| // When RHOSO 19.0 content is available, add: {"4.XX", "19.0"} | ||
| } | ||
|
|
||
| // detectRHOSOVersion returns the RHOSO version corresponding to the given OCP version. | ||
| // Falls back to OKPDefaultRHOSOVersion if the version cannot be parsed or is above all defined bounds. | ||
| func detectRHOSOVersion(ocpVersion string, logger logr.Logger) string { | ||
| detected, err := semver.NewVersion(ocpVersion) | ||
|
umago marked this conversation as resolved.
|
||
| if err != nil { | ||
| logger.Info("Failed to parse OCP version, using default RHOSO version", | ||
| "ocpVersion", ocpVersion, "default", OKPDefaultRHOSOVersion) | ||
| return OKPDefaultRHOSOVersion | ||
| } | ||
|
|
||
| for _, entry := range ocpToRHOSOVersionMap { | ||
| bound, err := semver.NewVersion(entry.maxOCPVersion) | ||
| if err != nil { | ||
| logger.Info("Invalid bound in RHOSO version map, using default", | ||
| "bound", entry.maxOCPVersion, "default", OKPDefaultRHOSOVersion) | ||
| return OKPDefaultRHOSOVersion | ||
| } | ||
| if detected.Compare(bound) <= 0 { | ||
| return entry.rhosoVersion | ||
| } | ||
| } | ||
|
|
||
| logger.Info("OCP version above all known bounds, using default RHOSO version", | ||
| "ocpVersion", ocpVersion, "default", OKPDefaultRHOSOVersion) | ||
| return OKPDefaultRHOSOVersion | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| 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 ( | ||
| "testing" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| ) | ||
|
|
||
| func TestDetectRHOSOVersion(t *testing.T) { | ||
| logger := logr.Discard() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| ocpVersion string | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "Version below bound returns mapped RHOSO version", | ||
| ocpVersion: "4.16", | ||
| expected: "18.0", | ||
| }, | ||
| { | ||
| name: "Version at bound returns mapped RHOSO version", | ||
| ocpVersion: "4.21", | ||
| expected: "18.0", | ||
| }, | ||
| { | ||
| name: "Version with patch at bound returns mapped RHOSO version", | ||
| ocpVersion: "4.21.3", | ||
| expected: "18.0", | ||
| }, | ||
| { | ||
| name: "Version above all known bounds falls back to default", | ||
| ocpVersion: "4.22", | ||
| expected: OKPDefaultRHOSOVersion, | ||
| }, | ||
| { | ||
| name: "Far future version falls back to default", | ||
| ocpVersion: "5.0", | ||
| expected: OKPDefaultRHOSOVersion, | ||
| }, | ||
| { | ||
| name: "Invalid version string falls back to default", | ||
| ocpVersion: "not-a-version", | ||
| expected: OKPDefaultRHOSOVersion, | ||
| }, | ||
| { | ||
| name: "Empty version string falls back to default", | ||
| ocpVersion: "", | ||
| expected: OKPDefaultRHOSOVersion, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := detectRHOSOVersion(tt.ocpVersion, logger) | ||
| if result != tt.expected { | ||
| t.Errorf("detectRHOSOVersion(%q) = %q, want %q", tt.ocpVersion, result, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestDetectRHOSOVersionMapOrdering(t *testing.T) { | ||
| logger := logr.Discard() | ||
|
|
||
| // Save and restore the global map so this test is self-contained. | ||
| original := ocpToRHOSOVersionMap | ||
| t.Cleanup(func() { ocpToRHOSOVersionMap = original }) | ||
|
|
||
| ocpToRHOSOVersionMap = []ocpVersionBound{ | ||
| {"4.21", "18.0"}, | ||
| {"5.99", "19.0"}, | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| ocpVersion string | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "Version matched by first entry", | ||
| ocpVersion: "4.16", | ||
| expected: "18.0", | ||
| }, | ||
| { | ||
| name: "Version at boundary of first entry", | ||
| ocpVersion: "4.21", | ||
| expected: "18.0", | ||
| }, | ||
| { | ||
| name: "Version matched by second entry", | ||
| ocpVersion: "5.0", | ||
| expected: "19.0", | ||
| }, | ||
| { | ||
| name: "Version at boundary of second entry", | ||
| ocpVersion: "5.99", | ||
| expected: "19.0", | ||
| }, | ||
| { | ||
| name: "Version above all bounds falls back to default", | ||
| ocpVersion: "6.0", | ||
| expected: OKPDefaultRHOSOVersion, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := detectRHOSOVersion(tt.ocpVersion, logger) | ||
| if result != tt.expected { | ||
| t.Errorf("detectRHOSOVersion(%q) = %q, want %q", tt.ocpVersion, result, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,4 @@ spec: | |
| dev: | ||
| featureFlags: | ||
| - okp | ||
| okpChunkFilterQuery: "product:(*openstack* OR *openshift*)" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: I can see the
DetectOCPVersionhas been called multiple times , does it make sense to detect the version once and then pass it where ever call is made ?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked a bit into that when i was reviewing the code but, to be honest, this is a cheap k8s API call that should be completely fine in practice. I would keep it like this for now to keep the code clearer and have buildLCoreConfigYAML() and buildLlamaStackYAML() independently (they both call this common method)
In the future I believe we should compeltely remove the buildLlamaStackYAML() cause in LCORE there are ways of generating the LlamaStack (OGX) config from the LCORE config itself and keep things consistent. We should do that instead IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you guys think this duplication is something to address, I can do it no problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the OGX config generation from LCORE config for the future.