Skip to content

PERFSCALE-2104: Enable and apply fieldalignment linter#6789

Open
sjug wants to merge 1 commit into
openshift:mainfrom
sjug:perfscale-2104-fieldalignment
Open

PERFSCALE-2104: Enable and apply fieldalignment linter#6789
sjug wants to merge 1 commit into
openshift:mainfrom
sjug:perfscale-2104-fieldalignment

Conversation

@sjug
Copy link
Copy Markdown
Contributor

@sjug sjug commented Jun 2, 2026

Enables the govet fieldalignment analyzer through the existing make verify-golangci path and applies the current baseline cleanup.

What changed:

  • Enabled govet.fieldalignment in .golangci.yaml.
  • Reordered internal/runtime structs that had no serialization, positional literal, reflection, unsafe, or binary-layout dependency.
  • Kept field order for API, config, persisted JSON, startup JSON, OVSDB model, generated, and test/table-fixture shapes.
  • Used narrow per-struct //nolint comments where source order is intentional and a file-level exclusion would hide future findings.

Why:
fieldalignment can reduce struct padding and pointer scan ranges, but it is a blunt analyzer. The useful CI value is catching future inefficient layouts in high-cardinality structs, not mechanically rewriting every struct in the tree. This PR fixes the safe internal cases and scopes exclusions so reviewers still get signal for new runtime structs.

Impact:
The structs changed here are mostly startup-time singletons or low-cardinality runtime objects, so direct memory/GC savings are expected to be small. The main benefit is the ongoing guardrail during review.

Verification:

  • make verify-golangci
  • go test ./pkg/admin/prerun ./pkg/servicemanager/startuprecorder ./pkg/servicemanager ./pkg/controllers/c2cc

Summary by CodeRabbit

  • Chores
    • Optimized struct field alignment across the codebase for improved memory efficiency and performance.
    • Enhanced code quality tooling configuration to enforce stricter linting standards across the project.

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

openshift-ci-robot commented Jun 2, 2026

@sjug: This pull request references PERFSCALE-2104 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:

Enables the govet fieldalignment analyzer through the existing make verify-golangci path and applies the current baseline cleanup.

What changed:

  • Enabled govet.fieldalignment in .golangci.yaml.
  • Reordered internal/runtime structs that had no serialization, positional literal, reflection, unsafe, or binary-layout dependency.
  • Kept field order for API, config, persisted JSON, startup JSON, OVSDB model, generated, and test/table-fixture shapes.
  • Used narrow per-struct //nolint comments where source order is intentional and a file-level exclusion would hide future findings.

Why:
fieldalignment can reduce struct padding and pointer scan ranges, but it is a blunt analyzer. The useful CI value is catching future inefficient layouts in high-cardinality structs, not mechanically rewriting every struct in the tree. This PR fixes the safe internal cases and scopes exclusions so reviewers still get signal for new runtime structs.

Impact:
The structs changed here are mostly startup-time singletons or low-cardinality runtime objects, so direct memory/GC savings are expected to be small. The main benefit is the ongoing guardrail during review.

Verification:

  • make verify-golangci
  • go test ./pkg/admin/prerun ./pkg/servicemanager/startuprecorder ./pkg/servicemanager ./pkg/controllers/c2cc

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

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: d3889e5e-ec0c-4fb2-9ea0-4b202dbcd215

📥 Commits

Reviewing files that changed from the base of the PR and between 8161288 and 4c9e977.

📒 Files selected for processing (23)
  • .golangci.yaml
  • pkg/admin/prerun/version.go
  • pkg/controllers/c2cc/controller.go
  • pkg/controllers/c2cc/nbdb.go
  • pkg/controllers/c2cc/routes.go
  • pkg/controllers/c2cc/service_routes.go
  • pkg/controllers/cluster-policy-controller.go
  • pkg/controllers/filewatcher.go
  • pkg/controllers/kube-apiserver.go
  • pkg/controllers/kube-controller-manager.go
  • pkg/controllers/openshift-route-controller-manager.go
  • pkg/loadbalancerservice/controller.go
  • pkg/mdns/controller.go
  • pkg/mdns/server/resolver.go
  • pkg/mdns/server/server.go
  • pkg/servicemanager/manager.go
  • pkg/servicemanager/service.go
  • pkg/servicemanager/startuprecorder/startuprecorder.go
  • pkg/telemetry/telemetry.go
  • pkg/util/all_err_group.go
  • pkg/util/cryptomaterial/certchains/chainsbuilder.go
  • pkg/util/cryptomaterial/certchains/signerbuilder.go
  • pkg/util/cryptomaterial/certchains/signers.go

Walkthrough

This PR updates struct field ordering across 22 files to optimize memory alignment and adds linter configuration. The .golangci.yaml enables govet's fieldalignment check globally while excluding test files and specific production paths. Struct fields are reordered in controllers, service managers, utilities, and supporting packages; lint directives suppress intentional alignment trade-offs.

Changes

Struct field alignment refactoring

Layer / File(s) Summary
Linter configuration and govet fieldalignment enablement
.golangci.yaml
Enabled govet fieldalignment check globally and added exclusion rules for test files, Kubernetes API definitions, config files, and pkg/controllers/c2cc/nbdb.go.
C2CC controller package alignment
pkg/controllers/c2cc/controller.go, pkg/controllers/c2cc/nbdb.go, pkg/controllers/c2cc/routes.go, pkg/controllers/c2cc/service_routes.go
Reordered C2CCRouteManager struct fields to group client and subsystem pointers, added lint directives for embedded route managers, and reformatted function-level lint comments.
Core controller field alignment
pkg/controllers/cluster-policy-controller.go, pkg/controllers/kube-apiserver.go, pkg/controllers/kube-controller-manager.go, pkg/controllers/openshift-route-controller-manager.go, pkg/controllers/filewatcher.go, pkg/loadbalancerservice/controller.go
Reordered fields in cluster policy, Kube API server, Kube controller manager, OpenShift route, and file watcher controllers to optimize alignment; moved unexported runtime fields before exported configuration fields in load balancer service controller.
Service manager and telemetry alignment
pkg/servicemanager/manager.go, pkg/servicemanager/service.go, pkg/servicemanager/startuprecorder/startuprecorder.go, pkg/telemetry/telemetry.go
Reordered ServiceManager, GenericService, and StartupRecorder structs; moved proxy transport field earlier in TelemetryClient and added lint directives for JSON field ordering.
mDNS, cryptomaterial, and utilities alignment
pkg/mdns/controller.go, pkg/mdns/server/resolver.go, pkg/mdns/server/server.go, pkg/util/cryptomaterial/certchains/chainsbuilder.go, pkg/util/cryptomaterial/certchains/signerbuilder.go, pkg/util/cryptomaterial/certchains/signers.go, pkg/util/all_err_group.go, pkg/admin/prerun/version.go
Added lint directives to embedded mutex fields in mDNS; reordered internal fields in Server struct; reordered certificate chain and signer struct fields; reordered AllErrGroup and versions struct fields to optimize alignment.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

ready-for-human-review

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (14 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling the fieldalignment linter and applying it across the codebase via struct field reordering.
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 modifies only non-test source files and configuration; custom check for Ginkgo test name stability is not applicable.
Test Structure And Quality ✅ Passed PR contains no test code changes; it only modifies struct field ordering and linter configuration. Custom check for Ginkgo test quality is not applicable.
Microshift Test Compatibility ✅ Passed This PR makes no changes to e2e tests; it only updates .golangci.yaml and reorders struct fields for the fieldalignment linter, making the test compatibility check not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR contains no new Ginkgo e2e tests; only linter config and struct field reordering changes. Check not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR only reorders struct fields and configures linter rules. No deployment manifests, operators, or scheduling constraints are introduced.
Ote Binary Stdout Contract ✅ Passed PR contains only struct field reordering and lint directives—no new code logic, imports, or stdout calls added in process-level code.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR contains no Ginkgo e2e tests (0 test files added). Changes are struct field reordering and linter configuration only.
No-Weak-Crypto ✅ Passed PR only modifies struct field ordering and linter configuration. No weak cryptography, custom crypto implementations, or insecure comparisons are introduced.
Container-Privileges ✅ Passed PR contains only Go source files and golangci-lint configuration—no K8s manifests, Dockerfiles, or container specs to assess for privilege settings.
No-Sensitive-Data-In-Logs ✅ Passed PR contains only struct reordering and linter config changes; no new logging statements or sensitive data exposure detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=warning msg="The linter 'gomodguard' is deprecated (since v2.12.0) due to: new major version. Replaced by gomodguard_v2."
level=warning msg="Suggested new configuration:\nlinters:\n enable:\n - gomodguard_v2\n"
level=error msg="Running error: context loading failed: failed to load packages: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: inconsistent vendoring in :\n\tgithub.com/apparentlymart/go-cidr@v1.1.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgithub.com/coreos/go-systemd@v0.0.0-20190321100706-95778dfbb74e: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgithub.com/google/go-cmp@v0.7.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgithub.com/miekg/dns@v1.1.63: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt\n\tgithub.com/openshift/api@v0.0.0-20260408092441-8b086e6b9eb9: is

... [truncated 31032 characters] ...

elet: is replaced in go.mod, but not marked as replaced in vendor/modules.txt\n\tk8s.io/metrics: is replaced in go.mod, but not marked as replaced in vendor/modules.txt\n\tk8s.io/mount-utils: is replaced in go.mod, but not marked as replaced in vendor/modules.txt\n\tk8s.io/pod-security-admission: is replaced in go.mod, but not marked as replaced in vendor/modules.txt\n\tk8s.io/sample-apiserver: is replaced in go.mod, but not marked as replaced in vendor/modules.txt\n\tk8s.io/sample-cli-plugin: is replaced in go.mod, but not marked as replaced in vendor/modules.txt\n\tk8s.io/sample-controller: is replaced in go.mod, but not marked as replaced in vendor/modules.txt\n\n\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor\n"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@openshift-ci openshift-ci Bot requested review from jogeo and kasturinarra June 2, 2026 13:44
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@coderabbitai coderabbitai Bot added the ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review label Jun 2, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

@sjug: 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.

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. ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants