Skip to content

OCPNODE-4040: Use single KubeletConfigIsAccepted condition type with True/False status#5854

Draft
aksjadha wants to merge 5 commits into
openshift:mainfrom
aksjadha:fix-OCPNODE-4040
Draft

OCPNODE-4040: Use single KubeletConfigIsAccepted condition type with True/False status#5854
aksjadha wants to merge 5 commits into
openshift:mainfrom
aksjadha:fix-OCPNODE-4040

Conversation

@aksjadha
Copy link
Copy Markdown

@aksjadha aksjadha commented Apr 16, 2026

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.Type from Success/Failure to KubeletConfigIsApplied and accordingly set status.Condition.Status to True/False

- How to verify it

Create a Kubeletconfig

1. Create kubeletconfig

$ cat kubeletconf.yaml
apiVersion: machineconfiguration.openshift.io/v1
kind: KubeletConfig
metadata:
  name: set-max-pods
spec:
  memorySwap:
     swapBehavior: LimitedSwap
  autoSizingReserved: true
  machineConfigPoolSelector:
    matchLabels:
      custom-kubelet: autoresize-reserved

$ oc apply -f kubeletconf.yaml

2. Verify kubeletconfig status:

$ oc get kubeletconfig set-max-pods -o yaml
[.....]
Status:
  Conditions:
    Last Transition Time:  2026-xx-xxTxx:xx:xxZ
    Message:               Success
    Status:                True
    Type:                  KubeletConfigIsApplied
    Last Transition Time:  2026-xx-xxTxx:xx:xxZ
    Message:               Error: KubeletConfiguration: swapBehavior is not allowed to be set, but contains: LimitedSwap
    Status:                False
    Type:                  KubeletConfigIsApplied

- Description for the changelog
This change makes kubeletconfig status more readable and understandable. Previously in case of Success, Status.Conditions.message and Status.Conditions.Type both fields showing Success.

Summary by CodeRabbit

  • Bug Fixes

    • KubeletConfig completion now treats the newer "accepted" condition (true/false) as completed alongside the legacy "success" condition, improving status handling and backward compatibility.
  • Tests

    • Test assertions and helpers updated to check the accepted-style condition and its true/false statuses and expected messages.

…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>
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 16, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 16, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Apr 16, 2026

@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.

Details

In response to this:

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.Type from Success/Failure to KubeletConfigIsApplied and accordingly set status.Condition.Status to True/False

- How to verify it

Create a Kubeletconfig

1. Create kubeletconfig

$ cat kubeletconf.yaml
apiVersion: machineconfiguration.openshift.io/v1
kind: KubeletConfig
metadata:
 name: set-max-pods
spec:
 memorySwap:
     swapBehavior: LimitedSwap
 autoSizingReserved: true
 machineConfigPoolSelector:
   matchLabels:
     custom-kubelet: autoresize-reserved

$ oc apply -f kubeletconf.yaml

2. Verify kubeletconfig status:

$ oc get kubeletconfig set-max-pods -o yaml
[.....]
Status:
  Conditions:
    Last Transition Time:  2026-xx-xxTxx:xx:xxZ
    Message:               Success
    Status:                True
    Type:                  KubeletConfigIsApplied
    Last Transition Time:  2026-xx-xxTxx:xx:xxZ
    Message:               Error: KubeletConfiguration: swapBehavior is not allowed to be set, but contains: LimitedSwap
    Status:                False
    Type:                  KubeletConfigIsApplied

- Description for the changelog
This change makes kubeletconfig status more readable and understandable. Previously in case of Success, Status.Conditions.message and Status.Conditions.Type both fields showing Success.

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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 29755eca-9b26-4cd2-9f7a-a57d12921164

📥 Commits

Reviewing files that changed from the base of the PR and between 7c72a53 and 60bec06.

⛔ Files ignored due to path filters (1)
  • vendor/github.com/openshift/api/machineconfiguration/v1/types.go is excluded by !**/vendor/**, !vendor/**
📒 Files selected for processing (1)
  • pkg/controller/kubelet-config/kubelet_config_controller.go
💤 Files with no reviewable changes (1)
  • pkg/controller/kubelet-config/kubelet_config_controller.go

Walkthrough

Unify 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.

Changes

Condition Type Refactoring

Layer / File(s) Summary
Completion detection and test helpers
pkg/apihelpers/apihelpers.go, pkg/controller/kubelet-config/kubelet_config_controller.go, test/extended-priv/kubeletconfig.go
AreMCGeneratingSubControllersCompletedForPool and syncKubeletConfig now treat the last KubeletConfig status condition as completed if it's KubeletConfigSuccess or KubeletConfigAccepted with ConditionTrue. Integration test polling helpers (waitUntilSuccess / waitUntilFailure) now assert the accepted condition's status and message.

Condition Error Wrapping

Layer / File(s) Summary
Condition generation and unit tests
pkg/controller/kubelet-config/helpers.go, pkg/controller/kubelet-config/helpers_test.go
wrapErrorWithCondition now sets the condition type to mcfgv1.KubeletConfigApplied and emits ConditionFalse on error / ConditionTrue on success; unit tests updated to expect the new condition type/status and adjusted case names.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 11 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing separate KubeletConfig condition types with a single type using True/False status values instead of separate Success/Failure types.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed All test case names in the PR use static, descriptive strings. No dynamic content, timestamps, UUIDs, or interpolation found in Ginkgo test titles or Go test names.
Test Structure And Quality ✅ Passed Tests follow quality requirements: single responsibility, assertions with failure messages, proper timeouts via EventuallyWithOffset in helper methods.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests are added in this PR. Modified files contain only production code, Go unit tests, and test utilities—no Ginkgo test definitions found.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests added. Changes are controller code, unit tests, and test helper functions used by existing e2e tests. Check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only KubeletConfig status condition handling logic and tests. No deployment manifests, pod affinity, nodeSelector, topology constraints, or scheduling-related changes detected.
Ote Binary Stdout Contract ✅ Passed PR introduces only condition type and logic changes with no new stdout writes, logging configuration changes, or process-level code modifications in main/init/BeforeSuite/AfterSuite.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e tests are added in this PR. Changes are limited to helper functions, unit tests, and test utilities—none of which are subject to the IPv6/disconnected network compatibility check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 16, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aksjadha
Once this PR has been reviewed and has the lgtm label, please assign pablintino for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 16, 2026

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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 kubernetes-sigs/prow repository.

@openshift-ci openshift-ci Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 16, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Apr 16, 2026

@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.

Details

In response to this:

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.Type from Success/Failure to KubeletConfigIsApplied and accordingly set status.Condition.Status to True/False

- How to verify it

Create a Kubeletconfig

1. Create kubeletconfig

$ cat kubeletconf.yaml
apiVersion: machineconfiguration.openshift.io/v1
kind: KubeletConfig
metadata:
 name: set-max-pods
spec:
 memorySwap:
     swapBehavior: LimitedSwap
 autoSizingReserved: true
 machineConfigPoolSelector:
   matchLabels:
     custom-kubelet: autoresize-reserved

$ oc apply -f kubeletconf.yaml

2. Verify kubeletconfig status:

$ oc get kubeletconfig set-max-pods -o yaml
[.....]
Status:
  Conditions:
    Last Transition Time:  2026-xx-xxTxx:xx:xxZ
    Message:               Success
    Status:                True
    Type:                  KubeletConfigIsApplied
    Last Transition Time:  2026-xx-xxTxx:xx:xxZ
    Message:               Error: KubeletConfiguration: swapBehavior is not allowed to be set, but contains: LimitedSwap
    Status:                False
    Type:                  KubeletConfigIsApplied

- Description for the changelog
This change makes kubeletconfig status more readable and understandable. Previously in case of Success, Status.Conditions.message and Status.Conditions.Type both fields showing Success.

Summary by CodeRabbit

  • Bug Fixes
  • Enhanced KubeletConfig status detection to properly recognize both new and legacy status conditions, improving backward compatibility and consistency in completion tracking.

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
pkg/controller/kubelet-config/kubelet_config_controller.go (1)

637-638: Tighten legacy success check to also require ConditionTrue.

The back-compat branch currently accepts KubeletConfigSuccess regardless 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

📥 Commits

Reviewing files that changed from the base of the PR and between f9f108a and 36aa492.

⛔ Files ignored due to path filters (1)
  • vendor/github.com/openshift/api/machineconfiguration/v1/types.go is excluded by !**/vendor/**, !vendor/**
📒 Files selected for processing (5)
  • pkg/apihelpers/apihelpers.go
  • pkg/controller/kubelet-config/helpers.go
  • pkg/controller/kubelet-config/helpers_test.go
  • pkg/controller/kubelet-config/kubelet_config_controller.go
  • test/extended-priv/kubeletconfig.go

Signed-off-by: aksjadha <aksjadha@redhat.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread vendor/github.com/openshift/api/machineconfiguration/v1/types.go Outdated
Comment thread pkg/controller/kubelet-config/helpers.go
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a 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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 36aa492 and 991307c.

⛔ Files ignored due to path filters (1)
  • vendor/github.com/openshift/api/machineconfiguration/v1/types.go is excluded by !**/vendor/**, !vendor/**
📒 Files selected for processing (5)
  • pkg/apihelpers/apihelpers.go
  • pkg/controller/kubelet-config/helpers.go
  • pkg/controller/kubelet-config/helpers_test.go
  • pkg/controller/kubelet-config/kubelet_config_controller.go
  • test/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]
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot May 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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

@aksjadha aksjadha changed the title OCPNODE-4040: Use single KubeletConfigIsApplied condition type with True/False status OCPNODE-4040: Use single KubeletConfigIsAccepted condition type with True/False status May 15, 2026
Comment thread pkg/controller/kubelet-config/kubelet_config_controller.go Outdated
Comment thread vendor/github.com/openshift/api/machineconfiguration/v1/types.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants