Skip to content

🌱 chore: adopt shared golangci-lint configuration from sdk-go#384

Merged
openshift-merge-bot[bot] merged 3 commits into
open-cluster-management-io:mainfrom
tesshuflower:adopt-sdk-go-lint
Jun 12, 2026
Merged

🌱 chore: adopt shared golangci-lint configuration from sdk-go#384
openshift-merge-bot[bot] merged 3 commits into
open-cluster-management-io:mainfrom
tesshuflower:adopt-sdk-go-lint

Conversation

@tesshuflower

@tesshuflower tesshuflower commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Adopts the shared golangci-lint configuration from sdk-go to standardize lint tooling across OCM repositories.

Similar to what was done for: open-cluster-management-io/cluster-proxy#279

Should hopefully simplify the move to golang 1.26 as we'll automatically get the correct linter version.

Changes

  • Makefile: Replace verify-gocilint target with lint target that remotely fetches and executes the shared run-lint.sh script from sdk-go, which auto-selects the correct golangci-lint version based on the project's Go version
  • Remove .golangci.yaml: Old v1 format config, incompatible with golangci-lint v2; the shared sdk-go config is used instead
  • Lint fixes across the codebase:
    • Fix import grouping (goimports) to properly separate open-cluster-management.io local imports from external packages
    • Remove deprecated rand.Seed() calls (not needed since Go 1.20)
    • Fix duplicate import of k8s.io/apiserver/pkg/server; use RunWithContext instead of deprecated Run
    • Replace deprecated k8s.io/utils/pointer with k8s.io/utils/ptr
    • Fix naming conventions (blockTlsCrtblockTLSCrt, existJsonPathsexistJSONPaths, etc.)
    • Add //nolint:revive for exported API names that cannot be renamed without breaking changes (JsonStructToValues, Index* functions)
    • Use _ for unused function parameters
    • Preallocate slices with known capacity
    • Fix spelling in comments

No Breaking Changes

All public API signatures, exported types, and function parameters remain unchanged. Naming convention fixes are only applied to unexported/local symbols.

Test plan

  • make lint passes with 0 issues
  • make test-unit passes

Summary by CodeRabbit

  • Chores

    • Updated linting configuration to use upstream Open Cluster Management Go SDK lint script via the Makefile.
    • Removed explicit random seed initialization from startup code.
    • Cleaned up import formatting and added linter directives across codebase.
  • Refactor

    • Improved code quality through variable naming standardization and performance optimizations.
    • Updated pointer utility dependencies and refactored conditional logic for maintainability.

@openshift-ci openshift-ci Bot requested review from qiujian16 and zhiweiyin318 June 11, 2026 19:06
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@tesshuflower, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 29 minutes and 20 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92c3870d-242c-454a-b681-cea2bdd7dcbf

📥 Commits

Reviewing files that changed from the base of the PR and between 80b622f and dafccb4.

📒 Files selected for processing (5)
  • Makefile
  • examples/helloworld_agent/agent.go
  • examples/helloworld_agent/cleanup_agent.go
  • examples/helloworld_helm/helloworld_helm.go
  • examples/helloworld_hosted/helloworld.go

Walkthrough

This PR consolidates multiple code quality improvements across the addon-framework: replaces local golangci-lint configuration with OCM SDK lint script, adds linter directives to suppress revive warnings on undocumented exported functions, removes deprecated Go random seeding and time imports, reorganizes all import blocks, migrates to newer Kubernetes utilities (k8s.io/utils/ptr and direct field access for Group/Resource), preallocates slices for performance, and refactors variable names and control flow for consistency and clarity.

Changes

Linting Compliance and Code Quality Updates

Layer / File(s) Summary
Linting infrastructure migration
Makefile
.golangci.yaml configuration file removed; Makefile updated to use OCM SDK lint script via `curl
Linter directives and unused parameter fixes
examples/helloworld_agent/*, examples/helloworld_helm/helloworld_helm.go, examples/helloworld_hosted/helloworld.go, pkg/addonfactory/helper.go, pkg/addonfactory/helm_agentaddon.go, pkg/addonfactory/template_agentaddon.go, pkg/index/index.go
Added //nolint:revive comments to exported functions and marked unused parameters as _ to suppress linter warnings.
Random seeding removal
cmd/example/helloworld/main.go, cmd/example/helloworld_helm/main.go, cmd/example/helloworld_hosted/main.go, pkg/cmd/factory/factory.go
Removed math/rand and time imports; eliminated rand.Seed(time.Now().UTC().UnixNano()) calls; updated factory signal handling to use genericapiserver.SetupSignalHandler() with RunWithContext(ctx).
Import block formatting
examples/helloworld/helloworld.go, examples/helloworld_agent/*, examples/helloworld_helm/helloworld_helm.go, examples/rbac/rbac.go, pkg/addonfactory/*, pkg/addonmanager/*, pkg/agent/*, pkg/index/index.go, pkg/utils/*
Added blank lines throughout import blocks to separate standard-library, Kubernetes, and third-party imports.
Kubernetes API migrations and preallocations
pkg/addonfactory/*, pkg/addonmanager/cloudevents/manager.go, pkg/addonmanager/controllers/addonconfig/controller.go, pkg/addonmanager/controllers/cmaconfig/controller.go, pkg/utils/permission.go, pkg/utils/probe_helper.go
Migrated from k8s.io/utils/pointer to k8s.io/utils/ptr; replaced ConfigGroupResource.Group/Resource field access with direct Group/Resource fields; preallocated slices for configInformers and probeFields based on known capacity.
Variable naming and code simplification
examples/helloworld_helm/helloworld_helm.go, pkg/addonmanager/controllers/agentdeploy/utils.go, pkg/addonmanager/controllers/certificate/csrapprove.go, pkg/addonmanager/controllers/registration/controller.go, pkg/assets/template.go, pkg/index/index.go, pkg/utils/config_checker.go, pkg/utils/csr_helpers.go
Renamed variables for consistency (userJsonValuesuserJSONValues, existJsonPathsexistJSONPaths, blockTls*blockTLS*, ccc); refactored if/else if chains to switch statements; simplified isHook boolean expression; replaced strings.Replace(-1) with strings.ReplaceAll.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • open-cluster-management-io/addon-framework#356: Both PRs modify pkg/addonmanager/controllers/registration/controller.go by refactoring buildRegistrationConfigs to handle signer-specific subject logic (notably preserving/clearing subjects for the token driver and deriving defaults for CSR).

Suggested labels

lgtm, approved

Suggested reviewers

  • zhiweiyin318
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly identifies the main change: adopting a shared golangci-lint configuration from the sdk-go repository to standardize lint tooling. It accurately summarizes the primary objective.
Description check ✅ Passed The PR description comprehensively covers the main changes, provides context (reference to similar work in cluster-proxy), lists specific lint fixes applied, explicitly states no breaking changes, and includes a test plan. It follows the repository template structure.
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.

✏️ 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.

@tesshuflower tesshuflower changed the title chore: adopt shared golangci-lint configuration from sdk-go 🌱 chore: adopt shared golangci-lint configuration from sdk-go Jun 11, 2026
Replace the local golangci-lint v1 setup with the shared sdk-go lint
infrastructure. The shared run-lint.sh script auto-selects the correct
golangci-lint version based on the project Go version.

Changes:
- Makefile: replace verify-gocilint target with lint target using sdk-go run-lint.sh
- Remove .golangci.yaml (v1 format, incompatible with golangci-lint v2)
- Fix all 86 lint issues found by the stricter v2 linter:
  - goimports (40): separate open-cluster-management.io imports into local group
  - staticcheck (22): remove deprecated rand.Seed, fix duplicate imports,
    use RunWithContext, replace k8s.io/utils/pointer with k8s.io/utils/ptr
  - revive (14): fix naming conventions, add nolint for exported API names
  - prealloc (5): preallocate slices with known capacity
  - unparam (3): use _ for unused function parameters
  - misspell (2): fix spelling in comments

Part of ongoing standardization of lint tooling across OCM repositories.

Co-authored-by: Claude <claude@anthropic.com>
Signed-off-by: Tesshu Flower <tflower@redhat.com>

@mikeshng mikeshng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar to what was done for: #384

This is pointing at itself? Do you mean another PR?

/hold

Let's discuss. I think linting is less of an issue now days with AI. I rather not spend AI tokens on just getting the linting to pass. As long as it's reasonable it should be ok but shouldn't be super strict. As code are mostly generated by AI now days, it should be pretty linted already also.

@mikeshng

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 11, 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.

Copilot AI 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.

Pull request overview

This PR standardizes linting for this repository by adopting the shared golangci-lint v2 configuration and runner from open-cluster-management-io/sdk-go, and applies repo-wide mechanical updates needed to satisfy the new lint rules (import grouping, deprecation cleanups, minor naming tweaks, and small performance nits like slice preallocation).

Changes:

  • Replace the local golangci-lint setup with the shared sdk-go run-lint.sh runner via make lint and remove the legacy .golangci.yaml config.
  • Apply goimports-style import grouping updates across packages/examples to match the shared config.
  • Address linter findings (deprecated API usage, minor naming cleanups, preallocations, and a few small logic/style simplifications).

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Makefile Replaces local golangci-lint install/run with remote shared sdk-go runner via make lint.
.golangci.yaml Removes legacy v1-format golangci-lint configuration.
pkg/utils/probe_helper.go Preallocates probe field slices; goimports grouping.
pkg/utils/permission.go Switches from deprecated k8s.io/utils/pointer to k8s.io/utils/ptr.
pkg/utils/image.go goimports grouping.
pkg/utils/helpers.go goimports grouping.
pkg/utils/csr_helpers.go Renames Tls vars to TLS-style; goimports grouping.
pkg/utils/config_checker.go Receiver rename cleanup in Check; (comment spelling issue remains).
pkg/utils/addon_config.go goimports grouping.
pkg/index/index.go Adds //nolint:revive for exported API names; small simplification; goimports grouping.
pkg/cmd/factory/factory.go Removes rand.Seed, uses RunWithContext/SetupSignalHandler correctly; comment spelling tweak (“canceling”).
pkg/assets/template.go Replaces strings.Replace(..., -1) with strings.ReplaceAll.
pkg/agent/v1alpha1/interface.go goimports grouping.
pkg/agent/interface.go goimports grouping.
pkg/agent/adapter.go goimports grouping.
pkg/addonmanager/manager.go goimports grouping.
pkg/addonmanager/interface.go goimports grouping.
pkg/addonmanager/controllers/registration/controller.go Refactors driver selection to switch; goimports grouping.
pkg/addonmanager/controllers/cmamanagedby/controller.go goimports grouping.
pkg/addonmanager/controllers/cmaconfig/controller.go Slice prealloc; uses embedded Group/Resource fields; goimports grouping.
pkg/addonmanager/controllers/certificate/csrsign.go goimports grouping.
pkg/addonmanager/controllers/certificate/csrapprove.go Refactors condition checks to switch; goimports grouping.
pkg/addonmanager/controllers/agentdeploy/utils.go Naming cleanup (JSON); minor boolean init cleanup; goimports grouping.
pkg/addonmanager/controllers/agentdeploy/hosted_sync.go goimports grouping.
pkg/addonmanager/controllers/agentdeploy/hosted_hook_sync.go goimports grouping.
pkg/addonmanager/controllers/agentdeploy/healthcheck_sync.go Uses embedded Group/Resource fields; goimports grouping.
pkg/addonmanager/controllers/agentdeploy/default_sync.go goimports grouping.
pkg/addonmanager/controllers/agentdeploy/default_hook_sync.go goimports grouping.
pkg/addonmanager/controllers/agentdeploy/controller.go goimports grouping.
pkg/addonmanager/controllers/addonconfig/controller.go Slice prealloc; uses embedded Group/Resource fields; goimports grouping.
pkg/addonmanager/cloudevents/manager.go Slice prealloc; goimports grouping.
pkg/addonmanager/base_manager.go goimports grouping.
pkg/addonmanager/addontesting/helpers.go goimports grouping.
pkg/addonfactory/test_helper.go goimports grouping.
pkg/addonfactory/template_agentaddon.go Marks unused param; goimports grouping.
pkg/addonfactory/helper.go Adds //nolint:revive for exported API naming constraint.
pkg/addonfactory/helm_agentaddon.go Marks unused params; goimports grouping.
pkg/addonfactory/addonfactory.go goimports grouping.
pkg/addonfactory/addondeploymentconfig.go goimports grouping.
examples/rbac/rbac.go goimports grouping.
examples/helloworld/helloworld.go goimports grouping.
examples/helloworld_helm/helloworld_helm.go JSON naming cleanup; uses embedded Group/Resource fields; goimports grouping.
examples/helloworld_agent/cleanup_agent.go goimports grouping.
examples/helloworld_agent/agent.go goimports grouping.
cmd/example/helloworld/main.go Removes rand.Seed usage; goimports grouping.
cmd/example/helloworld_hosted/main.go Removes rand.Seed usage.
cmd/example/helloworld_helm/main.go Removes rand.Seed usage; goimports grouping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Makefile
Comment on lines +50 to +52
.PHONY: lint
lint:
@bash -o pipefail -c 'curl -fsSL https://raw.githubusercontent.com/open-cluster-management-io/sdk-go/main/ci/lint/run-lint.sh | bash'

@tesshuflower tesshuflower Jun 11, 2026

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.

This is just following the practice from other ocm repos and in fact does not get diferent golangci-lint versions each time, but specific ones that align with the go version used in go.mod.

The second part is actually a good point, I had used the cluster-proxy change as a reference, and it should have the same issue as it also has vendoring

Update: I think the default mode of readonly is ok even with vendoring: https://go.dev/ref/mod#go-mod-file-go

specifically:

At go 1.14 or higher, automatic vendoring may be enabled. If the file vendor/modules.txt is present and consistent with go.mod, there is no need to explicitly use the -mod=vendor flag.

Comment on lines 105 to +107
// Note that: configChecker performs a instant update after it returns err, so DO NOT use one
// configChecker for multible containers!!!
func (cc *configChecker) Check(_ *http.Request) error {
newChecksum, err := load(cc.configfiles)
func (c *configChecker) Check(_ *http.Request) error {
@tesshuflower

tesshuflower commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Similar to what was done for: #384

This is pointing at itself? Do you mean another PR?

/hold

Let's discuss. I think linting is less of an issue now days with AI. I rather not spend AI tokens on just getting the linting to pass. As long as it's reasonable it should be ok but shouldn't be super strict. As code are mostly generated by AI now days, it should be pretty linted already also.

oops, wrong link, it's this one: open-cluster-management-io/cluster-proxy#279

I disagree, think we should be doing linting, this can reduce AI tokens by getting easy linting fixes that AI doesn't always catch on its own, causing more reviews etc - This change is to use the common linting from sdk-go as other repos do - which will also help when moving to golang v1.26, as the common script from sdk-go picks up the correct version of golangci-lint.

To be clear, this is also not adding new linting, this is just moving the linter to download using a shared script from sdk-go instead of a hardcoded one in the Makefile (which we would need to keep up-to-date separately).

@mikeshng mikeshng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To be clear, this is also not adding new linting, this is just moving the linter to download using a shared script from sdk-go instead of a hardcoded one in the Makefile (which we would need to keep up-to-date separately).

Sounds good to me!

/unhold

/lgtm

@mikeshng

Copy link
Copy Markdown
Member

Thanks @tesshuflower

You will have to fix the linting error in the CI.

@openshift-ci openshift-ci Bot removed the lgtm label Jun 11, 2026
Signed-off-by: Tesshu Flower <tflower@redhat.com>

@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 `@Makefile`:
- Around line 50-54: The Makefile is missing a .PHONY declaration for the verify
target; add `.PHONY: verify` to the .PHONY list (or create a new .PHONY line
that includes verify) so that the verify target (which depends on lint) is
always treated as a phony target rather than a file, preventing make from
skipping it when a file named "verify" exists.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7248b7a1-ba9a-40ce-bb1d-0e3a4c4b10f1

📥 Commits

Reviewing files that changed from the base of the PR and between 929daf0 and 80b622f.

📒 Files selected for processing (48)
  • .golangci.yaml
  • Makefile
  • cmd/example/helloworld/main.go
  • cmd/example/helloworld_helm/main.go
  • cmd/example/helloworld_hosted/main.go
  • examples/helloworld/helloworld.go
  • examples/helloworld_agent/agent.go
  • examples/helloworld_agent/cleanup_agent.go
  • examples/helloworld_helm/helloworld_helm.go
  • examples/helloworld_hosted/helloworld.go
  • examples/rbac/rbac.go
  • pkg/addonfactory/addondeploymentconfig.go
  • pkg/addonfactory/addonfactory.go
  • pkg/addonfactory/helm_agentaddon.go
  • pkg/addonfactory/helper.go
  • pkg/addonfactory/template_agentaddon.go
  • pkg/addonfactory/test_helper.go
  • pkg/addonmanager/addontesting/helpers.go
  • pkg/addonmanager/base_manager.go
  • pkg/addonmanager/cloudevents/manager.go
  • pkg/addonmanager/controllers/addonconfig/controller.go
  • pkg/addonmanager/controllers/agentdeploy/controller.go
  • pkg/addonmanager/controllers/agentdeploy/default_hook_sync.go
  • pkg/addonmanager/controllers/agentdeploy/default_sync.go
  • pkg/addonmanager/controllers/agentdeploy/healthcheck_sync.go
  • pkg/addonmanager/controllers/agentdeploy/hosted_hook_sync.go
  • pkg/addonmanager/controllers/agentdeploy/hosted_sync.go
  • pkg/addonmanager/controllers/agentdeploy/utils.go
  • pkg/addonmanager/controllers/certificate/csrapprove.go
  • pkg/addonmanager/controllers/certificate/csrsign.go
  • pkg/addonmanager/controllers/cmaconfig/controller.go
  • pkg/addonmanager/controllers/cmamanagedby/controller.go
  • pkg/addonmanager/controllers/registration/controller.go
  • pkg/addonmanager/interface.go
  • pkg/addonmanager/manager.go
  • pkg/agent/adapter.go
  • pkg/agent/interface.go
  • pkg/agent/v1alpha1/interface.go
  • pkg/assets/template.go
  • pkg/cmd/factory/factory.go
  • pkg/index/index.go
  • pkg/utils/addon_config.go
  • pkg/utils/config_checker.go
  • pkg/utils/csr_helpers.go
  • pkg/utils/helpers.go
  • pkg/utils/image.go
  • pkg/utils/permission.go
  • pkg/utils/probe_helper.go
💤 Files with no reviewable changes (2)
  • .golangci.yaml
  • cmd/example/helloworld_hosted/main.go

Comment thread Makefile
Addresses CodeRabbit suggestion: without .PHONY: verify, make would
treat verify as a file target and silently skip it if a file named
'verify' existed in the directory.

Signed-off-by: Tesshu Flower <tflower@redhat.com>

@mikeshng mikeshng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci Bot added the lgtm label Jun 12, 2026
@qiujian16

Copy link
Copy Markdown
Member

/approve

@openshift-ci

openshift-ci Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mikeshng, qiujian16, tesshuflower

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot Bot merged commit 5017f37 into open-cluster-management-io:main Jun 12, 2026
15 checks passed
@tesshuflower tesshuflower deleted the adopt-sdk-go-lint branch June 12, 2026 13:05
@tesshuflower tesshuflower restored the adopt-sdk-go-lint branch June 15, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants