Skip to content

OCPBUGS-94251: Add CEL duration validation to NodePool drain/detach timeouts - #9117

Open
vismishr wants to merge 2 commits into
openshift:mainfrom
vismishr:fix-nodepool-duration-validation
Open

OCPBUGS-94251: Add CEL duration validation to NodePool drain/detach timeouts#9117
vismishr wants to merge 2 commits into
openshift:mainfrom
vismishr:fix-nodepool-duration-validation

Conversation

@vismishr

@vismishr vismishr commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

nodeDrainTimeout and nodeVolumeDetachTimeout on NodePoolSpec are *metav1.Duration with no CRD-level validation. Invalid strings like "1" (no unit suffix) pass admission, get stored in etcd, and crash the cluster-wide NodePool informer on deserialization (time.ParseDuration failure).

This PR adds XValidation CEL rules to both fields that validate the value matches Go duration syntax at admission time. Follows the HTTPKeepAliveTimeout precedent from openshift/api (operator/v1/types_ingress.go) for the CEL regex pattern and escaping.

Changes:

  • api/hypershift/v1beta1/nodepool_types.go: Added +kubebuilder:validation:Type:=string and +kubebuilder:validation:XValidation markers to both fields
  • Regenerated CRDs via make update
  • Added 8 envtest test cases (4 per field: 2 invalid, 2 valid)

Which issue(s) this PR fixes:

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

Special notes for your reviewer:

Follows the HTTPKeepAliveTimeout precedent from openshift/api for CEL regex escaping (four backslashes in the marker). MinLength/MaxLength omitted to avoid CRD schema check errors — the CEL regex already rejects empty/invalid strings.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Bug Fixes
    • Added validation for node drain and volume detach timeout values.
    • Timeout settings must now use valid, non-negative duration formats (e.g., 30s, 5m, 1h).

@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-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Jul 27, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@vismishr: This pull request references Jira Issue OCPBUGS-94251, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

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

Details

In response to this:

What this PR does / why we need it:

nodeDrainTimeout and nodeVolumeDetachTimeout on NodePoolSpec are *metav1.Duration with no CRD-level validation. Invalid strings like "1" (no unit suffix) pass admission, get stored in etcd, and crash the cluster-wide NodePool informer on deserialization (time.ParseDuration failure).

This PR adds XValidation CEL rules to both fields that validate the value matches Go duration syntax at admission time. Follows the HTTPKeepAliveTimeout precedent from openshift/api (operator/v1/types_ingress.go) for the CEL regex pattern and escaping.

Changes:

  • api/hypershift/v1beta1/nodepool_types.go: Added +kubebuilder:validation:Type:=string and +kubebuilder:validation:XValidation markers to both fields
  • Regenerated CRDs via make update
  • Added 8 envtest test cases (4 per field: 2 invalid, 2 valid)

Which issue(s) this PR fixes:

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

Special notes for your reviewer:

Follows the HTTPKeepAliveTimeout precedent from openshift/api for CEL regex escaping (four backslashes in the marker). MinLength/MaxLength omitted to avoid CRD schema check errors — the CEL regex already rejects empty/invalid strings.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

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

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 6338870b-e8e1-47d7-947d-68151f780732

📥 Commits

Reviewing files that changed from the base of the PR and between 0b792c4 and 494f2de.

⛔ Files ignored due to path filters (9)
  • api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests/nodepools.hypershift.openshift.io/AAA_ungated.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests/nodepools.hypershift.openshift.io/GCPPlatform.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests/nodepools.hypershift.openshift.io/OSStreams.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests/nodepools.hypershift.openshift.io/OpenStack.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • cmd/install/assets/crds/hypershift-operator/tests/nodepools.hypershift.openshift.io/stable.nodepools.validation.testsuite.yaml is excluded by !cmd/install/assets/**/*.yaml
  • cmd/install/assets/crds/hypershift-operator/zz_generated.crd-manifests/nodepools-CustomNoUpgrade.crd.yaml is excluded by !**/zz_generated.crd-manifests/**, !cmd/install/assets/**/*.yaml
  • cmd/install/assets/crds/hypershift-operator/zz_generated.crd-manifests/nodepools-Default.crd.yaml is excluded by !**/zz_generated.crd-manifests/**, !cmd/install/assets/**/*.yaml
  • cmd/install/assets/crds/hypershift-operator/zz_generated.crd-manifests/nodepools-TechPreviewNoUpgrade.crd.yaml is excluded by !**/zz_generated.crd-manifests/**, !cmd/install/assets/**/*.yaml
  • vendor/github.com/openshift/hypershift/api/hypershift/v1beta1/nodepool_types.go is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (1)
  • api/hypershift/v1beta1/nodepool_types.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/hypershift/v1beta1/nodepool_types.go

📝 Walkthrough

Walkthrough

Added kubebuilder validation annotations to nodeDrainTimeout and nodeVolumeDetachTimeout in NodePoolSpec. Both fields now declare string types and require duration values with unit suffixes such as 30s, 5m, or 1h.

Suggested reviewers: jparrill, sdminonne

🚥 Pre-merge checks | ✅ 10 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Test Structure And Quality ❓ Inconclusive Tests are YAML-driven envtest validation tests, not Ginkgo Go tests. The check requests "Ginkgo test code" review, but this PR uses a different testing framework (envtest with YAML test suites). Ca... Clarify: Are YAML-driven envtest validation test suites acceptable, or must tests be Ginkgo-based Go tests with It blocks and BeforeEach/AfterEach hooks?
✅ Passed checks (10 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 CEL duration validation to NodePool drain and detach timeouts.
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 This PR adds 14 YAML-based CRD validation test cases, not Ginkgo tests. The test names are all static and deterministic with no dynamic content, clearly describing what each test validates. Since t...
Topology-Aware Scheduling Compatibility ✅ Passed PR only modifies CRD validation schema for duration fields, not deployment manifests, operator code, or scheduling constraints. Check is not applicable to this change.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests were added in this PR. Changes are only kubebuilder validation markers on NodePoolSpec timeout fields and envtest unit tests, not e2e tests that would need IPv6/disconnected net...
No-Weak-Crypto ✅ Passed PR adds duration field validation using Kubebuilder annotations; contains no cryptographic code, weak algorithms (MD5/SHA1/DES/RC4/3DES/Blowfish/ECB), custom crypto implementations, or non-constant...
Container-Privileges ✅ Passed Changed files are NodePool schema/CRD/testsuite updates; searches found no privileged, hostPID/Network/IPC, allowPrivilegeEscalation, SYS_ADMIN, or root-user fields.
No-Sensitive-Data-In-Logs ✅ Passed PR adds duration field validation annotations to nodepool_types.go without any logging code or sensitive data exposure; changes are purely declarative validation rules on struct fields.
✨ 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.

@openshift-ci openshift-ci Bot added area/api Indicates the PR includes changes for the API area/cli Indicates the PR includes changes for CLI and removed do-not-merge/needs-area labels Jul 27, 2026
@openshift-ci

openshift-ci Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vismishr
Once this PR has been reviewed and has the lgtm label, please assign csrwng 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
openshift-ci Bot requested review from jparrill and sdminonne July 27, 2026 10:46
@openshift-ci-robot

Copy link
Copy Markdown

@vismishr: This pull request references Jira Issue OCPBUGS-94251, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

What this PR does / why we need it:

nodeDrainTimeout and nodeVolumeDetachTimeout on NodePoolSpec are *metav1.Duration with no CRD-level validation. Invalid strings like "1" (no unit suffix) pass admission, get stored in etcd, and crash the cluster-wide NodePool informer on deserialization (time.ParseDuration failure).

This PR adds XValidation CEL rules to both fields that validate the value matches Go duration syntax at admission time. Follows the HTTPKeepAliveTimeout precedent from openshift/api (operator/v1/types_ingress.go) for the CEL regex pattern and escaping.

Changes:

  • api/hypershift/v1beta1/nodepool_types.go: Added +kubebuilder:validation:Type:=string and +kubebuilder:validation:XValidation markers to both fields
  • Regenerated CRDs via make update
  • Added 8 envtest test cases (4 per field: 2 invalid, 2 valid)

Which issue(s) this PR fixes:

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

Special notes for your reviewer:

Follows the HTTPKeepAliveTimeout precedent from openshift/api for CEL regex escaping (four backslashes in the marker). MinLength/MaxLength omitted to avoid CRD schema check errors — the CEL regex already rejects empty/invalid strings.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Bug Fixes
  • Added validation for node drain and volume detach timeout values.
  • Timeout settings must now use valid duration formats, such as 30s, 5m, or 1h.

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.

@vismishr
vismishr force-pushed the fix-nodepool-duration-validation branch from 0223375 to 3ed7210 Compare July 27, 2026 10:49
…ach timeouts

Add XValidation CEL rules to nodeDrainTimeout and nodeVolumeDetachTimeout
fields on NodePoolSpec to reject invalid duration strings at admission time.
Previously, malformed values like "1" (no unit suffix) passed CRD validation,
got stored in etcd, and crashed the cluster-wide NodePool informer on
deserialization.

Follows the HTTPKeepAliveTimeout precedent from openshift/api for the CEL
regex pattern matching Go duration syntax.
@vismishr
vismishr force-pushed the fix-nodepool-duration-validation branch from 3ed7210 to 0b792c4 Compare July 27, 2026 10:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 `@api/hypershift/v1beta1/nodepool_types.go`:
- Around line 187-197: Update the NodeDrainTimeout and nodeVolumeDetachTimeout
validations to use Kubernetes duration format validation with a non-negative
constraint instead of the current regex-only XValidation, preserving their
string representation and documented fields. Ensure validation matches
time.ParseDuration behavior, including rejecting overflow values while accepting
valid forms such as .5s and the ASCII us suffix. Add envtest coverage for
overflow rejection and these edge-valid duration forms.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: db181a01-10cf-463b-bba3-46866ffd925d

📥 Commits

Reviewing files that changed from the base of the PR and between 872a7e8 and 0223375.

⛔ Files ignored due to path filters (9)
  • api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests/nodepools.hypershift.openshift.io/AAA_ungated.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests/nodepools.hypershift.openshift.io/GCPPlatform.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests/nodepools.hypershift.openshift.io/OSStreams.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • api/hypershift/v1beta1/zz_generated.featuregated-crd-manifests/nodepools.hypershift.openshift.io/OpenStack.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • cmd/install/assets/crds/hypershift-operator/tests/nodepools.hypershift.openshift.io/stable.nodepools.validation.testsuite.yaml is excluded by !cmd/install/assets/**/*.yaml
  • cmd/install/assets/crds/hypershift-operator/zz_generated.crd-manifests/nodepools-CustomNoUpgrade.crd.yaml is excluded by !**/zz_generated.crd-manifests/**, !cmd/install/assets/**/*.yaml
  • cmd/install/assets/crds/hypershift-operator/zz_generated.crd-manifests/nodepools-Default.crd.yaml is excluded by !**/zz_generated.crd-manifests/**, !cmd/install/assets/**/*.yaml
  • cmd/install/assets/crds/hypershift-operator/zz_generated.crd-manifests/nodepools-TechPreviewNoUpgrade.crd.yaml is excluded by !**/zz_generated.crd-manifests/**, !cmd/install/assets/**/*.yaml
  • vendor/github.com/openshift/hypershift/api/hypershift/v1beta1/nodepool_types.go is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (1)
  • api/hypershift/v1beta1/nodepool_types.go

Comment thread api/hypershift/v1beta1/nodepool_types.go Outdated
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.51%. Comparing base (144cca9) to head (494f2de).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9117   +/-   ##
=======================================
  Coverage   44.51%   44.51%           
=======================================
  Files         774      774           
  Lines       96997    97003    +6     
=======================================
+ Hits        43179    43185    +6     
  Misses      50830    50830           
  Partials     2988     2988           

see 2 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.39% <ø> (ø)
cpo-hostedcontrolplane 47.22% <ø> (ø)
cpo-other 45.25% <ø> (ø)
hypershift-operator 54.46% <ø> (+0.01%) ⬆️
other 32.64% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ection

Update NodePool nodeDrainTimeout and nodeVolumeDetachTimeout CEL
validation to use duration() function for overflow detection and
accept leading-dot decimals like .5s. Follows the HTTPKeepAliveTimeout
two-rule pattern: regex for format + guarded duration() for range check.

Add envtest coverage for .5s, us suffix, and overflow edge cases.
@openshift-ci

openshift-ci Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@vismishr: all tests passed!

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

area/api Indicates the PR includes changes for the API area/cli Indicates the PR includes changes for CLI jira/valid-bug Indicates that a referenced Jira bug is valid 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.

3 participants