Skip to content

add Ports field in GatewayClient and enforce Port/Ports coherence#3233

Open
MircoBarone wants to merge 4 commits intoliqotech:masterfrom
MircoBarone:PR6-multitunnel-gatewayclientflags
Open

add Ports field in GatewayClient and enforce Port/Ports coherence#3233
MircoBarone wants to merge 4 commits intoliqotech:masterfrom
MircoBarone:PR6-multitunnel-gatewayclientflags

Conversation

@MircoBarone
Copy link
Copy Markdown
Contributor

Description

Part of the multi-tunnel WireGuard implementation. This is the 3rd PR related to issue #3225.

The Ports field was introduced in GatewayClientSpec. The idea is to store the list of endpoint ports that the gateway server has exposed for the WireGuard interfaces. Ports is not meant to replace the legacy Port field, which is kept for backward compatibility. The invariant is that Ports[0] must always be equal to Port.

To enforce this, a new function EnsurePortsCoherence was added to the ClientReconciler. At the beginning of each reconcile cycle, this function checks whether Port and Ports are consistent. If not, it normalizes them according to the following rules:

  • If only Port is specified, Ports is set to []int32{Port}
  • If Ports is specified, Port is overwritten with Ports[0]
  • If neither is specified, both are set to the default value

After normalization, the resource is updated and the reconcile cycle is requeued.

@adamjensenbot
Copy link
Copy Markdown
Collaborator

Hi @MircoBarone. Thanks for your PR!

I am @adamjensenbot.
You can interact with me issuing a slash command in the first line of a comment.
Currently, I understand the following commands:

  • /rebase: Rebase this PR onto the master branch (You can add the option test=true to launch the tests
    when the rebase operation is completed)
  • /merge: Merge this PR into the master branch
  • /build Build Liqo components
  • /test Launch the E2E and Unit tests
  • /hold, /unhold Add/remove the hold label to prevent merging with /merge

Make sure this PR appears in the liqo changelog, adding one of the following labels:

  • feat: 🚀 New Feature
  • fix: 🐛 Bug Fix
  • refactor: 🧹 Code Refactoring
  • docs: 📝 Documentation
  • style: 💄 Code Style
  • perf: 🐎 Performance Improvement
  • test: ✅ Tests
  • chore: 🚚 Dependencies Management
  • build: 📦 Builds Management
  • ci: 👷 CI/CD
  • revert: ⏪ Reverts Previous Changes

@github-actions github-actions Bot added the feat Adds a new feature to the codebase label Mar 24, 2026
@github-actions github-actions Bot added the style Changes related to code formatting, whitespace, or linting, without affecting functionality label Mar 24, 2026
@MircoBarone MircoBarone force-pushed the PR6-multitunnel-gatewayclientflags branch from d678438 to e9bae96 Compare April 1, 2026 08:52
@MircoBarone MircoBarone marked this pull request as draft April 16, 2026 18:30
@MircoBarone MircoBarone force-pushed the PR6-multitunnel-gatewayclientflags branch from e9bae96 to dbc13ad Compare April 17, 2026 16:16
@github-actions github-actions Bot added the refactor Reorganizes or optimizes code without changing its behavior label Apr 17, 2026
@MircoBarone
Copy link
Copy Markdown
Contributor Author

I have removed the coherence check (Ports[0] == Port) for GatewayClient from client_controller.go. The controller is not the appropriate place to handle validation or mutation of this resource.

The logic is now handled via CEL validation: if both Port and Ports are provided, Ports[0] must match Port, otherwise the resource is rejected. It remains possible to create a GatewayClient specifying only Port, only Ports, or neither. No mutation is performed on the resource.

Potential Issues

Ports is intended to replace Port. It populates the --endpoint-ports flag of the wireguard container, while Port populates the --endpoint-port flag.

  • If a user uses a template that only supports --endpoint-port but provides the port via the Ports field, the configuration will not work.
  • Conversely, if only Port is specified but the template only uses --endpoint-ports, it will fail because the value is not automatically copied to the new flag.

I believe these issues can be solved by using a more robust template, for example:

- --endpoint-port={{ if .Spec.Endpoint.Port }}{{ .Spec.Endpoint.Port }}{{ else if .Spec.Endpoint.Ports }}{{ index .Spec.Endpoint.Ports 0 }}{{ end }}
- --endpoint-ports={{ if .Spec.Endpoint.Ports }}{{ range $i, $p := .Spec.Endpoint.Ports }}{{ if $i }},{{ end }}{{ $p }}{{ end }}{{ else }}{{ .Spec.Endpoint.Port }}{{ end }}

I am moving this PR out of draft. Let me know if you think a Mutating Webhook is strictly necessary or if this CEL-based approach is sufficient. In my opinion, this approach can also serve as a base if we want to introduce mutation in the future

@MircoBarone MircoBarone marked this pull request as ready for review April 21, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Adds a new feature to the codebase refactor Reorganizes or optimizes code without changing its behavior size/M style Changes related to code formatting, whitespace, or linting, without affecting functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants