Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

HYPERFLEET-443 | Fix lint issues and enable 15/16 HyperFleet standard linters#5

Merged
xueli181114 merged 2 commits into
openshift-hyperfleet:mainfrom
tzhou5:fix-lint-issues
Jan 12, 2026
Merged

HYPERFLEET-443 | Fix lint issues and enable 15/16 HyperFleet standard linters#5
xueli181114 merged 2 commits into
openshift-hyperfleet:mainfrom
tzhou5:fix-lint-issues

Conversation

@tzhou5

@tzhou5 tzhou5 commented Jan 9, 2026

Copy link
Copy Markdown
Contributor
  • Fix errcheck: check os.Setenv return value in tests
  • Fix gosec G101/G115/G404: add nolint comments with explanations
  • Fix lll: break long lines to meet 120 char limit
  • Enable 15 of 16 required linters (revive temporarily disabled)
  • TODO: Enable revive after adding comments to exported symbols

Summary by CodeRabbit

  • Bug Fixes

    • Added configuration pre-validation to catch missing required environment variables early and surface clearer initialization errors.
  • Tests

    • Improved test environment setup for safer, isolated environment variable handling.
  • Chores

    • Updated linter and formatting configuration to align with project standards and enable additional quality checks.
  • Refactor

    • Minor internal refactors and logging message formatting changes with no behavioral impact.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 9, 2026

Copy link
Copy Markdown

Walkthrough

This PR updates .golangci.yml to enable most standard linters (including lll and gosec) while keeping revive disabled with explicit rule-exemptions and TODOs. It adds a validateConfig() pre-check to the pull-secret job to fail fast when required env vars (GCP_PROJECT_ID, CLUSTER_ID, SECRET_NAME, PULL_SECRET_DATA) are missing, adjusts test env setup to use t.Setenv, and applies formatting and //nolint annotations across several files. No public APIs or exported signatures were changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ciaranRoche
  • tirthct
  • yingzhanredhat
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
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.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: enabling 15/16 HyperFleet standard linters and fixing associated lint issues.

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

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2e792f and 0bd9f83.

📒 Files selected for processing (3)
  • .golangci.yml
  • cmd/pull-secret/jobs/pull_secret_test.go
  • cmd/pull-secret/main.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/pull-secret/jobs/pull_secret_test.go
  • .golangci.yml
🔇 Additional comments (1)
cmd/pull-secret/main.go (1)

23-23: LGTM! Concise nolint explanation.

The shortened comment maintains clarity while being more concise, appropriately explaining why ignoring the error from SetLogLevel is safe.


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

@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

Caution

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

⚠️ Outside diff range comments (1)
cmd/pull-secret/jobs/pull_secret_test.go (1)

268-278: Prefer t.Setenv over os.Clearenv()/os.Setenv() for test isolation.

The added os.Setenv error check is good, but os.Clearenv() is process-global and can become flaky if any tests in this package start using t.Parallel() later. Consider switching to t.Setenv(k, v) (and only setting the needed keys) instead of clearing the whole environment.

🤖 Fix all issues with AI agents
In @.golangci.yml:
- Around line 1-6: The header comment claiming "All 16 required linters enabled"
is inaccurate because the revive linter remains disabled (the revive entry in
.golangci.yml is set to disabled); either enable revive or update the header to
say "15 of 16 required linters enabled" (or similar) to match the actual
configuration—locate the revive config block and the top-of-file header comment
and change one of them so the comment and the revive setting are consistent.
🧹 Nitpick comments (2)
cmd/pull-secret/jobs/pull_secret.go (2)

20-22: //nolint:gosec (G101) on pullSecretTaskName looks unnecessary.

The string doesn’t look like a credential; if gosec is flagging it anyway and you want to keep the suppression, the justification comment is good.


349-366: Bound the exponential backoff + seed jitter to avoid overflow and synchronized retries.

1<<uint(i) is only safe while i is small; since maxRetries is a parameter, consider clamping the exponent and using a locally-seeded RNG for jitter so multiple pods don’t “randomly” retry in lockstep. This also lets you drop the gosec suppressions by construction.

Proposed diff (safer backoff + seeded jitter)
 func retryWithBackoff(ctx context.Context, fn func() error, maxRetries int) error {
 	var err error
+	// Seed once per call (low overhead at small maxRetries). Alternatively: package-level rand.New(...) seeded in init().
+	rng := rand.New(rand.NewSource(time.Now().UnixNano()))
 	for i := 0; i < maxRetries; i++ {
 		err = fn()
 		if err == nil {
 			return nil
 		}
@@
 		if i < maxRetries-1 {
 			// Calculate backoff with jitter (±20%)
-			//nolint:gosec // G115: i is bounded by maxRetries (small value)
-			baseBackoff := time.Duration(1<<uint(i)) * time.Second
+			// Clamp exponent to avoid overflow for large maxRetries.
+			exp := i
+			if exp > 30 {
+				exp = 30
+			}
+			baseBackoff := time.Duration(1<<uint(exp)) * time.Second
 			jitterRange := float64(baseBackoff) * 0.2
 			// Random value between -20% and +20% of base backoff
-			//nolint:gosec // G404: weak random is acceptable for jitter calculation
-			jitter := time.Duration((rand.Float64()*2 - 1) * jitterRange)
+			jitter := time.Duration((rng.Float64()*2 - 1) * jitterRange)
 			backoff := baseBackoff + jitter
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 812a509 and e2e792f.

📒 Files selected for processing (6)
  • .golangci.yml
  • cmd/pull-secret/jobs/pull_secret.go
  • cmd/pull-secret/jobs/pull_secret_test.go
  • cmd/pull-secret/main.go
  • pkg/job/job.go
  • pkg/job/metrics.go
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/job/job.go (1)
pkg/job/metrics.go (2)
  • MetricsReporter (10-12)
  • MetricsCollector (16-22)
🔇 Additional comments (11)
pkg/job/metrics.go (1)

61-65: LGTM!

The multi-line formatting improves readability while maintaining identical functionality. This aligns with the PR objective of meeting the 120-character line limit for the lll linter.

pkg/job/job.go (6)

100-106: LGTM!

Clean refactoring to an intermediate variable. This improves readability and complies with line length requirements without changing functionality.


210-213: LGTM!

Multi-line formatting for the panic logging call improves readability while maintaining identical behavior.


268-272: LGTM!

Consistent multi-line formatting applied to panic logging, matching the style used elsewhere in the file.


302-303: LGTM!

The nolint:gosec directive is appropriate here. The G115 warning concerns int-to-uint32 conversion, but task counts realistically won't exceed uint32 bounds in a job runner context. The inline explanation follows best practices for nolint annotations.


307-312: LGTM!

Multi-line struct initialization improves readability and meets line length requirements.


357-358: LGTM!

Consistent application of the nolint:gosec directive, matching the pattern used in jobRunner.Run. This maintains uniformity across both runner implementations.

cmd/pull-secret/main.go (1)

21-25: Double-check //nolint:errcheck is still recognized (nolintlint can be picky).

Putting //nolint:errcheck on its own line is usually fine, but if nolintlint is enabled it may enforce stricter placement/formatting. If you see “unused nolint directive”, move it to the end of the assignment line.

cmd/pull-secret/jobs/pull_secret.go (2)

93-96: Flag help string wrap is clean.


110-150: Logging line-break refactors look consistent and keep semantics intact.

Also applies to: 153-170, 203-229, 309-312

.golangci.yml (1)

5-6: There is no CI in this repository—golangci-lint runs locally only.

The config correctly declares version: "2" and uses v2-specific features like the formatters section. However, there are no GitHub Actions workflows, CI/CD pipelines, or any automated systems in the repository. The linting tool runs only when developers execute make lint locally. Developers with golangci-lint v1 installed will encounter errors with this config; document the required v1.61.0+ version in the Makefile or add a version check.

Likely an incorrect or invalid review comment.

Comment thread .golangci.yml
Comment thread .golangci.yml
Comment thread .golangci.yml
@xueli181114

Copy link
Copy Markdown
Contributor

/lgtm

@xueli181114 xueli181114 merged commit 21e0959 into openshift-hyperfleet:main Jan 12, 2026
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants