Skip to content

Conversation

brandtkeller
Copy link
Member

@brandtkeller brandtkeller commented Jun 13, 2025

Description

Adds the ability to specify listening addresses for binding the tunnel connection. This allows users to specify other addresses than the hardcoded localhost/127.0.0.1 in such a way as to bind to all interfaces for connectivity on the zarf CLI machine.

IE zarf connect <target> --address 0.0.0.0 to bind to all interfaces.

Primarily this replaces the use of portforward.New() which has localhost hardcoded and calls portforward.NewOnAddresses() with directly calling portfoward.NewOnAddresses() and ensuring we pass in localhost everywhere except for when overriding.

Minor Note - added ls alias to zarf connect list command as this follows the same patterns seen elsewhere (zarf package ls)

The goal was minimal impact to tunnel function signature - that said, updates were required to support the tunnel endpoint methods now potentially returning many.

Related Issue

Fixes #3913

Checklist before merging

Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
@brandtkeller brandtkeller self-assigned this Jun 13, 2025
@brandtkeller brandtkeller requested review from a team as code owners June 13, 2025 16:06
Copy link

netlify bot commented Jun 13, 2025

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit 3103ff8
🔍 Latest deploy log https://app.netlify.com/projects/zarf-docs/deploys/68814026d655de0008f695cd

Copy link

codecov bot commented Jun 13, 2025

Codecov Report

Attention: Patch coverage is 1.68067% with 117 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pkg/cluster/tunnel.go 0.00% 68 Missing ⚠️
src/cmd/connect.go 13.33% 13 Missing ⚠️
src/cmd/internal.go 0.00% 12 Missing ⚠️
src/pkg/cluster/zarf.go 0.00% 12 Missing ⚠️
src/pkg/packager/mirror.go 0.00% 8 Missing ⚠️
src/cmd/crane.go 0.00% 4 Missing ⚠️
Files with missing lines Coverage Δ
src/cmd/crane.go 29.82% <0.00%> (ø)
src/pkg/packager/mirror.go 0.00% <0.00%> (ø)
src/cmd/internal.go 34.71% <0.00%> (-0.91%) ⬇️
src/pkg/cluster/zarf.go 17.21% <0.00%> (-0.59%) ⬇️
src/cmd/connect.go 30.47% <13.33%> (-2.16%) ⬇️
src/pkg/cluster/tunnel.go 9.22% <0.00%> (-0.86%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
@brandtkeller brandtkeller marked this pull request as draft June 13, 2025 16:30
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
@brandtkeller brandtkeller marked this pull request as ready for review June 13, 2025 17:29
@brandtkeller brandtkeller marked this pull request as draft June 14, 2025 03:04
@brandtkeller
Copy link
Member Author

Moving to draft - going to align to kubectl for passing a comma-separated list of addresses as opposed to a single address.

Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
@brandtkeller brandtkeller marked this pull request as ready for review July 22, 2025 16:37
@brandtkeller brandtkeller changed the title feat(connect): support for listen address on zarf connect feat!(connect): support for listen address on zarf connect Jul 22, 2025
Copy link
Contributor

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

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

Some small requests on the API feel, otherwise seems like a good change

giteaClient, err := gitea.NewClient(tunnelURL, s.GitServer.PushUsername, s.GitServer.PushPassword)
// tunnel is created with the default listenAddress - there will only be one endpoint until otherwise supported
tunnelURLs := tunnel.HTTPEndpoints()
giteaClient, err := gitea.NewClient(tunnelURLs[0], s.GitServer.PushUsername, s.GitServer.PushPassword)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would read better to have a function like FirstEndpoint for this, which errors if there isn't an endpoint. We will always have at least one based on how you setup the defaults, but this would just future proof it to 100% never panicing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am good with making that addition - I felt retaining the Endpoint() method and simply returning the "first" arbitrarily as potentially deceiving (rather the user should decide which they want/need) - but the addition of a FirstEndpoint() is still reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking on this more - and the distinction between tunnel.Endpoints() and tunnel.HTTPEndpoints() and tunnel.FullURLs() -> I am a bit torn here.

I don't think it makes sense to create tunnel.First*()` methods for each. For sake of error traceability I do think it may make sense to return errors on zero present - otherwise let the consumer consume the endpoints as they see fit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that's reasonable. Though instead of an error I think we should check if the list is nil (go automatically treats lists of 0 length as nil)

Copy link
Member Author

Choose a reason for hiding this comment

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

instead of an error I think we should check if the list is nil (go automatically treats lists of 0 length as nil)

Can you elaborate?

I generally understand the length check to be more idiomatic as it is safe for nil and non-nil states (such as empty non-nil states).

But maybe you are suggesting something else such as not returning the error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry yeah I had some incorrect assumptions on how slices work and my suggestion was unclear. I'm suggesting that we only return a list then callers can error if the len is 0, before using the first item in the list.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah! I am good with that - change in progress.

Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Copy link
Contributor

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

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

LGTM

@brandtkeller brandtkeller added this pull request to the merge queue Jul 24, 2025
Merged via the queue into main with commit 1a902fd Jul 24, 2025
39 checks passed
@brandtkeller brandtkeller deleted the 3913_port_forward branch July 24, 2025 01:52
Ansible-man pushed a commit to Ansible-man/zarf that referenced this pull request Sep 6, 2025
…3914)

Signed-off-by: Brandt Keller <brandt.keller@defenseunicorns.com>
Signed-off-by: Cade Thomas <cadethomas23@gmail.com>
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.

Add all kubectl port-forward capabilities to zarf connect
2 participants