Skip to content

Plain mode: support port forwarding #3699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Horiodino
Copy link
Contributor

Fixes #2962

Changes

  • Added --port-forward CLI flag to limactl create, allowing users to specify static port forwards even in plain mode.
  • Modified host agent to set up static SSH-based TCP port forwarding in plain mode.
  • Updated YAML expressions to handle portForwards from CLI.
  • Added validation warnings for large port ranges in plain mode.

Copy link
Member

@nirs nirs left a comment

Choose a reason for hiding this comment

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

It is not clear what is the suggested behavior. Can we start with the documentation instead of the code, so we have clear understanding of wanted behavior?

portForwards:
- guestPort: 80
hostPort: 9090
static: true
Copy link
Member

Choose a reason for hiding this comment

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

We should also test mixed ports. Both dynamic and static ports will be available when running in normal mode, but only the static ports will be available in --plain mode.

I'm not sure if static ports should be served using ssh when running in normal mode, but this is implementation detail.

@alexandear alexandear requested a review from Copilot July 12, 2025 16:50
Copy link

@Copilot 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

Adds support for user-defined static port forwarding in plain mode by extending the CLI, YAML schema, host agent logic, and validation.

  • Introduce a --port-forward flag with parsing and YQ expression generation
  • Extend PortForward with Static, filter non-static rules in plain mode, and warn on large port ranges
  • Update host agent to separate/apply static forwards and add end-to-end tests + CI jobs

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/portfwd/forward.go Skip dynamic forwarding for statically handled ports
pkg/limayaml/validate.go Warn for port ranges >10 in plain mode
pkg/limayaml/limayaml.go Add Static field to PortForward struct
pkg/limayaml/defaults.go Remove non-static forwards when plain mode is enabled
pkg/limayaml/defaults_test.go Tests for filtering static vs. non-static forwards
pkg/hostagent/hostagent.go Separate and apply static forwards; adjust event loop logic
cmd/limactl/editflags/editflags.go Register port-forward flag and implement parsing & expression
cmd/limactl/editflags/editflags_test.go Unit tests for ParsePortForward and BuildPortForwardExpression
hack/test-templates/static-port-forward.yaml Template covering static/dynamic port examples
hack/test-plain-static-port-forward.sh Script to verify static-only forwarding in plain mode
hack/test-nonplain-static-port-forward.sh Script to verify full forwarding in normal mode
.github/workflows/test.yml CI jobs to run the new static port forwarding tests
Comments suppressed due to low confidence (2)

pkg/hostagent/hostagent.go:619

  • [nitpick] Consider adding unit or integration tests for separateStaticPortForwards and addStaticPortForwardsFromList to verify correct separation and application of static port-forwarding rules.
func (a *HostAgent) addStaticPortForwardsFromList(ctx context.Context, staticPortForwards []limayaml.PortForward) {

pkg/hostagent/hostagent.go:642

  • The loop uses for i := range len(a.instConfig.PortForwards), which attempts to range over an int and will not compile. Change it to for i := range a.instConfig.PortForwards or use a classic indexed loop like for i := 0; i < len(...); i++.
	for i := range len(a.instConfig.PortForwards) {

@Horiodino Horiodino force-pushed the port-forwarding branch 2 times, most recently from c4cea4c to 5f856c3 Compare July 13, 2025 08:58
Signed-off-by: Praful Khanduri <[email protected]>

Skip static port forwards on gRPC because conflicts

Signed-off-by: Praful Khanduri <[email protected]>

Revert unintended changes to templates/default.yaml

Signed-off-by: Praful Khanduri <[email protected]>

fixed failing golangci lint err

Signed-off-by: Praful Khanduri <[email protected]>
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.

Plain mode: support port forwarding (opt-in)
5 participants