Skip to content

MG-271: Implement standard must-gather directory naming convention#364

Open
neha037 wants to merge 10 commits into
openshift:masterfrom
neha037:feature/mg-271
Open

MG-271: Implement standard must-gather directory naming convention#364
neha037 wants to merge 10 commits into
openshift:masterfrom
neha037:feature/mg-271

Conversation

@neha037

@neha037 neha037 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements standard must-gather directory naming convention to align with oc adm must-gather, ensuring consistency across all must-gather collection methods.

Changes

Implementation

  • New: pkg/mustgatherutil/directory_naming.go - Directory name generation utility
    • GenerateMustGatherDirectoryName(): Generates directory names following the oc adm must-gather convention
    • getClusterIDSuffix(): Retrieves last 12 characters of cluster ID from ClusterVersion resource
    • generateRandomSuffix(): Generates 6-digit random suffix for uniqueness
  • Modified: controllers/mustgather/mustgather_controller.go - Calls mustgatherutil.GenerateMustGatherDirectoryName() before job creation
  • Modified: controllers/mustgather/template.go - Passes directory name to gather container via MUST_GATHER_DEST_DIR environment variable

Tests

  • New: pkg/mustgatherutil/directory_naming_test.go
    • Directory naming with/without cluster ID
    • Format validation (timestamp YYYYMMDDTHHMMSSZ, random 6 digits)
    • Uniqueness testing (100 concurrent runs)
    • UTC timezone conversion tests
    • Cluster ID suffix extraction edge cases
  • New: controllers/mustgather/mustgather_controller_test.go - Tests for directory name integration in job creation
  • Modified: controllers/mustgather/template_test.go - Updated test calls to include directory name parameter
  • New: test/e2e/must_gather_operator_test.go - E2E tests for directory naming behavior

Directory Naming Format

With Cluster ID (default)

must-gather.local.<cluster-id-suffix>.<timestamp>.<random>

Example: must-gather.local.ef0123456789.20260617T143025Z.042315

Without Cluster ID (fallback)

must-gather.local.<timestamp>.<random>

Example: must-gather.local.20260617T143025Z.042315

Where:

  • cluster-id-suffix: Last 12 characters of cluster ID from clusterversion.config.openshift.io/version
  • timestamp: UTC timestamp in format YYYYMMDDTHHMMSSZ
  • random: 6-digit random number (000000-999999)

RBAC

RBAC for ClusterVersion access is already present:

//+kubebuilder:rbac:groups=config.openshift.io,resources=clusterversions,verbs=get;list;watch

Testing

Unit Tests

go test ./pkg/mustgatherutil/... ./controllers/mustgather/... -v
  • TestGenerateMustGatherDirectoryName - Format validation with/without cluster ID (9 sub-tests)
  • TestGenerateMustGatherDirectoryName_Uniqueness - Uniqueness across 100 runs
  • TestGenerateMustGatherDirectoryName_UTCConversion - Timezone handling (3 sub-tests)
  • TestGetClusterIDSuffix_WrongClusterVersionName - Fallback when ClusterVersion name doesn't match

E2E Tests

go test ./test/e2e/... -v

Verification

go build ./...        # ✅ Builds successfully
go test ./...         # ✅ All tests pass

Additional Notes

  • Backward Compatibility: This is a breaking change in directory naming, but acceptable as documented behavior change. No API changes.
  • Fallback Behavior: Gracefully handles scenarios where cluster ID is unavailable (permissions, missing resource)
  • No API Changes: Implementation is transparent to users - no changes to MustGather CRD

Implements

Jira: MG-271 - Change must-gather directory name in must-gather-operator

Acceptance Criteria

  • ✅ Directory naming convention is consistent across oc adm mustgather
  • ✅ Add relevant UT and E2E

🤖 Generated with Claude Code

neha037 and others added 2 commits June 17, 2026 11:18
This change aligns the must-gather-operator with the oc adm must-gather
directory naming convention for consistency across collection methods.

Changes:
- Add generateMustGatherDirectoryName() to create directory names following
  the pattern: must-gather.local.<cluster-id-suffix>.<timestamp>.<random>
