Skip to content

OCPBUGS-79069 - fix the since and sinceTime validation issue#345

Open
praveencodes wants to merge 5 commits into
openshift:masterfrom
praveencodes:OCPBUGS-79069
Open

OCPBUGS-79069 - fix the since and sinceTime validation issue#345
praveencodes wants to merge 5 commits into
openshift:masterfrom
praveencodes:OCPBUGS-79069

Conversation

@praveencodes
Copy link
Copy Markdown
Contributor

@praveencodes praveencodes commented Apr 30, 2026

OCPBUGS-79069 - Fixed the since and sinceTime validation issue.

since: 1d / since: 1w / since: 1y - The invalid values like this give validation error now.
since: -10s / since: -10d - These negative since values give validation error now.
sinceTime: 2026-04-02T00:00:00Z - The future date won't work. The CR error status will be updated now.
sinceTime: 2026-02-02t00:00:00Z / sinceTime: 2026-02-02T00:00:00z - The invalid values like these gives the validation error now.
Validation error for invalid since value - The MustGather "mustgather-with-since" is invalid: spec.gatherSpec: Invalid value: "object": since may only use these duration suffixes: ns, us, µs, ms, s, m, h (e.g. 2h, 30m, 168h for one week).

Validation error for invalid sinceTime value - The MustGather "mustgather-with-sincetime" is invalid: spec.gatherSpec: Invalid value: "object": sinceTime must be in RFC3339 format.

NOTE: since: 0s is not handled as part of this PR.

Summary by CodeRabbit

  • Bug Fixes

    • Stricter validation for MustGather time filters: since must be non-negative and use allowed duration units; sinceTime must match RFC3339 and cannot be in the future. Reconciliation now marks instances as validation failures when sinceTime is a future timestamp.
  • Tests

    • Added a unit test covering the future sinceTime validation path.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Walkthrough

Adds CRD-level validations for GatherSpec.since and GatherSpec.sinceTime (regex and non-negativity), removes generic format annotations, and enforces a controller-side rejection when SinceTime is in the future; a unit test covering the future-SinceTime path is included.

Changes

MustGather validation and reconciliation

Layer / File(s) Summary
Data Shape / API annotations
api/v1alpha1/mustgather_types.go
Removed generic format annotations and added explicit validation comments/annotations for GatherSpec.since and GatherSpec.sinceTime (allowed duration units, non-negative constraint, RFC3339 instant pattern).
CRD Schema / Manifests
bundle/manifests/.../operator.openshift.io_mustgathers.yaml, deploy/crds/operator.openshift.io_mustgathers.yaml
Updated spec.gatherSpec field descriptions and added x-kubernetes-validations rules: since non-negativity, since allowed-unit regex, and sinceTime RFC3339 regex; retained mutual-exclusion between since and sinceTime.
Constants / Keys
controllers/mustgather/constant.go
Added exported ValidationSinceTime constant ("sinceTime") for the validation key used by the controller.
Controller logic
controllers/mustgather/mustgather_controller.go
Added pre-job validation: if GatherSpec.SinceTime is set and is after current time, getJobFromInstance returns an error and the CR is marked Failed with the ValidationSinceTime reason.
Tests
controllers/mustgather/mustgather_controller_test.go
Added TestGetJobFromInstanceFutureSinceTimeSetsValidationStatus to assert that a future SinceTime causes getJobFromInstance to error and the MustGather status is set to Failed with a reason referencing ValidationSinceTime.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as MustGather Controller
    participant Clock as System Clock
    participant Status as CR Status Updater

    Client->>Controller: Reconcile MustGather (with SinceTime)
    Controller->>Clock: Read current time (now)
    Controller->>Controller: Compare SinceTime > now?
    alt SinceTime > now
        Controller->>Status: Mark CR Status Failed (ValidationSinceTime)
        Status-->>Client: Status updated (Failed)
    else SinceTime <= now
        Controller->>Controller: Proceed to job lookup/creation
        Controller-->>Client: Continue reconcile flow
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 10 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Topology-Aware Scheduling Compatibility ❓ Inconclusive No result was produced after verification. Marking as INCONCLUSIVE. Re-run the check or adjust instructions to produce a final result.
✅ 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 directly references the ticket and describes the main change: fixing validation for 'since' and 'sinceTime' fields, which aligns with the core functionality modified across CRD schemas, constants, and validation logic.
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 New test TestGetJobFromInstanceFutureSinceTimeSetsValidationStatus uses standard Go testing (not Ginkgo). Test name is static and descriptive with no dynamic values. No Ginkgo tests modified in PR.
Test Structure And Quality ✅ Passed The custom check is for Ginkgo test code. The PR adds a test to a standard Go testing.T file (mustgather_controller_test.go), not Ginkgo. The check is not applicable to this test type.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests added. PR adds only a unit test using Go testing package, not Ginkgo e2e tests. Check only applies to e2e tests.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests added in this PR. The added test is a unit test, not a Ginkgo e2e test. SNO compatibility check only applies to Ginkgo e2e tests.
Ote Binary Stdout Contract ✅ Passed Not applicable. This is a Kubernetes operator controller, not an OTE test binary. No stdout violations detected.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests added. Only a Go unit test added to mustgather_controller_test.go. Check scope is not applicable.

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

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@openshift-ci openshift-ci Bot requested review from Tafhim and rbhilare April 30, 2026 10:14
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 30, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 the current code and only fix it if needed.

Inline comments:
In `@bundle/manifests/tech-preview/operator.openshift.io_mustgathers.yaml`:
- Around line 75-76: The CRD in bundle/manifests still declares
spec.gatherSpec.since with format: duration while the deploy CRD removed it,
causing inconsistent validation; update the bundle CRD by removing the format:
duration entry for the spec.gatherSpec.since property so the schema matches the
deploy CRD (ensure the property under spec.gatherSpec.since in the
operator.openshift.io_mustgathers CRD only has type: string and no format).
🪄 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: 03cc9209-84ea-4967-89b6-e85c7de30f40

📥 Commits

Reviewing files that changed from the base of the PR and between 59b15a1 and 6ce4a4a.

📒 Files selected for processing (6)
  • api/v1alpha1/mustgather_types.go
  • bundle/manifests/tech-preview/operator.openshift.io_mustgathers.yaml
  • controllers/mustgather/constant.go
  • controllers/mustgather/mustgather_controller.go
  • controllers/mustgather/mustgather_controller_test.go
  • deploy/crds/operator.openshift.io_mustgathers.yaml

Comment thread bundle/manifests/tech-preview/operator.openshift.io_mustgathers.yaml Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.87%. Comparing base (59b15a1) to head (4397399).

Files with missing lines Patch % Lines
controllers/mustgather/mustgather_controller.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #345      +/-   ##
==========================================
- Coverage   62.89%   62.87%   -0.02%     
==========================================
  Files           8        8              
  Lines         830      835       +5     
==========================================
+ Hits          522      525       +3     
- Misses        302      303       +1     
- Partials        6        7       +1     
Files with missing lines Coverage Δ
api/v1alpha1/mustgather_types.go 100.00% <ø> (ø)
controllers/mustgather/mustgather_controller.go 58.65% <60.00%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 `@controllers/mustgather/mustgather_controller.go`:
- Around line 401-406: Run the sinceTime validation (the block that calls
setValidationFailureStatus with ValidationSinceTime) before calling
getMustGatherImage / reading OPERATOR_IMAGE so it short-circuits early; after
setting the validation failure status return a handled reconcile result that
does not propagate an error to ManageError (i.e., return the zero/handled
ctrl.Result and nil error from Reconcile) so downstream ManageError is not
invoked. Ensure you update the control flow in Reconcile to check the validation
first and use the same setValidationFailureStatus call/site as before.
🪄 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: b749aef8-f8e6-48df-a55e-3ec7310a9979

📥 Commits

Reviewing files that changed from the base of the PR and between d4fa624 and 4397399.

📒 Files selected for processing (2)
  • controllers/mustgather/mustgather_controller.go
  • controllers/mustgather/mustgather_controller_test.go

Comment on lines +401 to +406
if instance.Spec.GatherSpec != nil && instance.Spec.GatherSpec.SinceTime != nil && instance.Spec.GatherSpec.SinceTime.After(time.Now()) {
err := fmt.Errorf("gatherSpec.sinceTime must be at or before the current date and time")
if _, validationErr := r.setValidationFailureStatus(ctx, log, instance, ValidationSinceTime, err); validationErr != nil {
return nil, fmt.Errorf("failed to set validation failure status: %w, %w", err, validationErr)
}
return nil, err
Copy link
Copy Markdown

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

Short-circuit handled sinceTime validation before generic error handling.

This branch updates status via setValidationFailureStatus, but then still returns a non-nil error. Downstream, Line 159 sends that error into ManageError, so the future-sinceTime case is not actually a clean validation short-circuit. Also, because this check runs after image/env resolution, unrelated prereq failures can mask the sinceTime validation entirely.

Please run this validation before getMustGatherImage / OPERATOR_IMAGE lookup, and return a handled signal that Reconcile can exit on without calling ManageError.

🤖 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 `@controllers/mustgather/mustgather_controller.go` around lines 401 - 406, Run
the sinceTime validation (the block that calls setValidationFailureStatus with
ValidationSinceTime) before calling getMustGatherImage / reading OPERATOR_IMAGE
so it short-circuits early; after setting the validation failure status return a
handled reconcile result that does not propagate an error to ManageError (i.e.,
return the zero/handled ctrl.Result and nil error from Reconcile) so downstream
ManageError is not invoked. Ensure you update the control flow in Reconcile to
check the validation first and use the same setValidationFailureStatus call/site
as before.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 2026

@praveencodes: The following tests 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-gcp-operator 4397399 link true /test e2e-gcp-operator
ci/prow/validate-boilerplate 4397399 link false /test validate-boilerplate

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants