Skip to content

simplify: remove redundant loop-variable copies in eventgateway files#887

Merged
rspurgeon merged 2 commits intomainfrom
copilot/simplify-redundant-loop-copies
Apr 25, 2026
Merged

simplify: remove redundant loop-variable copies in eventgateway files#887
rspurgeon merged 2 commits intomainfrom
copilot/simplify-redundant-loop-copies

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 24, 2026

In Go 1.22+, each range-loop iteration owns its variable, making xCopy := x; return &xCopy dead code. Six functions across the eventgateway and adopt packages used this pattern unnecessarily.

Changes

  • findClusterByName (backend_clusters.go) — 2 copies removed
  • findVirtualClusterByName (virtual_clusters.go) — 2 copies removed
  • findListenerByName (listeners.go) — 1 copy removed
  • findDataPlaneCertByName (data_plane_certificates.go) — 1 copy removed
  • findClusterPolicyByName (cluster-policies.go) — 1 copy removed
  • resolveEventGatewayControlPlane (adopt/event_gateway.go) — 1 copy removed

Before:

for _, cluster := range clusters {
    if cluster.Name != "" && strings.ToLower(cluster.Name) == lowered {
        clusterCopy := cluster
        return &clusterCopy
    }
}

After:

for _, cluster := range clusters {
    if cluster.Name != "" && strings.ToLower(cluster.Name) == lowered {
        return &cluster
    }
}

No functional change — aligns with the Go 1.26 modernization standard in AGENTS.md.

Copilot AI changed the title [WIP] Simplify redundant loop variable copies in eventgateway files simplify: remove redundant loop-variable copies in eventgateway files Apr 24, 2026
Copilot AI requested a review from rspurgeon April 24, 2026 21:54
@rspurgeon rspurgeon marked this pull request as ready for review April 24, 2026 21:59
@rspurgeon rspurgeon requested review from a team as code owners April 24, 2026 21:59
Copilot AI review requested due to automatic review settings April 24, 2026 21:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 modernizes several Event Gateway and adopt helper functions by removing now-unnecessary per-iteration struct copies when returning pointers from range loops, aligning the code with the repository’s Go 1.26 toolchain semantics.

Changes:

  • Removed redundant xCopy := x patterns in multiple find*ByName helpers and in resolveEventGatewayControlPlane.
  • Continued to return pointers to per-iteration range variables (maintaining the prior “pointer to copy” behavior without extra locals).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/cmd/root/products/konnect/eventgateway/backend_clusters.go Removes redundant loop-variable copy in backend cluster lookup helper.
internal/cmd/root/products/konnect/eventgateway/virtual_clusters.go Removes redundant loop-variable copies in virtual cluster lookup helper.
internal/cmd/root/products/konnect/eventgateway/listeners.go Removes redundant loop-variable copy in listener lookup helper.
internal/cmd/root/products/konnect/eventgateway/data_plane_certificates.go Removes redundant loop-variable copy in data plane certificate lookup helper.
internal/cmd/root/products/konnect/eventgateway/cluster-policies.go Removes redundant loop-variable copy in cluster policy lookup helper.
internal/cmd/root/products/konnect/adopt/event_gateway.go Removes redundant loop-variable copy when selecting an EGW control plane by name.

Copilot AI temporarily deployed to kongctl-acceptance-2 April 24, 2026 22:02 Inactive
Copilot AI temporarily deployed to kongctl-acceptance-3 April 24, 2026 22:02 Inactive
Copilot AI temporarily deployed to kongctl-acceptance-4 April 24, 2026 22:02 Inactive
Copilot AI temporarily deployed to kongctl-acceptance-5 April 24, 2026 22:02 Inactive
Copilot AI temporarily deployed to kongctl-acceptance April 24, 2026 22:02 Inactive
@rspurgeon rspurgeon merged commit de2bde4 into main Apr 25, 2026
26 checks passed
@rspurgeon rspurgeon deleted the copilot/simplify-redundant-loop-copies branch April 25, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[simplifier] Simplify redundant loop variable copies in recently modified eventgateway files

4 participants