Skip to content

CNTRLPLANE-4008: feat: add hypershiftlinter golangci-lint plugin - #9237

Merged
openshift-merge-bot[bot] merged 6 commits into
openshift:mainfrom
bryan-cox:worktree-hypershiftlinter-plugin
Aug 17, 2026
Merged

CNTRLPLANE-4008: feat: add hypershiftlinter golangci-lint plugin#9237
openshift-merge-bot[bot] merged 6 commits into
openshift:mainfrom
bryan-cox:worktree-hypershiftlinter-plugin

Conversation

@bryan-cox

@bryan-cox bryan-cox commented Aug 6, 2026

Copy link
Copy Markdown
Member

What this PR does / why we need it:

Adds the hypershiftlinter golangci-lint v2 Go plugin: a framework plus 7 static-analysis analyzers that enforce test conventions from TESTING.md and test/e2e/v2/AGENTS.md. This PR introduces and unit-tests the analyzers only — it does not enable enforcement yet. Enablement (wiring into .golangci.yml/make lint) and the mechanical fix-up of existing violations are deferred to a follow-up PR (#9271) so that:

  • This PR can be reviewed/merged on its own smaller surface (plugin + analyzers + their tests).
  • hack/tools/hypershiftlinter.so and make test-linter land on main first, so the CI workflow that runs the analyzers' own unit tests (test-linter.yaml / test-linter-reusable.yaml) can actually execute on subsequent PRs — a brand-new reusable workflow can't get a green pre-merge run on the PR that introduces it, since GitHub resolves uses: ...@main and the pull_request trigger from the base branch.
  • The full "enable + fix all existing violations" change can be reviewed and rolled out separately in CNTRLPLANE-4008: enable hypershiftlinter and fix test naming #9271 without blocking this foundational plumbing.

Commit 1 — Vendor analysistest:

Promotes golang.org/x/tools from indirect to direct in hack/tools/go.mod and vendors the analysistest, checker, diff, testenv, and txtar packages needed by the analyzer test suites.

Commit 2 — Plugin framework:

plugin.go (BuildAnalyzers with optional enable list via settings) and cmd/plugin/main.go (golangci-lint plugin entry point). Builds as a Go shared library (.so) via go build -buildmode=plugin. Adds the hypershiftlinter.so build target, an opt-in hypershift-lint-all target, and a test-linter target to the Makefile. Does not touch make lint/lint-fix — enforcement is intentionally deferred to #9271.

Commit 3 — Analyzers:

7 analyzers split by scope:

  • TESTING.md (unit tests only): testcasename, testfuncname
  • AGENTS.md (test/e2e/v2/ only): guestcluster, contextbackground, vacuouspass, ipv6url, sippyannotation

Each analyzer has analysistest-based unit tests with good/bad testdata/ fixtures.

Commit 4 — CI workflows:

test-linter.yaml (caller, path-filtered to hack/tools/hypershiftlinter/**) and test-linter-reusable.yaml (runs make test-linter, i.e. go test ./hypershiftlinter/analyzers/...). Named Unit Tests (HyperShift Linter) to match the existing Unit Tests check naming convention. Also switches lint-reusable.yaml from copying pre-built runner-image tools to an actions/cache step keyed on Makefile + go.mod + go.sum + hypershiftlinter source, avoiding the version-mismatch failures that occur when the pre-built golangci-lint host binary and a source-built plugin disagree on golang.org/x/tools.

Which issue(s) this PR fixes:

Fixes CNTRLPLANE-4008

Special notes for your reviewer:

  • The plugin builds as a Go shared library (.so) via go build -buildmode=plugin. Plugin and golangci-lint host binary must be compiled from the same hack/tools/go.mod — a golang.org/x/tools version mismatch causes plugin.Open() to fail at runtime.
  • hypershiftlinter is not enabled in this PR — .golangci.yml and make lint are unchanged from main. make hypershift-lint-all exists as an opt-in target for manually running the analyzers against the current tree.
  • make test-linter runs the analyzers' own unit tests and passes locally with all 7 analyzer packages green.
  • Follow-up: #9271 enables the plugin in .golangci.yml/make lint and fixes all resulting test-naming violations. It depends on this PR merging first so hypershiftlinter.so exists.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • New Features

    • Added a HyperShift linter with checks for test naming, annotations, terminology, IPv6-safe URLs, context usage, and ineffective assertions.
    • Added commands to build, run, configure, and test the linter.
  • CI

    • Added automated linter test workflows and improved lint-tool caching.
  • Documentation

    • Added usage guidance, supported checks, build requirements, and rollout information.
  • Tests

    • Added coverage for all new linting rules and supported file patterns.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

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

openshift-ci Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci Bot added do-not-merge/needs-area needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: ce70db9f-f7bf-4b67-b4c9-a2343bc72396

📥 Commits

Reviewing files that changed from the base of the PR and between f4cfd7d and 91e3068.

⛔ Files ignored due to path filters (2)
  • hack/tools/hypershiftlinter/analyzers/contextbackground/testdata/src/test/e2e/v2/bad/bad_test.go is excluded by !**/testdata/**
  • hack/tools/hypershiftlinter/analyzers/contextbackground/testdata/src/test/e2e/v2/good/good_test.go is excluded by !**/testdata/**
📒 Files selected for processing (1)
  • hack/tools/hypershiftlinter/analyzers/contextbackground/contextbackground.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • hack/tools/hypershiftlinter/analyzers/contextbackground/contextbackground.go

📝 Walkthrough

Walkthrough

This change adds a golangci-lint plugin with seven analyzers for unit-test and v2 E2E test conventions. The plugin supports JSON analyzer selection and provides a golangci-lint entry point. Makefile targets build the plugin and run its tests. GitHub Actions runs linter tests on relevant pull requests and caches lint tools. Documentation describes the analyzers and commands.

Sequence Diagram(s)

sequenceDiagram
  participant PullRequest
  participant GitHubActions
  participant Makefile
  participant HypershiftLinterPlugin
  participant GolangCILint

  PullRequest->>GitHubActions: change linter-related paths
  GitHubActions->>Makefile: run make test-linter
  Makefile->>HypershiftLinterPlugin: execute analyzer tests
  Makefile->>HypershiftLinterPlugin: build plugin with CGO enabled
  GolangCILint->>HypershiftLinterPlugin: call New with settings
  HypershiftLinterPlugin-->>GolangCILint: return configured analyzers
Loading

Mergeability Score: ⚪ Minimal · up to 91e30

This change adds and tests an opt-in linting plugin without changing existing lint enforcement; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 11
✅ 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 clearly identifies the addition of the hypershiftlinter golangci-lint plugin, which is the main change.
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 Changed Ginkgo fixtures use static string titles only; no interpolated values, generated identifiers, IPs, timestamps, or changed production E2E test files were found.
Test Structure And Quality ✅ Passed All PR test paths are under hypershiftlinter; real tests use testing.T/analysistest, and Ginkgo-like fixtures are no-op analyzer inputs with no cluster operations or waits.
Topology-Aware Scheduling Compatibility ✅ Passed The PR adds Makefile/CI plumbing, Go analyzers, tests, and documentation; changed files contain no deployment, controller, operator, or Kubernetes scheduling constraints.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Added Ginkgo fixtures contain no IPv4 or external-network use; IPv4 literals occur only in non-Ginkgo static analyzer fixtures and are not runnable e2e tests.
No-Weak-Crypto ✅ Passed The PR diff adds no MD5, SHA1, DES, RC4, Blowfish, ECB, custom crypto, or secret/token comparisons; bytes.Equal only compares serialized analyzer facts.
Container-Privileges ✅ Passed The aggregate diff adds no container/Kubernetes manifest and no privileged, host namespace, SYS_ADMIN, allowPrivilegeEscalation, or root-user setting.
No-Sensitive-Data-In-Logs ✅ Passed The PR diff adds no logging of credentials, PII, internal hostnames, or customer data; its only log.Printf is a static IPv4 test fixture, and analyzer messages contain lint guidance.
✨ 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 added approved Indicates a PR has been approved by an approver from all required OWNERS files. area/ci-tooling Indicates the PR includes changes for CI or tooling area/cli Indicates the PR includes changes for CLI area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/control-plane-pki-operator Indicates the PR includes changes for the control plane PKI operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/platform/aws PR/issue for AWS (AWSPlatform) platform area/platform/azure PR/issue for Azure (AzurePlatform) platform area/platform/gcp PR/issue for GCP (GCPPlatform) platform area/platform/kubevirt PR/issue for KubeVirt (KubevirtPlatform) platform area/platform/none PR/issue for None (NonePlatform) platform - user-supplied infrastructure area/platform/openstack PR/issue for OpenStack (OpenStackPlatform) platform area/platform/powervs PR/issue for PowerVS (PowerVSPlatform) platform and removed do-not-merge/needs-area labels Aug 6, 2026
@bryan-cox
bryan-cox force-pushed the worktree-hypershiftlinter-plugin branch from 4d80587 to d2da990 Compare August 6, 2026 09:43
@openshift-ci openshift-ci Bot added area/api Indicates the PR includes changes for the API area/documentation Indicates the PR includes changes for documentation area/testing Indicates the PR includes changes for e2e testing and removed approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 6, 2026
@bryan-cox
bryan-cox force-pushed the worktree-hypershiftlinter-plugin branch from d2da990 to a2056a8 Compare August 6, 2026 09:43
@openshift-ci openshift-ci Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 6, 2026
@bryan-cox bryan-cox changed the title feat: add hypershiftlinter golangci-lint plugin fix(tests): align unit test naming with TESTING.md conventions Aug 6, 2026
@openshift-ci

openshift-ci Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bryan-cox

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-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 6, 2026
@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2026
…uite

Address review feedback on the hypershiftlinter analyzers:

- testcasename: looksLikeTestCaseMap now requires the value struct to
  declare at least one recognized test field, matching the corroboration
  looksLikeTestCaseStruct already applies. Plain lookup/fixture maps such
  as map[string]struct{ Addr string }{...} are no longer flagged.
- contextbackground: exempt AfterSuite alongside BeforeSuite and the
  Synchronized*Suite hooks, since it is the same suite-level teardown hook
  with no per-spec context.

Add testdata fixtures covering both cases.

Signed-off-by: Bryan Cox <brcox@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
Document why the plugin exists (machine-enforced test conventions), the
7 analyzers and their scopes, how the plugin is built and run, and the
intentionally staged rollout that lands the plugin and its tests before
enforcement is enabled.

Signed-off-by: Bryan Cox <brcox@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
@bryan-cox
bryan-cox force-pushed the worktree-hypershiftlinter-plugin branch from f4cfd7d to 91e3068 Compare August 13, 2026 18:22
@cblecker

Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2026
@bryan-cox

Copy link
Copy Markdown
Member Author

/verified later @bryan-cox

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws
/test e2e-v2-azure-self-managed
/test e2e-v2-gke

@openshift-ci-robot openshift-ci-robot added verified-later verified Signifies that the PR passed pre-merge verification criteria labels Aug 13, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@bryan-cox: This PR has been marked to be verified later by @bryan-cox.

Details

In response to this:

/verified later @bryan-cox

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.

@bryan-cox

Copy link
Copy Markdown
Member Author

/override ci/prow/e2e-aks
/override ci/prow/e2e-aws
/override ci/prow/e2e-aws-upgrade-hypershift-operator
/override ci/prow/e2e-kubevirt-aws-ovn-reduced
/override ci/prow/e2e-v2-aws
/override ci/prow/e2e-v2-azure-self-managed
/override ci/prow/e2e-v2-gke

@bryan-cox

Copy link
Copy Markdown
Member Author

Overrode e2e, this is just linter changes.

@openshift-ci

openshift-ci Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-aks, ci/prow/e2e-aws, ci/prow/e2e-aws-upgrade-hypershift-operator, ci/prow/e2e-kubevirt-aws-ovn-reduced, ci/prow/e2e-v2-aws, ci/prow/e2e-v2-azure-self-managed, ci/prow/e2e-v2-gke

Details

In response to this:

/override ci/prow/e2e-aks
/override ci/prow/e2e-aws
/override ci/prow/e2e-aws-upgrade-hypershift-operator
/override ci/prow/e2e-kubevirt-aws-ovn-reduced
/override ci/prow/e2e-v2-aws
/override ci/prow/e2e-v2-azure-self-managed
/override ci/prow/e2e-v2-gke

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.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD f7e85cc and 2 for PR HEAD 91e3068 in total

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD cd26599 and 1 for PR HEAD 91e3068 in total

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD ea98bde and 0 for PR HEAD 91e3068 in total

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/hold

Revision 91e3068 was retested 3 times: holding

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 14, 2026
@bryan-cox

Copy link
Copy Markdown
Member Author

/override "ci/prow/e2e-v2-azure-self-managed"
/override "ci/prow/e2e-kubevirt-aws-ovn-reduced"

These tests are failing outside this PR and these most recent failures are not from this PR. Moving this PR forward so I can work on enabling the linter and fixing the linter issues.

@bryan-cox

Copy link
Copy Markdown
Member Author

/hold cancel

@openshift-ci

openshift-ci Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-kubevirt-aws-ovn-reduced, ci/prow/e2e-v2-azure-self-managed

Details

In response to this:

/override "ci/prow/e2e-v2-azure-self-managed"
/override "ci/prow/e2e-kubevirt-aws-ovn-reduced"

These tests are failing outside this PR and these most recent failures are not from this PR. Moving this PR forward so I can work on enabling the linter and fixing the linter issues.

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.

@openshift-ci openshift-ci Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 17, 2026
@bryan-cox

Copy link
Copy Markdown
Member Author

/override "Red Hat Konflux / hypershift-operator-enterprise-contract / hypershift-operator-main"

@bryan-cox

Copy link
Copy Markdown
Member Author

/override "Red Hat Konflux / hypershift-operator-main-enterprise-contract / hypershift-operator-main"

@openshift-ci

openshift-ci Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

@bryan-cox: Overrode contexts on behalf of bryan-cox: Red Hat Konflux / hypershift-operator-enterprise-contract / hypershift-operator-main

Details

In response to this:

/override "Red Hat Konflux / hypershift-operator-enterprise-contract / hypershift-operator-main"

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.

@openshift-ci

openshift-ci Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

@bryan-cox: Overrode contexts on behalf of bryan-cox: Red Hat Konflux / hypershift-operator-main-enterprise-contract / hypershift-operator-main

Details

In response to this:

/override "Red Hat Konflux / hypershift-operator-main-enterprise-contract / hypershift-operator-main"

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.

@openshift-ci

openshift-ci Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

@bryan-cox: all tests passed!

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.

@openshift-merge-bot
openshift-merge-bot Bot merged commit 4f411bd into openshift:main Aug 17, 2026
50 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/api Indicates the PR includes changes for the API area/ci-tooling Indicates the PR includes changes for CI or tooling area/cli Indicates the PR includes changes for CLI area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/control-plane-pki-operator Indicates the PR includes changes for the control plane PKI operator - in an OCP release area/documentation Indicates the PR includes changes for documentation area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/platform/aws PR/issue for AWS (AWSPlatform) platform area/platform/azure PR/issue for Azure (AzurePlatform) platform area/platform/gcp PR/issue for GCP (GCPPlatform) platform area/platform/kubevirt PR/issue for KubeVirt (KubevirtPlatform) platform area/platform/none PR/issue for None (NonePlatform) platform - user-supplied infrastructure area/platform/openstack PR/issue for OpenStack (OpenStackPlatform) platform area/platform/powervs PR/issue for PowerVS (PowerVSPlatform) platform area/testing Indicates the PR includes changes for e2e testing jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. verified Signifies that the PR passed pre-merge verification criteria verified-later

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants