Skip to content

OCPBUGS-6075: nodelink: log and emit events for invalid labels#1496

Open
RadekManak wants to merge 1 commit intoopenshift:mainfrom
RadekManak:OCPBUGS-6075
Open

OCPBUGS-6075: nodelink: log and emit events for invalid labels#1496
RadekManak wants to merge 1 commit intoopenshift:mainfrom
RadekManak:OCPBUGS-6075

Conversation

@RadekManak
Copy link
Copy Markdown
Contributor

@RadekManak RadekManak commented May 6, 2026

Summary

  • Validate Machine labels before applying them to the Node, using metav1validation.ValidateLabels to catch malformed labels early with a clear error message
  • Log errors at default verbosity (klog.Errorf) for both label validation failures and node update errors, so they're visible without needing --v=11
  • Emit Warning events (InvalidNodeLabels, FailedUpdateNode) on the Machine object so failures surface via oc describe machine

Fixes https://issues.redhat.com/browse/OCPBUGS-6075

Test plan

  • Unit tests pass (make test)
  • Lint passes (make lint)
  • Added TestReconcileWithInvalidLabels covering:
    • Valid labels succeed without error
    • Invalid label values (e.g. bar/baz) are rejected with error + event
    • Invalid label keys (e.g. spaces in key) are rejected with error + event

Summary by CodeRabbit

  • New Features

    • Events are now emitted when node labels fail validation or when node updates fail.
    • Kubernetes label validation is performed before applying node updates.
  • Tests

    • Added comprehensive test coverage for node label validation, including both valid and invalid scenarios with event emission verification.

The nodelink controller silently swallowed errors when copying
malformed labels from Machine to Node. The client.Update() returned
a 422 but the error was only visible at --v=11 via HTTP round-tripper
logs.

- Validate labels before attempting the node update using
  metav1validation.ValidateLabels, catching invalid labels early
  with a clear error message
- Log errors with klog.Errorf (visible at default verbosity) for
  both validation failures and update errors
- Emit Warning events (InvalidNodeLabels, FailedUpdateNode) on the
  Machine object so failures are visible via oc describe machine
@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels May 6, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@RadekManak: This pull request references Jira Issue OCPBUGS-6075, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • Validate Machine labels before applying them to the Node, using metav1validation.ValidateLabels to catch malformed labels early with a clear error message
  • Log errors at default verbosity (klog.Errorf) for both label validation failures and node update errors, so they're visible without needing --v=11
  • Emit Warning events (InvalidNodeLabels, FailedUpdateNode) on the Machine object so failures surface via oc describe machine

Fixes https://issues.redhat.com/browse/OCPBUGS-6075

Test plan

  • Unit tests pass (make test)
  • Lint passes (make lint)
  • Added TestReconcileWithInvalidLabels covering:
  • Valid labels succeed without error
  • Invalid label values (e.g. bar/baz) are rejected with error + event
  • Invalid label keys (e.g. spaces in key) are rejected with error + event

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 May 6, 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: 1bda3a9b-5a3f-4d86-9082-e7ed763d78fe

📥 Commits

Reviewing files that changed from the base of the PR and between 3687798 and 4ef3491.

📒 Files selected for processing (2)
  • pkg/controller/nodelink/nodelink_controller.go
  • pkg/controller/nodelink/nodelink_controller_test.go

Walkthrough

The PR adds event recording and Kubernetes label validation to the NodeLink controller. It introduces an eventRecorder field, validates node labels before updates, and emits warning events when validation fails or updates encounter errors.

Changes

NodeLink Controller Event Recording & Label Validation

Layer / File(s) Summary
Data Shape
pkg/controller/nodelink/nodelink_controller.go
ReconcileNodeLink struct gains eventRecorder field of type events.EventRecorder.
Core Logic & Validation
pkg/controller/nodelink/nodelink_controller.go
New validateNodeLabels() helper delegates to Kubernetes label validation; validation is called before node updates with errors logged and warning events recorded; update failures also emit events via event recorder.
Wiring & Initialization
pkg/controller/nodelink/nodelink_controller.go
Event recorder is initialized from the manager during reconciler construction: mgr.GetEventRecorder("nodelink-controller").
Imports & Dependencies
pkg/controller/nodelink/nodelink_controller.go
Added imports for validation helpers and events recorder functionality.
Tests & Test Fixtures
pkg/controller/nodelink/nodelink_controller_test.go
Fake event recorder added to test reconciler setup; new TestReconcileWithInvalidLabels function validates label validation and event emission on valid and invalid labels.

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 42.86% 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 summarizes the main change: adding event emission and logging for invalid node labels in the NodeLink controller.
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 TestReconcileWithInvalidLabels uses stable, static test names via t.Run() with hardcoded strings. No dynamic information present.
Test Structure And Quality ✅ Passed Test meets all quality criteria: single responsibility, proper setup/cleanup, no timeout issues, meaningful assertion messages, and consistent with codebase patterns.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added. TestReconcileWithInvalidLabels is a standard Go unit test, not a Ginkgo e2e test. The check does not apply.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR does not add Ginkgo e2e tests. The new test is a standard Go unit test (testing.T), not Ginkgo. SNO compatibility check does not apply.
Topology-Aware Scheduling Compatibility ✅ Passed This PR adds label validation and event recording to a controller. No scheduling manifests, affinity rules, or topology constraints are introduced.
Ote Binary Stdout Contract ✅ Passed PR modifies standard controller and unit test code, not OTE binary entry points or E2E test suites. No stdout-writing violations detected. All logging uses klog (stderr by default).
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests added. PR adds a unit test using Go's testing package, not Ginkgo. Custom check only applies to Ginkgo e2e tests.

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

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.1)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


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

@openshift-ci openshift-ci Bot requested review from damdo and theobarberbany May 6, 2026 13:48
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nrb 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

@RadekManak
Copy link
Copy Markdown
Contributor Author

/hold clanker created

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 6, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 2026

@RadekManak: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-ovn 4ef3491 link true /test e2e-aws-ovn

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants