Skip to content

RFE-5434: Add cluster ID and timestamp to must-gather directory name#2252

Open
asadawar wants to merge 5 commits intoopenshift:mainfrom
asadawar:rfe-5434-must-gather-dir-naming
Open

RFE-5434: Add cluster ID and timestamp to must-gather directory name#2252
asadawar wants to merge 5 commits intoopenshift:mainfrom
asadawar:rfe-5434-must-gather-dir-naming

Conversation

@asadawar
Copy link
Copy Markdown

@asadawar asadawar commented Apr 13, 2026

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

Summary by CodeRabbit

  • New Features

    • Enhanced must-gather destination naming to include a cluster identifier suffix (when available), a UTC timestamp, and a random suffix for clearer artifact organization and traceability.
    • Keeps a fallback naming format when cluster metadata is unavailable.
  • Tests

    • Added deterministic tests validating the new naming semantics, timestamp format, cluster-ID handling, and behavior when no cluster metadata/client is present.

@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 13, 2026
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 13, 2026

@asadawar: This pull request references RFE-5434 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 feature request to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

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 13, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Default must-gather output directory naming changed: when unset, DestDir is now generated by a new generateDestDir(ctx) method that includes a UTC timestamp and, when available, a cluster-id suffix (last 12 chars of cluster ID); if unavailable, the suffix is omitted.

Changes

Cohort / File(s) Summary
Must-Gather Core
pkg/cli/admin/mustgather/mustgather.go
Added (*MustGatherOptions).generateDestDir(ctx) and getClock() plus a clock clock.PassiveClock field. Complete() now calls generateDestDir when DestDir is empty. generateDestDir queries o.ConfigClient.ConfigV1().ClusterVersions().Get(...) (5s timeout) for cluster ID suffix (last 12 chars) and builds defaults: must-gather.local.<cluster-id-suffix>.<UTC-timestamp>.<rand> or fallback must-gather.local.<UTC-timestamp>.<rand>. Import set updated to include k8s.io/utils/clock. Example text updated.
Must-Gather Tests
pkg/cli/admin/mustgather/mustgather_test.go
Added deterministic tests TestGenerateDestDir and TestGenerateDestDirNoConfigClient using a fakeClock to fix timestamps. Tests assert prefix must-gather.local., conditional cluster-id suffix presence/format, UTC timestamp YYYYMMDDTHHMMSSZ, and trailing numeric suffix. Added/updated test imports (e.g., strings).

Sequence Diagram(s)

sequenceDiagram
    participant CLI as MustGatherOptions
    participant Config as Config API (ClusterVersions)
    participant Clock as PassiveClock

    CLI->>Clock: Now() (UTC timestamp)
    alt ConfigClient available
        CLI->>Config: Get(ClusterVersion) (with 5s timeout)
        Config-->>CLI: ClusterVersion (includes ClusterID)
        CLI->>CLI: extract last 12 chars of ClusterID
    else ConfigClient nil or unavailable
        CLI-->>CLI: no cluster-id suffix
    end
    CLI->>CLI: format dest dir "must-gather.local.[<suffix>.]<timestamp>.<rand>"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 9 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (9 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding cluster ID and timestamp to must-gather directory names, which matches the core functionality implemented in the PR.
Stable And Deterministic Test Names ✅ Passed All test names in the added test code are stable and deterministic with no dynamic values or timestamps in test titles.
Test Structure And Quality ✅ Passed The new tests meet all specified quality requirements. They test single, focused behaviors with meaningful assertion messages that include context. The tests follow established patterns in the codebase (table-driven tests, fake clients, standard error reporting), use appropriate test doubles (fakeClock implementing PassiveClock interface), and don't require BeforeEach/AfterEach setup since they're deterministic unit tests without state management or cluster resource cleanup needs.
Microshift Test Compatibility ✅ Passed PR adds standard Go unit tests (TestGenerateDestDir, TestGenerateDestDirNoConfigClient), not Ginkgo e2e tests with It(), Describe(), Context() patterns. Custom check applies only to Ginkgo e2e tests, so check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This pull request does not add Ginkgo e2e tests. The modified mustgather_test.go file contains only standard Go unit tests that use mocked clients and a fake clock to test the generateDestDir() method in isolation. These unit tests do not make assumptions about multi-node or HA cluster topologies, so SNO compatibility check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only oc adm must-gather CLI directory naming logic using ClusterVersion API; introduces no Kubernetes scheduling constraints, deployment manifests, or topology-incompatible features.
Ote Binary Stdout Contract ✅ Passed The PR modifications do not introduce any process-level stdout writes that would violate the OTE Binary Stdout Contract.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR contains only standard Go unit tests, no Ginkgo e2e tests detected.

✏️ 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 openshift-ci bot requested review from ingvagabund and tchap April 13, 2026 10:53
@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 13, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 13, 2026

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

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 `@pkg/cli/admin/mustgather/mustgather.go`:
- Around line 277-279: generateDestDir() currently calls
o.ConfigClient.ConfigV1().ClusterVersions().Get with context.TODO(), which can
block startup on slow/unreachable API servers; replace the context.TODO() with a
short timeout context (e.g., using context.WithTimeout) and defer cancel so the
lookup is bounded, then use that ctx when calling
ConfigV1().ClusterVersions().Get; target the call site referencing
o.ConfigClient, ConfigV1(), ClusterVersions().Get and ensure errors from context
deadline are handled the same as other lookup failures so the fallback path
still executes.
🪄 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), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: b20ea37c-8b72-4cbd-a950-65a1fbfb2bad

📥 Commits

Reviewing files that changed from the base of the PR and between 66dee73 and 7785cf8.

📒 Files selected for processing (2)
  • pkg/cli/admin/mustgather/mustgather.go
  • pkg/cli/admin/mustgather/mustgather_test.go

Comment thread pkg/cli/admin/mustgather/mustgather.go
@asadawar asadawar force-pushed the rfe-5434-must-gather-dir-naming branch from 1c1f293 to 7785cf8 Compare April 13, 2026 11:19
@tchap
Copy link
Copy Markdown
Contributor

tchap commented Apr 13, 2026

Wouldn't it be nicer to use must-gather.local.<cluster-id-suffix>.<timestamp>.<rand> ? Like this it would be sorted when listing by name according to cluster, timestamp.

@asadawar asadawar force-pushed the rfe-5434-must-gather-dir-naming branch from 7785cf8 to 7396e5b Compare April 13, 2026 13:10
@asadawar
Copy link
Copy Markdown
Author

Good point, reordered to must-gather.local.<cluster-id-suffix>.<timestamp>.<rand> so that ls groups by cluster and sorts chronologically. Updated.

@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 13, 2026

@asadawar: This pull request references RFE-5434 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 feature request to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

Summary by CodeRabbit

Release Notes

  • New Features
  • Enhanced must-gather directory naming to include cluster identifier and timestamp information for improved artifact organization and traceability.
  • Added fallback naming mechanism when cluster metadata is unavailable.

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.

@asadawar asadawar force-pushed the rfe-5434-must-gather-dir-naming branch from 7396e5b to 67a47be Compare April 14, 2026 14:41
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 14, 2026

@asadawar: This pull request references RFE-5434 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 feature request to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

Summary by CodeRabbit

  • New Features

  • Enhanced must-gather destination naming to include a cluster identifier suffix (when available), a UTC timestamp, and a random suffix for clearer artifact organization and traceability.

  • Retains a fallback naming format when cluster metadata is unavailable.

  • Tests

  • Added tests validating new naming semantics, timestamp format, and behavior when no cluster metadata/client is present.

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.

// times. If the cluster ID cannot be retrieved (e.g. cluster is unreachable), it falls back
// to the timestamp and random ID only.
// See: https://issues.redhat.com/browse/RFE-5434
func (o *MustGatherOptions) generateDestDir(ctx context.Context) string {
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.

Honestly would be nicer to pass a clock.Clock interface so that the tests are deterministic. And then align the tests to check for exact names instead of just contains.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good suggestion, done. Added a clock.PassiveClock field to MustGatherOptions — that's a smaller interface from k8s.io/utils/clock that only requires Now() and Since(), which is all we need here (the full Clock interface includes timers that we don't use).

In production, it's initialized with clock.RealClock{} in NewMustGatherOptions(), so it calls the real time.Now(). In tests, I created a simple fakeClock struct that returns a fixed time (2026-04-14T12:00:00Z), which lets us assert exact prefixes like must-gather.local.76708af6b91c.20260414T120000Z. instead of regex patterns.

The random suffix from rand.Int63() is still non-deterministic, but that's fine — the important parts (cluster ID and timestamp) are now fully testable.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@tchap just checking in on this. All your feedback has been addressed (reordering, clock.PassiveClock, klog.V(4) debug logging, fallback format in example text). Could you take a quick look when you get a chance? Also, would you be able to run /ok-to-test so CI can pick it up? Thanks!

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 `@pkg/cli/admin/mustgather/mustgather.go`:
- Around line 76-77: Update the example text in the must-gather help/usage block
(the comment containing "# Gather information..." and the example line "oc adm
must-gather") to explicitly show that the `<cluster-id-suffix>` is optional —
state that the default output directory is
`must-gather.local.<cluster-id-suffix>.<timestamp>.<rand>` but when a cluster ID
is unavailable the suffix is omitted producing
`must-gather.local.<timestamp>.<rand>`, and adjust the example line or add a
second example to demonstrate the fallback form without `<cluster-id-suffix>`.
🪄 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: 8609b9a3-7893-43d3-83a6-26b82ef7ddbe

📥 Commits

Reviewing files that changed from the base of the PR and between 7396e5b and 67a47be.

📒 Files selected for processing (2)
  • pkg/cli/admin/mustgather/mustgather.go
  • pkg/cli/admin/mustgather/mustgather_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/cli/admin/mustgather/mustgather_test.go

Comment thread pkg/cli/admin/mustgather/mustgather.go Outdated
Include the last 12 characters of the cluster ID and a UTC timestamp
in the auto-generated must-gather destination directory name. This helps
support engineers distinguish must-gather archives from different clusters
and collection times, especially when customers upload multiple archives
to the same support case.

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example:    must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

If the cluster ID cannot be retrieved (e.g. cluster is unreachable),
the directory name falls back to: must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434
@asadawar asadawar force-pushed the rfe-5434-must-gather-dir-naming branch from 67a47be to dda7aec Compare April 14, 2026 15:07
The example text now mentions both the format with cluster ID suffix
and the fallback format without it, so users know what to expect when
the cluster ID is unavailable.
Comment thread pkg/cli/admin/mustgather/mustgather.go Outdated
IOStreams: streams,
Timeout: 10 * time.Minute,
VolumePercentage: defaultVolumePercentage,
Clock: clock.RealClock{},
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.

Better to export as few fields as necessary. I would rename this to clock and only set it in tests. And in generateDestDir() you can do

clock := o.clock
if clock == nil {
    clock = clock.RealClock{}
}

Or feel free to add a helper method on MustGatherOptions like getClock() and that one returns o.clock or RealClock{} when that field is unset.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, updated. Renamed to unexported clock field, removed the default from the constructor, and added a getClock() helper that returns RealClock{} when nil. Went with the helper approach since there's already a similar getNamespace() pattern in the same file. Tests set the field directly since they're in the same package.

Renamed Clock to clock (unexported) since only tests need to set it.
Removed the default from the constructor and added a getClock() helper
that returns RealClock{} when the field is nil.
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 20, 2026

@asadawar: This pull request references RFE-5434 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 feature request to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Include the last 12 characters of the cluster ID and a UTC timestamp in the auto-generated must-gather destination directory name
  • Helps support engineers distinguish must-gather archives from different clusters and collection times when customers upload multiple archives to the same support case
  • Falls back gracefully if cluster ID is unavailable (e.g. cluster is unreachable)

New format: must-gather.local.<rand>.<cluster-id-suffix>.<timestamp>
Example: must-gather.local.5119224030749742202.76708af6b91c.20260413T141030Z

Fallback (cluster unreachable): must-gather.local.<rand>.<timestamp>

Details

The change is in Complete() within pkg/cli/admin/mustgather/mustgather.go. A new generateDestDir() method:

  1. Queries ClusterVersion "version" via the existing ConfigClient to retrieve Spec.ClusterID
  2. Extracts the last 12 characters of the UUID (low collision probability per UUID substring analysis)
  3. Appends a UTC timestamp in compact ISO 8601 format (20060102T150405Z) — the Z suffix avoids timezone ambiguity
  4. Falls back to must-gather.local.<rand>.<timestamp> if ClusterVersion is unreachable

No new CLI flags are introduced — the consensus in the RFE discussion was to change the default naming rather than adding an opt-in option.

Test plan

  • Unit tests added for generateDestDir() covering: full cluster ID, short cluster ID, empty cluster ID, nil ConfigClient
  • All existing mustgather package tests pass (24/24)
  • Manual validation on a live cluster: oc adm must-gather produces directory with cluster ID suffix and timestamp
  • Manual validation with --dest-dir flag: custom directory name is still respected (no change in behavior)
  • Manual validation with unreachable cluster: directory falls back to must-gather.local.<rand>.<timestamp>

See: https://issues.redhat.com/browse/RFE-5434

Summary by CodeRabbit

  • New Features

  • Enhanced must-gather destination naming to include a cluster identifier suffix (when available), a UTC timestamp, and a random suffix for clearer artifact organization and traceability.

  • Keeps a fallback naming format when cluster metadata is unavailable.

  • Tests

  • Added deterministic tests validating the new naming semantics, timestamp format, cluster-ID handling, and behavior when no cluster metadata/client is present.

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.

@tchap
Copy link
Copy Markdown
Contributor

tchap commented Apr 20, 2026

/ok-to-test
/lgtm

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 20, 2026
@tchap
Copy link
Copy Markdown
Contributor

tchap commented Apr 20, 2026

/label tide/merge-method-squash

@openshift-ci openshift-ci bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Apr 20, 2026
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 20, 2026
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

🧹 Nitpick comments (1)
pkg/cli/admin/mustgather/mustgather.go (1)

272-285: Godoc comment is attached to the wrong function.

The doc block on lines 272–276 describes generateDestDir but is placed immediately above getClock(), making it the godoc for getClock. The stray // See: https://issues.redhat.com/browse/RFE-5434 at line 284 is what ends up attached to generateDestDir. Move the descriptive comment down to generateDestDir and add a short godoc on getClock.

✏️ Proposed fix
-// generateDestDir builds the default destination directory name for must-gather output.
-// The format includes a partial cluster ID (last 12 characters), a UTC timestamp, and a
-// random ID to help distinguish must-gather archives from different clusters and collection
-// times. If the cluster ID cannot be retrieved (e.g. cluster is unreachable), it falls back
-// to the timestamp and random ID only.
+// getClock returns the injected PassiveClock, defaulting to clock.RealClock{} when unset.
 func (o *MustGatherOptions) getClock() clock.PassiveClock {
 	if o.clock != nil {
 		return o.clock
 	}
 	return clock.RealClock{}
 }
 
-// See: https://issues.redhat.com/browse/RFE-5434
+// generateDestDir builds the default destination directory name for must-gather output.
+// The format includes a partial cluster ID (last 12 characters), a UTC timestamp, and a
+// random ID to help distinguish must-gather archives from different clusters and collection
+// times. If the cluster ID cannot be retrieved (e.g. cluster is unreachable), it falls back
+// to the timestamp and random ID only.
+// See: https://issues.redhat.com/browse/RFE-5434
 func (o *MustGatherOptions) generateDestDir(ctx context.Context) string {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/cli/admin/mustgather/mustgather.go` around lines 272 - 285, The long doc
comment that describes generateDestDir is currently placed above getClock, so
move the descriptive block (the lines explaining the destination directory
format and fallback behavior) down so it immediately precedes generateDestDir;
then replace that moved comment's original location with a short godoc for
getClock (e.g., "getClock returns the configured clock or the real clock") so
getClock has its own concise documentation and generateDestDir retains the
detailed explanation and the existing "See: ..." line.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/cli/admin/mustgather/mustgather.go`:
- Around line 44-46: The import block in mustgather.go has unsorted imports
causing gofmt/verify to fail; reorder the two k8s.io/utils imports so
"k8s.io/utils/clock" comes before "k8s.io/utils/exec" (i.e., update the import
list containing "k8s.io/utils/exec", "k8s.io/utils/clock", and utilptr
"k8s.io/utils/ptr" to follow alphabetical order) and run gofmt/verify to ensure
the import ordering is correct.

---

Nitpick comments:
In `@pkg/cli/admin/mustgather/mustgather.go`:
- Around line 272-285: The long doc comment that describes generateDestDir is
currently placed above getClock, so move the descriptive block (the lines
explaining the destination directory format and fallback behavior) down so it
immediately precedes generateDestDir; then replace that moved comment's original
location with a short godoc for getClock (e.g., "getClock returns the configured
clock or the real clock") so getClock has its own concise documentation and
generateDestDir retains the detailed explanation and the existing "See: ..."
line.
🪄 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: 4790b8f8-9ca1-4b21-b81a-68f40bf1c04b

📥 Commits

Reviewing files that changed from the base of the PR and between 67a47be and 6483683.

📒 Files selected for processing (2)
  • pkg/cli/admin/mustgather/mustgather.go
  • pkg/cli/admin/mustgather/mustgather_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/cli/admin/mustgather/mustgather_test.go

Comment thread pkg/cli/admin/mustgather/mustgather.go Outdated
@tchap
Copy link
Copy Markdown
Contributor

tchap commented Apr 20, 2026

/lgtm cancel

Please fix the import ordering as mentioned by CodeRabbit.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 20, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 20, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@asadawar
Copy link
Copy Markdown
Author

Fixed the import ordering. Ready for another look.

@tchap
Copy link
Copy Markdown
Contributor

tchap commented Apr 20, 2026

Let me wait for CI, I will tag this when it seems ok.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 20, 2026

@asadawar: 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/verify 2d3c35a link true /test verify

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

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants