OCPNODE-4040: Use single KubeletConfigIsAccepted condition type with True/False status#5854
OCPNODE-4040: Use single KubeletConfigIsAccepted condition type with True/False status#5854aksjadha wants to merge 5 commits into
Conversation
…rue/False status Replace separate Success/Failure condition types with a unified KubeletConfigIsApplied type that uses Status=True for success and Status=False for failure, following standard Kubernetes condition conventions. Signed-off-by: aksjadha <aksjadha@redhat.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@aksjadha: This pull request references OCPNODE-4040 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions 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 openshift-eng/jira-lifecycle-plugin repository. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openshift/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
WalkthroughUnify KubeletConfig condition semantics: produced conditions now use a single Applied/Accepted form (True/False); controller and API checks accept either legacy Success or Accepted(True); unit and integration tests updated to assert the new/accepted condition semantics. ChangesCondition Type Refactoring
Condition Error Wrapping
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 11 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (11 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: aksjadha The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @aksjadha. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
|
@aksjadha: This pull request references OCPNODE-4040 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions 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 openshift-eng/jira-lifecycle-plugin repository. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pkg/controller/kubelet-config/kubelet_config_controller.go (1)
637-638: Tighten legacy success check to also requireConditionTrue.The back-compat branch currently accepts
KubeletConfigSuccessregardless of status.Suggested predicate tightening
- configSuccess = (lastCondition.Type == mcfgv1.KubeletConfigApplied && lastCondition.Status == corev1.ConditionTrue) || - lastCondition.Type == mcfgv1.KubeletConfigSuccess // backwards compatibility + configSuccess = (lastCondition.Type == mcfgv1.KubeletConfigApplied && lastCondition.Status == corev1.ConditionTrue) || + (lastCondition.Type == mcfgv1.KubeletConfigSuccess && lastCondition.Status == corev1.ConditionTrue) // backwards compatibility🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/controller/kubelet-config/kubelet_config_controller.go` around lines 637 - 638, The legacy success check currently treats any lastCondition.Type == mcfgv1.KubeletConfigSuccess as success regardless of status; update the configSuccess assignment so both branches require lastCondition.Status == corev1.ConditionTrue (i.e., require (lastCondition.Type == mcfgv1.KubeletConfigApplied && lastCondition.Status == corev1.ConditionTrue) || (lastCondition.Type == mcfgv1.KubeletConfigSuccess && lastCondition.Status == corev1.ConditionTrue)), referencing configSuccess, lastCondition.Type/Status, mcfgv1.KubeletConfigApplied, mcfgv1.KubeletConfigSuccess and corev1.ConditionTrue.pkg/apihelpers/apihelpers.go (1)
391-391: Add a defensive empty-slice check before reading the last condition.
mck.Status.Conditions[len(...)-1]can panic if conditions are absent; return “not completed” instead.Suggested hardening
- lastCondition := mck.Status.Conditions[len(mck.Status.Conditions)-1] + if len(mck.Status.Conditions) == 0 { + return fmt.Errorf("KubeletConfig has not completed") + } + lastCondition := mck.Status.Conditions[len(mck.Status.Conditions)-1]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/apihelpers/apihelpers.go` at line 391, Add a defensive check before reading the last condition from mck.Status.Conditions: if len(mck.Status.Conditions) == 0 return the "not completed" status immediately instead of accessing the last element; otherwise proceed to read lastCondition := mck.Status.Conditions[len(mck.Status.Conditions)-1]. This prevents a panic when Conditions is empty and ensures the function returns "not completed" in that case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/apihelpers/apihelpers.go`:
- Line 391: Add a defensive check before reading the last condition from
mck.Status.Conditions: if len(mck.Status.Conditions) == 0 return the "not
completed" status immediately instead of accessing the last element; otherwise
proceed to read lastCondition :=
mck.Status.Conditions[len(mck.Status.Conditions)-1]. This prevents a panic when
Conditions is empty and ensures the function returns "not completed" in that
case.
In `@pkg/controller/kubelet-config/kubelet_config_controller.go`:
- Around line 637-638: The legacy success check currently treats any
lastCondition.Type == mcfgv1.KubeletConfigSuccess as success regardless of
status; update the configSuccess assignment so both branches require
lastCondition.Status == corev1.ConditionTrue (i.e., require (lastCondition.Type
== mcfgv1.KubeletConfigApplied && lastCondition.Status == corev1.ConditionTrue)
|| (lastCondition.Type == mcfgv1.KubeletConfigSuccess && lastCondition.Status ==
corev1.ConditionTrue)), referencing configSuccess, lastCondition.Type/Status,
mcfgv1.KubeletConfigApplied, mcfgv1.KubeletConfigSuccess and
corev1.ConditionTrue.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 27468e66-24dc-4534-865a-a305916d4395
⛔ Files ignored due to path filters (1)
vendor/github.com/openshift/api/machineconfiguration/v1/types.gois excluded by!**/vendor/**,!vendor/**
📒 Files selected for processing (5)
pkg/apihelpers/apihelpers.gopkg/controller/kubelet-config/helpers.gopkg/controller/kubelet-config/helpers_test.gopkg/controller/kubelet-config/kubelet_config_controller.gotest/extended-priv/kubeletconfig.go
Signed-off-by: aksjadha <aksjadha@redhat.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tConfig has been accepted"
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/apihelpers/apihelpers.go`:
- Line 391: The code unconditionally accesses the last element of
mck.Status.Conditions which will panic if the slice is empty; update the logic
around the line that sets lastCondition :=
mck.Status.Conditions[len(mck.Status.Conditions)-1] to first check
len(mck.Status.Conditions) == 0 and, in that case, return a non-completed error
(or the existing not-completed error path) instead of indexing; otherwise
proceed to set lastCondition and continue as before—look for usages of
mck.Status.Conditions and the local variable lastCondition to apply this guard.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 45a947f0-3e5a-4393-b372-d7cd45214f05
⛔ Files ignored due to path filters (1)
vendor/github.com/openshift/api/machineconfiguration/v1/types.gois excluded by!**/vendor/**,!vendor/**
📒 Files selected for processing (5)
pkg/apihelpers/apihelpers.gopkg/controller/kubelet-config/helpers.gopkg/controller/kubelet-config/helpers_test.gopkg/controller/kubelet-config/kubelet_config_controller.gotest/extended-priv/kubeletconfig.go
🚧 Files skipped from review as they are similar to previous changes (2)
- pkg/controller/kubelet-config/helpers.go
- pkg/controller/kubelet-config/kubelet_config_controller.go
| } | ||
|
|
||
| if mck.Status.Conditions[len(mck.Status.Conditions)-1].Type != mcfgv1.KubeletConfigSuccess { | ||
| lastCondition := mck.Status.Conditions[len(mck.Status.Conditions)-1] |
There was a problem hiding this comment.
Guard against empty status.conditions before last-element access.
Line 391 can panic if mck.Status.Conditions is empty. Add a length check and return a non-completed error instead of indexing unconditionally.
Suggested fix
- lastCondition := mck.Status.Conditions[len(mck.Status.Conditions)-1]
+ if len(mck.Status.Conditions) == 0 {
+ return fmt.Errorf("KubeletConfig has not completed: no status conditions")
+ }
+ lastCondition := mck.Status.Conditions[len(mck.Status.Conditions)-1]📝 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.
| lastCondition := mck.Status.Conditions[len(mck.Status.Conditions)-1] | |
| if len(mck.Status.Conditions) == 0 { | |
| return fmt.Errorf("KubeletConfig has not completed: no status conditions") | |
| } | |
| lastCondition := mck.Status.Conditions[len(mck.Status.Conditions)-1] |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/apihelpers/apihelpers.go` at line 391, The code unconditionally accesses
the last element of mck.Status.Conditions which will panic if the slice is
empty; update the logic around the line that sets lastCondition :=
mck.Status.Conditions[len(mck.Status.Conditions)-1] to first check
len(mck.Status.Conditions) == 0 and, in that case, return a non-completed error
(or the existing not-completed error path) instead of indexing; otherwise
proceed to set lastCondition and continue as before—look for usages of
mck.Status.Conditions and the local variable lastCondition to apply this guard.
✅ Addressed in commit 7c72a53
… on an empty slice in aihelper.go
Replace separate Success/Failure condition types with a unified KubeletConfigIsApplied type that uses Status=True for success and Status=False for failure, following standard Kubernetes condition conventions.
- What I did
Replace Kubeletconfig
status.Condition.TypefromSuccess/FailuretoKubeletConfigIsAppliedand accordingly setstatus.Condition.StatustoTrue/False- How to verify it
Create a Kubeletconfig
- Description for the changelog
This change makes kubeletconfig status more readable and understandable. Previously in case of Success,
Status.Conditions.messageandStatus.Conditions.Typeboth fields showing Success.Summary by CodeRabbit
Bug Fixes
Tests