Skip to content

Simplify registerSecretInGatewayConfig to reduce cyclomatic complexity - #5491

Merged
salonichf5 merged 4 commits into
nginx:mainfrom
somaz94:feat/refactor-register-secret
Jun 25, 2026
Merged

salonichf5 merged 4 commits into
nginx:mainfrom
somaz94:feat/refactor-register-secret

Conversation

@somaz94

@somaz94 somaz94 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Problem: registerSecretInGatewayConfig carried a //nolint:gocyclo because it duplicated the same five-case named-secret switch across the new-entry and existing-entry branches.

Solution: extract the duplicated named-secret switch into a small assignNamedSecret helper (shared by both branches) and hoist the local hasSuffix closure to a package-level function. The two branches are NOT merged: the docker-secret handling keeps its original asymmetry exactly (the new-entry path overwrites the map entry on first match with break; the existing-entry path appends). This is a behavior-preserving refactor that drops the //nolint:gocyclo.

Testing:

  • go test ./internal/controller/provisioner/... passes unchanged (existing TestRegisterResourceInGatewayConfig covers every secret type across both new and existing-entry paths).
  • golangci-lint run ./internal/controller/provisioner/... reports 0 issues (gocyclo min-complexity 15; the nolint is removed).
  • gofmt, go vet, go build clean.

related: #5253

NONE

@nginx-bot

nginx-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

Hi @somaz94!

Thanks for opening this pull request!
Be sure to check out our Contributing Guidelines while you wait for someone on the team to review this.

Please make sure to include the issue number in the PR description to automatically close the issue when the PR is merged.
See Linking a pull request to an issue and our Pull Request Guidelines for more information.

@nginx-bot nginx-bot Bot added the community label Jun 23, 2026
@github-actions github-actions Bot added the enhancement New feature or request label Jun 23, 2026
@somaz94
somaz94 marked this pull request as ready for review June 23, 2026 09:40
@somaz94
somaz94 requested a review from a team as a code owner June 23, 2026 09:40
@salonichf5
salonichf5 merged commit 9529131 into nginx:main Jun 25, 2026
40 checks passed
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in NGINX Gateway Fabric Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants