-
Notifications
You must be signed in to change notification settings - Fork 142
Teach config operator to filter feature gate manifests by major version inclusion #459
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds operator version parsing using semver and introduces version-based filtering for featuregate manifests. New helper functions evaluate whether manifests apply to the current operator version, filtering results in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes ✨ Finishing touches
Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JoelSpeed The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/operator/starter.go (1)
393-406: Consider avoiding variable shadowing for clarity.The loop variable
version(string) is shadowed by the parsed variable (uint64) at line 395. This makes the error message at line 398 less helpful, as it prints the parsed number instead of the original string that failed to parse.🔎 Proposed refactor
func includesDesiredVersion(versions []string, operatorVersion uint64) (bool, error) { - for _, version := range versions { - version, err := strconv.ParseUint(version, 10, 64) + for _, versionStr := range versions { + version, err := strconv.ParseUint(versionStr, 10, 64) if err != nil { // Malformed annotation so should be excluded - return false, fmt.Errorf("malformed annotation: %s", version) + return false, fmt.Errorf("malformed annotation: %s", versionStr) } if version == operatorVersion { return true, nil } } return false, nil }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (1)
pkg/operator/starter.go
🧰 Additional context used
📓 Path-based instructions (1)
**
⚙️ CodeRabbit configuration file
-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.
Files:
pkg/operator/starter.go
🔇 Additional comments (3)
pkg/operator/starter.go (3)
249-252: LGTM!The operator version parsing uses
ParseTolerant, which is appropriate for handling various version formats. Error handling is correct, and only the major version is extracted for filtering, which aligns with the feature requirements.
284-287: LGTM!The version-based filtering is correctly implemented. Manifests that don't apply to the current operator version are appropriately skipped during the walk.
12-12: Library verification complete:github.com/blang/semver/v4v4.0.0 is the latest stable version with no known security vulnerabilities.The import is safe to use.
| func excludesOperatorVersion(annotations map[string]string, operatorVersion uint64) bool { | ||
| var versionsRaw string | ||
|
|
||
| for k, v := range annotations { | ||
| if k == "release.openshift.io/major-version" { | ||
| versionsRaw = v | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if versionsRaw == "" { | ||
| return false | ||
| } | ||
|
|
||
| versions := strings.Split(versionsRaw, ",") | ||
|
|
||
| hasOperatorVersion, err := includesDesiredVersion(versions, operatorVersion) | ||
| if err != nil { | ||
| // Malformed annotation so should be excluded. | ||
| return true | ||
| } | ||
|
|
||
| return !hasOperatorVersion | ||
| } |
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.
Trim whitespace when parsing version list.
The version strings are split by comma but not trimmed of whitespace. If an annotation contains spaces (e.g., "4, 5"), the parsing in includesDesiredVersion will fail, causing the manifest to be incorrectly excluded.
🔎 Proposed fix to trim whitespace
versions := strings.Split(versionsRaw, ",")
+ for i := range versions {
+ versions[i] = strings.TrimSpace(versions[i])
+ }
hasOperatorVersion, err := includesDesiredVersion(versions, operatorVersion)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func excludesOperatorVersion(annotations map[string]string, operatorVersion uint64) bool { | |
| var versionsRaw string | |
| for k, v := range annotations { | |
| if k == "release.openshift.io/major-version" { | |
| versionsRaw = v | |
| break | |
| } | |
| } | |
| if versionsRaw == "" { | |
| return false | |
| } | |
| versions := strings.Split(versionsRaw, ",") | |
| hasOperatorVersion, err := includesDesiredVersion(versions, operatorVersion) | |
| if err != nil { | |
| // Malformed annotation so should be excluded. | |
| return true | |
| } | |
| return !hasOperatorVersion | |
| } | |
| func excludesOperatorVersion(annotations map[string]string, operatorVersion uint64) bool { | |
| var versionsRaw string | |
| for k, v := range annotations { | |
| if k == "release.openshift.io/major-version" { | |
| versionsRaw = v | |
| break | |
| } | |
| } | |
| if versionsRaw == "" { | |
| return false | |
| } | |
| versions := strings.Split(versionsRaw, ",") | |
| for i := range versions { | |
| versions[i] = strings.TrimSpace(versions[i]) | |
| } | |
| hasOperatorVersion, err := includesDesiredVersion(versions, operatorVersion) | |
| if err != nil { | |
| // Malformed annotation so should be excluded. | |
| return true | |
| } | |
| return !hasOperatorVersion | |
| } |
🤖 Prompt for AI Agents
In pkg/operator/starter.go around lines 368 to 391, the code splits the
annotation value by comma but does not trim whitespace so entries like "4, 5"
produce values with leading spaces and cause includesDesiredVersion to misparse
them; fix by iterating the versions slice after strings.Split, applying
strings.TrimSpace to each element and filtering out any empty strings, then pass
the cleaned slice to includesDesiredVersion (or alternatively trim when building
the versionsRaw) so parsing succeeds for annotations containing spaces.
|
@JoelSpeed: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
This teaches the config operator to filter based on major-version, see openshift/library-go#2069 and openshift/api#2637