- Retrieve cluster ID from ClusterVersion resource (last 12 characters)
- Fallback to timestamp+random format if cluster ID unavailable
- Pass generated directory name to gather container via MUST_GATHER_DEST_DIR env var
- Add comprehensive unit tests for directory name generation

Implements: MG-271

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Code review verdict: Approved (9/10)
- All acceptance criteria met
- Comprehensive unit tests (426 lines)
- RBAC properly configured
- No critical issues found

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

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
ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 35ee4897-0935-4c70-809f-18671634b4c8

📥 Commits

Reviewing files that changed from the base of the PR and between e65f61a and 79853bd.

📒 Files selected for processing (7)
  • controllers/mustgather/mustgather_controller.go
  • controllers/mustgather/mustgather_controller_test.go
  • controllers/mustgather/template.go
  • controllers/mustgather/template_test.go
  • pkg/mustgatherutil/directory_naming.go
  • pkg/mustgatherutil/directory_naming_test.go
  • test/e2e/must_gather_operator_test.go

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting


Walkthrough

This PR adds must-gather destination directory generation, passes it into the gather container as MUST_GATHER_DEST_DIR, and updates reconciliation to generate it only for new Jobs while reusing the existing Job for status handling. Unit and e2e tests cover the new naming and injection behavior.

Changes

Must-gather directory naming feature

Layer / File(s) Summary
Directory name utility
pkg/mustgatherutil/directory_naming.go, pkg/mustgatherutil/directory_naming_test.go
Adds GenerateMustGatherDirectoryName, helper suffix generation, and tests for format, uniqueness, UTC conversion, and ClusterVersion lookup behavior.
Template env var injection
controllers/mustgather/template.go, controllers/mustgather/template_test.go
Adds MUST_GATHER_DEST_DIR support to the gather container, threads a directoryName parameter through template construction, and updates tests to validate the new env var behavior.
Controller reconcile path
controllers/mustgather/mustgather_controller.go, controllers/mustgather/mustgather_controller_test.go
Fetches existingJob first, generates a directory name only for new Jobs, uses existingJob for status evaluation, and adds reconcile tests for creation and re-reconcile behavior.
E2E validation
test/e2e/must_gather_operator_test.go
Adds end-to-end checks for the generated directory name format and uniqueness across separate MustGather runs.

Estimated code review effort: 3 (Moderate) | ~30 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
No-Sensitive-Data-In-Logs ❌ Error Line 49 logs raw error with "error", err which exposes cluster metadata and API details. Suggested fix: remove the "error", err parameters to log only the safe message. Remove "error", err from line 49: log.V(2).Info("Unable to retrieve cluster ID, continuing without it")
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Ipv6 And Disconnected Network Test Compatibility ⚠️ Warning PR adds Ginkgo e2e tests with external connectivity requirements: hardcoded quay.io/kubevirt image and sftp.access.redhat.com connectivity that will fail in IPv6-only disconnected CI environments. Add [Skipped:Disconnected] to test names requiring external connectivity; use cluster-internal image streams for container images instead of quay.io.
Test Structure And Quality ❓ Inconclusive The custom check explicitly instructs to review "Ginkgo test code," but the PR adds standard Go unit tests (testing.T), not Ginkgo tests. The check criteria are Ginkgo-specific (Describe/Context/It... Clarify whether the check applies to standard Go tests (testing.T) in the controllers/mustgather package or only to Ginkgo-based E2E tests in test/e2e/.
✅ 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 'MG-271: Implement standard must-gather directory naming convention' clearly and specifically summarizes the main change—implementing a standard directory naming convention for must-gather operations, which is the primary objective of this PR.
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 PR contains only Go standard library testing (testing.T), not Ginkgo tests. Custom check targets Ginkgo frameworks and is not applicable here.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests are added in this PR. All new tests use Go's standard testing package. E2E test artifacts mentioned in PR description are generated for a future follow-up PR.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests were added in this PR. The PR adds unit tests in controllers/mustgather/directory_naming_test.go (standard Go testing package, not Ginkgo), and mentions E2E artifacts as c...
Topology-Aware Scheduling Compatibility ✅ Passed This PR introduces no new topology-breaking scheduling constraints. Changes are limited to directory name generation utilities and environment variable passing. Pre-existing preferred affinity for...
Ote Binary Stdout Contract ✅ Passed No process-level stdout writes found. Code uses logr/zap logger configured to write to stderr by default; no direct fmt.Print or os.Stdout calls present.
No-Weak-Crypto ✅ Passed No weak cryptographic algorithms (MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB) or non-constant-time secret comparisons found. Code uses math/rand for directory naming (non-security-sensitive), validat...
Container-Privileges ✅ Passed PR adds directory naming logic without introducing privileged containers, hostPID/Network/IPC, SYS_ADMIN capabilities, or allowPrivilegeEscalation settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci openshift-ci Bot requested review from devppratik and dustman9000 June 17, 2026 06:36
@openshift-ci

openshift-ci Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@neha037 neha037 marked this pull request as draft June 17, 2026 06:41
@codecov-commenter

codecov-commenter commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.81%. Comparing base (e65f61a) to head (79853bd).
⚠️ Report is 1 commits behind head on master.

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #364      +/-   ##
==========================================
+ Coverage   82.32%   82.81%   +0.49%     
==========================================
  Files           8        9       +1     
  Lines         905      931      +26     
==========================================
+ Hits          745      771      +26     
  Misses        148      148              
  Partials       12       12              
Files with missing lines Coverage Δ
controllers/mustgather/template.go 100.00% <100.00%> (ø)
pkg/mustgatherutil/directory_naming.go 100.00% <100.00%> (ø)
controllers/mustgather/mustgather_controller.go 94.01% <90.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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 Jun 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
controllers/mustgather/template_test.go (1)

219-219: ⚡ Quick win

Add assertions for MUST_GATHER_DEST_DIR in the updated tests.

These tests pass a directory name but never verify gatherEnvDestDir is emitted, so the new wiring can break without test failure.

🔧 Suggested additions
-			container := getGatherContainer(tt.mustGatherImage, tt.audit, tt.timeout, tt.storage, tt.caConfigMap, tt.timeFilter, tt.command, tt.args, "must-gather.local.test.20240101T120000Z.000001")
+			expectedDir := "must-gather.local.test.20240101T120000Z.000001"
+			container := getGatherContainer(tt.mustGatherImage, tt.audit, tt.timeout, tt.storage, tt.caConfigMap, tt.timeFilter, tt.command, tt.args, expectedDir)
+			envMap := envValues(container)
+			if envMap[gatherEnvDestDir] != expectedDir {
+				t.Fatalf("expected %s=%s, got %s", gatherEnvDestDir, expectedDir, envMap[gatherEnvDestDir])
+			}
-			job := getJobTemplate("img", "operator-image", mg, "", "must-gather.local.test.20240101T120000Z.000001")
+			expectedDir := "must-gather.local.test.20240101T120000Z.000001"
+			job := getJobTemplate("img", "operator-image", mg, "", expectedDir)
 			gather := findGatherContainerInJob(t, job)
 			got := envValues(gather)
+			if got[gatherEnvDestDir] != expectedDir {
+				t.Fatalf("expected %s=%s, got %s", gatherEnvDestDir, expectedDir, got[gatherEnvDestDir])
+			}

Also applies to: 592-592, 678-678

🤖 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/template_test.go` at line 219, The tests call
getGatherContainer with a directory name parameter but do not verify that the
MUST_GATHER_DEST_DIR environment variable (gatherEnvDestDir) is properly set in
the returned container. Add assertions in the test cases at lines 219, 592, and
678 to verify that the container environment includes the correct
gatherEnvDestDir value matching the directory name passed to getGatherContainer,
ensuring the new wiring cannot break without test failures.
🤖 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/directory_naming_test.go`:
- Line 107: The `configv1.Install(scheme)` function calls at lines 107, 195,
300, and 370 are discarding their error return values using blank identifier
assignment. Instead of ignoring these errors, check the error return value from
each `configv1.Install(scheme)` call and fail the test immediately with a clear
error message if installation fails, ensuring proper test setup validation
before continuing with test execution.

In `@controllers/mustgather/directory_naming.go`:
- Line 72: The log.V(1).Info call in directory_naming.go logs the full
directoryName which contains the cluster ID suffix and exposes
customer-identifying metadata. Remove the "directoryName", dirName parameters
from the log statement, keeping only the non-sensitive "hasClusterID" parameter
to prevent exposing cluster-identifying data in operator logs.

---

Nitpick comments:
In `@controllers/mustgather/template_test.go`:
- Line 219: The tests call getGatherContainer with a directory name parameter
but do not verify that the MUST_GATHER_DEST_DIR environment variable
(gatherEnvDestDir) is properly set in the returned container. Add assertions in
the test cases at lines 219, 592, and 678 to verify that the container
environment includes the correct gatherEnvDestDir value matching the directory
name passed to getGatherContainer, ensuring the new wiring cannot break without
test failures.
🪄 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: 16271d96-ec22-431e-9bb3-b23cc5aa0346

📥 Commits

Reviewing files that changed from the base of the PR and between e65f61a and 2509c51.

📒 Files selected for processing (6)
  • controllers/mustgather/directory_naming.go
  • controllers/mustgather/directory_naming_test.go
  • controllers/mustgather/mustgather_controller.go
  • controllers/mustgather/template.go
  • controllers/mustgather/template_test.go
  • review-report-MG-271.json

Comment thread controllers/mustgather/directory_naming_test.go Outdated
Comment thread controllers/mustgather/directory_naming.go Outdated
@neha037 neha037 changed the title feat(MG-271): Implement standard must-gather directory naming convention MG-271: Implement standard must-gather directory naming convention Jun 17, 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 Jun 17, 2026
@openshift-ci-robot

openshift-ci-robot commented Jun 17, 2026

Copy link
Copy Markdown

@neha037: This pull request references MG-271 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 story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

Implements standard must-gather directory naming convention to align with oc adm must-gather, ensuring consistency across all must-gather collection methods.

Changes

Implementation

  • New: controllers/mustgather/directory_naming.go - Directory name generation logic
  • generateMustGatherDirectoryName(): Generates directory names following the oc adm must-gather convention
  • getClusterIDSuffix(): Retrieves last 12 characters of cluster ID from ClusterVersion resource
  • generateRandomSuffix(): Generates 6-digit random suffix for uniqueness
  • Modified: controllers/mustgather/mustgather_controller.go - Calls directory name generator before job creation
  • Modified: controllers/mustgather/template.go - Passes directory name to gather container via MUST_GATHER_DEST_DIR environment variable

Tests

  • New: controllers/mustgather/directory_naming_test.go (426 lines)
  • Directory naming with/without cluster ID
  • Format validation (timestamp YYYYMMDDTHHMMSSZ, random 6 digits)
  • Uniqueness testing (100 concurrent runs)
  • Cluster ID suffix extraction tests
  • Modified: controllers/mustgather/template_test.go - Updated test calls to include directory name parameter

Documentation

  • New: review-report-MG-271.json - Comprehensive code review report (Approved: 9/10)

Directory Naming Format

With Cluster ID (default)

must-gather.local.<cluster-id-suffix>.<timestamp>.<random>

Example: must-gather.local.ef0123456789.20260617T143025Z.042315

Without Cluster ID (fallback)

must-gather.local.<timestamp>.<random>

Example: must-gather.local.20260617T143025Z.042315

Where:

  • cluster-id-suffix: Last 12 characters of cluster ID from clusterversion.config.openshift.io/version
  • timestamp: UTC timestamp in format YYYYMMDDTHHMMSSZ
  • random: 6-digit random number (000000-999999)

RBAC

RBAC for ClusterVersion access is already present:

//+kubebuilder:rbac:groups=config.openshift.io,resources=clusterversions,verbs=get;list;watch

Testing

Unit Tests (✅ Complete)

go test ./controllers/mustgather -v -run "TestGenerate|TestGetClusterIDSuffix|TestDirectoryNameFormat"

All tests pass:

  • TestGenerateMustGatherDirectoryName - Format validation with/without cluster ID
  • TestGenerateMustGatherDirectoryName_Uniqueness - Uniqueness across 100 runs
  • TestGetClusterIDSuffix - Cluster ID extraction
  • TestGenerateRandomSuffix - Random suffix format
  • TestDirectoryNameFormat - Comprehensive format validation

E2E Tests (📝 Generated, ready for follow-up)

E2E test artifacts generated in output/e2e_must-gather-operator/:

  • test-cases.md - Comprehensive test scenarios
  • execution-steps.md - Step-by-step execution guide
  • e2e_test.go - Ginkgo-based E2E tests
  • e2e-suggestions.md - Test recommendations

Can be added to test/e2e/ in a follow-up PR.

Verification

Build

go build ./controllers/mustgather

✅ Builds successfully

Tests

go test ./controllers/mustgather

✅ All tests pass (existing + new)

Code Review

Verdict: ✅ Approved (9/10)

Module Review Results

  • Golang Logic & Safety: ✅ PASSED
  • Intent matches Jira acceptance criteria
  • Proper context handling (no context.TODO())
  • Correct error wrapping with %w
  • Edge cases handled (empty/short cluster IDs, permission errors)
  • Scheme registration verified (configv1 already in main.go)
  • Operator Metadata (OLM): ✅ PASSED
  • RBAC markers present for config.openshift.io/clusterversions
  • Three-way consistency verified (marker & CSV)
  • Build Consistency: ✅ PASSED
  • Dependencies complete
  • No generation drift

Full review: review-report-MG-271.json

Implements

Jira: MG-271 - Change must-gather directory name in must-gather-operator

Acceptance Criteria

  • ✅ Directory naming convention is consistent across oc adm mustgather
  • ✅ Add relevant UT and E2E

Additional Notes

  • Backward Compatibility: This is a breaking change in directory naming, but acceptable as documented behavior change. No API changes.
  • Fallback Behavior: Gracefully handles scenarios where cluster ID is unavailable (permissions, missing resource)
  • No API Changes: Implementation is transparent to users - no changes to MustGather CRD

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

  • Must-gather now generates uniquely formatted destination directory names following oc adm must-gather conventions, incorporating timestamp, random suffix, and optional cluster identification.

  • Tests

  • Added comprehensive coverage for directory name generation, formatting, uniqueness, and cluster ID suffix derivation, including error/edge cases.

  • Chores

  • Added internal structured review report documentation for the change.

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 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
controllers/mustgather/directory_naming.go (1)

54-58: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid logging raw cluster ID retrieval errors.

Line 57 logs the full err, which can leak internal API endpoints/hostnames from client-go error text. Log a sanitized reason/classification instead of the raw error payload.

🔧 Suggested change
-		log.V(2).Info("Unable to retrieve cluster ID, continuing without it", "error", err)
+		var reason string
+		switch {
+		case errors.IsNotFound(err):
+			reason = "not_found"
+		case errors.IsForbidden(err):
+			reason = "forbidden"
+		default:
+			reason = "lookup_failed"
+		}
+		log.V(2).Info("Unable to retrieve cluster ID, continuing without it", "reason", reason)

As per coding guidelines, **/*.{go,py,sh,bash,java,js,ts,c,cpp}: "Flag logging that may expose ... internal hostnames, or customer data".

🤖 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/directory_naming.go` around lines 54 - 58, The error
logging in the cluster ID retrieval error handling block is logging the raw err
value directly, which can expose internal API endpoints or hostnames from
client-go error messages. Replace the "error", err parameter in the
log.V(2).Info call with a sanitized classification or reason string that
describes the type of error without exposing internal details. For example,
instead of passing the raw err, classify it as a generic reason like
"cluster_id_unavailable" or similar that indicates the failure type without
revealing sensitive infrastructure information.

Source: Coding guidelines

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

Outside diff comments:
In `@controllers/mustgather/directory_naming.go`:
- Around line 54-58: The error logging in the cluster ID retrieval error
handling block is logging the raw err value directly, which can expose internal
API endpoints or hostnames from client-go error messages. Replace the "error",
err parameter in the log.V(2).Info call with a sanitized classification or
reason string that describes the type of error without exposing internal
details. For example, instead of passing the raw err, classify it as a generic
reason like "cluster_id_unavailable" or similar that indicates the failure type
without revealing sensitive infrastructure information.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 83a413cb-4faa-4e3c-ac93-3e35b2c6f0d3

📥 Commits

Reviewing files that changed from the base of the PR and between 2509c51 and 1d73180.

📒 Files selected for processing (1)
  • controllers/mustgather/directory_naming.go

@neha037

neha037 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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/directory_naming.go`:
- Around line 42-43: The random number generation in the directory naming logic
uses rand.Int63() which can produce up to 19 digits, but the format specifier
%06d only sets a minimum width, not a maximum, resulting in inconsistent
directory name lengths. Replace the rand.Int63() call (around line 95) with
rand.Intn(1_000_000) to ensure the random component is limited to exactly 6
digits when formatted. This will maintain the correct directory naming format of
must-gather.local.<random>.<cluster-id-suffix>.<timestamp> with consistent
6-digit random values.

In `@controllers/mustgather/mustgather_controller.go`:
- Around line 201-202: The reqLogger.Error call is logging the full instance
object which may expose customer metadata. Replace the instance parameter in the
error logging statement with a stable identifier such as instance.Name,
instance.Namespace, or another unique identifier that does not expose sensitive
customer data. This ensures the log message provides necessary debugging context
while maintaining security and privacy standards.
🪄 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: 4a8e9a23-b963-4d6f-a3dd-8fff2d950ae6

📥 Commits

Reviewing files that changed from the base of the PR and between 10049db and 761cf94.

📒 Files selected for processing (3)
  • controllers/mustgather/directory_naming.go
  • controllers/mustgather/directory_naming_test.go
  • controllers/mustgather/mustgather_controller.go

Comment thread controllers/mustgather/directory_naming.go Outdated
Comment thread controllers/mustgather/mustgather_controller.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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/directory_naming.go`:
- Line 49: In the log.V(2).Info call on line 49 of directory_naming.go, the raw
error object is being logged as the "error" field, which may expose sensitive
internal cluster metadata and violates security guidelines. Remove the "error",
err parameters from the log statement to use only the sanitized message "Unable
to retrieve cluster ID, continuing without it" without including the raw error
payload.
🪄 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: d4233e81-0e8b-477e-bf63-c325a6d53075

📥 Commits

Reviewing files that changed from the base of the PR and between 761cf94 and 077af09.

📒 Files selected for processing (3)
  • controllers/mustgather/directory_naming.go
  • controllers/mustgather/directory_naming_test.go
  • controllers/mustgather/mustgather_controller.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • controllers/mustgather/mustgather_controller.go
  • controllers/mustgather/directory_naming_test.go

Comment thread controllers/mustgather/directory_naming.go Outdated
@neha037

neha037 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@neha037

neha037 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@neha037

neha037 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@@ -176,31 +177,31 @@ func (r *MustGatherReconciler) Reconcile(ctx context.Context, request reconcile.
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the restructuring is done because

Old code (master) — built the job template before checking if the job already exists:
job := getJobFromInstance(...) // always runs — API calls, image lookup, etc.
job1 := client.Get(job.Name, ...) // then check if it exists
if not found → create

this branch — checks first, only builds if needed:
existingJob := client.Get(instance.Name, ...) // check first
if not found → job := getJobFromInstance(...) // only build when we need to create

getJobFromInstance now calls generateMustGatherDirectoryName, which makes an API call to fetch the ClusterVersion. On the old code path, that API call would happen on every reconcile — even when the job already exists and is running. With restructuring, the directory name generation (and the ClusterVersion lookup) only happens once, when actually creating the job.

The rename from job1 to existingJob is just a clarity

@neha037 neha037 marked this pull request as ready for review June 25, 2026 10:12
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 25, 2026
@openshift-ci openshift-ci Bot requested review from Tafhim and ravitri June 25, 2026 10:13
@neha037

neha037 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@neha037

neha037 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

/jira refresh

@openshift-ci-robot

openshift-ci-robot commented Jul 6, 2026

Copy link
Copy Markdown

@neha037: This pull request references MG-271 which is a valid jira issue.

Details

In response to this:

/jira refresh

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.

@neha037

neha037 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai summary

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
✅ Action performed

Summary regeneration triggered.

@neha037

neha037 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

/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 Jul 6, 2026
@openshift-ci

openshift-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@neha037: 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/validate-boilerplate 79853bd 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

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. 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