Skip to content

Refactor port conflict resolver to reduce its cyclomatic complexity#5438

Merged
salonichf5 merged 2 commits into
nginx:mainfrom
somaz94:feat/refactor-port-conflict-resolver
Jun 16, 2026
Merged

Refactor port conflict resolver to reduce its cyclomatic complexity#5438
salonichf5 merged 2 commits into
nginx:mainfrom
somaz94:feat/refactor-port-conflict-resolver

Conversation

@somaz94

@somaz94 somaz94 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Problem: createPortConflictResolver carried a //nolint:gocyclo exception (plus a maintainer FIXME to refactor before 2.7). Its returned closure packed all per-port conflict-detection logic into a single deeply nested function, hurting readability.

Solution: Extracted the closed-over state into a portConflictResolver struct and split the conflict handling into focused methods (resolveProtocolGroupConflict, resolveSameProtocolGroupConflict) plus three small invalidate* helpers that replace the repeated "mark listener invalid + append condition" blocks. Behavior is unchanged; the //nolint:gocyclo directive and the FIXME comment are removed.

Testing:

  • go test ./internal/controller/state/graph/... passes unchanged (existing table-driven conflict tests).
  • golangci-lint run ./internal/controller/state/graph/... reports 0 issues — every resulting function is now under the configured gocyclo min-complexity: 15, so the nolint removal holds.
  • gofmt + go vet clean.

This is a first step toward #5253 (one of the ~14 nolint:gocyclo functions — the one flagged with a FIXME(bjee19)). Happy to follow up with the remaining sites in separate PRs.

related: #5253

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

NONE

@github-actions github-actions Bot added the enhancement New feature or request label Jun 11, 2026
somaz94 added a commit to somaz94/somaz94 that referenced this pull request Jun 11, 2026
@somaz94 somaz94 marked this pull request as ready for review June 12, 2026 01:14
@somaz94 somaz94 requested a review from a team as a code owner June 12, 2026 01:14

@bjee19 bjee19 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm, thanks!

@salonichf5 salonichf5 merged commit 3907a3e into nginx:main Jun 16, 2026
40 checks passed
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in NGINX Gateway Fabric Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants