OCPNODE-4040: Use single KubeletConfigAccepted condition type with True/False status#5854
OCPNODE-4040: Use single KubeletConfigAccepted condition type with True/False status#5854aksjadha wants to merge 1 commit into
Conversation
|
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. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughProduced conditions now use a single KubeletConfigAccepted (ConditionTrue/ConditionFalse) form; controller/API completion checks accept KubeletConfigAccepted(True) or legacy KubeletConfigSuccess; 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
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
|
60bec06 to
7f764f1
Compare
|
/ok-to-test |
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`:
- Around line 395-396: The build fails because mcfgv1.KubeletConfigAccepted is
referenced in pkg/apihelpers/apihelpers.go but the vendored
github.com/openshift/api version only defines KubeletConfigSuccess/Failure;
either upgrade the openshift/api module in go.mod to a release that defines
mcfgv1.KubeletConfigAccepted (run `go get github.com/openshift/api@<version>`
and `go mod vendor`), or add a temporary compatibility shim: create a
single-source constant in the pkg/apihelpers package (e.g., const
KubeletConfigAccepted = "KubeletConfigAccepted") and update all uses that
currently reference mcfgv1.KubeletConfigAccepted (including kubelet-config
controller/helpers/tests) to use pkg/apihelpers.KubeletConfigAccepted until the
dependency is updated.
🪄 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: d87138a9-6cb1-40d9-9494-6a780f50b153
📒 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 due to trivial changes (1)
- pkg/controller/kubelet-config/kubelet_config_controller.go
| if !((lastCondition.Type == mcfgv1.KubeletConfigAccepted && lastCondition.Status == corev1.ConditionTrue) || | ||
| lastCondition.Type == mcfgv1.KubeletConfigSuccess) { // backwards compatibility |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Locate machineconfiguration API type definitions:"
api_file="$(fd -i 'types.go' vendor/github.com/openshift/api/machineconfiguration/v1 | head -n1 || true)"
if [[ -z "${api_file}" ]]; then
echo "ERROR: vendor openshift/api types.go not found"
exit 1
fi
echo "Using: ${api_file}"
echo
echo "Check available KubeletConfig condition constants:"
rg -n 'KubeletConfig(StatusConditionType|Success|Failure|Accepted|IsAccepted|IsApplied)' "${api_file}"
echo
echo "Find all new references to KubeletConfigAccepted in this PR surface:"
rg -n '\bKubeletConfigAccepted\b' pkg test
echo
echo "Expected: if no definition is found in ${api_file}, current references cannot compile."Repository: openshift/machine-config-operator
Length of output: 2617
Build blocker: mcfgv1.KubeletConfigAccepted missing from vendored openshift/api
pkg/apihelpers/apihelpers.go (lines 395-396) references mcfgv1.KubeletConfigAccepted, but vendor/github.com/openshift/api/machineconfiguration/v1/types.go only defines KubeletConfigSuccess and KubeletConfigFailure (no KubeletConfigAccepted). Update/sync the github.com/openshift/api dependency to a version that exports KubeletConfigAccepted, or add a temporary compatibility shim/alias so compilation succeeds (including the existing uses in kubelet-config controller/helpers/tests).
🧰 Tools
🪛 golangci-lint (2.12.2)
[error] 395-395: : # github.com/openshift/machine-config-operator/pkg/apihelpers
pkg/apihelpers/apihelpers.go:395:39: undefined: mcfgv1.KubeletConfigAccepted
(typecheck)
🤖 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` around lines 395 - 396, The build fails because
mcfgv1.KubeletConfigAccepted is referenced in pkg/apihelpers/apihelpers.go but
the vendored github.com/openshift/api version only defines
KubeletConfigSuccess/Failure; either upgrade the openshift/api module in go.mod
to a release that defines mcfgv1.KubeletConfigAccepted (run `go get
github.com/openshift/api@<version>` and `go mod vendor`), or add a temporary
compatibility shim: create a single-source constant in the pkg/apihelpers
package (e.g., const KubeletConfigAccepted = "KubeletConfigAccepted") and update
all uses that currently reference mcfgv1.KubeletConfigAccepted (including
kubelet-config controller/helpers/tests) to use
pkg/apihelpers.KubeletConfigAccepted until the dependency is updated.
|
@aksjadha: 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. |
Replace separate Success/Failure condition types with a unified
Acceptedtype that uses Status=True for success and Status=False for failure, following standard Kubernetes condition conventions.- What I did
Replace Kubeletconfig
status.Condition.TypefromSuccess/FailuretoAcceptedand accordingly setstatus.Condition.StatustoTrue/FalseRaised PR to add KubeletConfigAccepted const in 'openshift/api/machineconfiguration/v1/types.go'
- 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
Documentation