Skip to content

fix: initialize port-forward namespace and address flags from provide… - #1937

Open
Samyra312007 wants to merge 3 commits into
kmesh-net:mainfrom
Samyra312007:fix/portforward-flag-init
Open

Samyra312007 wants to merge 3 commits into
kmesh-net:mainfrom
Samyra312007:fix/portforward-flag-init

Conversation

@Samyra312007

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

Fixes pkg/kube.NewPortForwarder() so that newPortForwarder() initializes the Cobra namespace and address flags from the ns and localAddress arguments passed by the caller instead of the hardcoded KmeshNamespace (kmesh-system) and DefaultLocalAddress (localhost) defaults.

Previously the supplied namespace and bind address were stored in the portForwarder struct but never reflected in the Cobra flags, so the port-forward command bound to localhost regardless of the requested localAddress and exposed an inconsistent namespace flag value. Existing callers pass ""/kmesh-system, so behavior is preserved for them.

Also adds unit tests in pkg/kube/portforwarder_test.go covering flag initialization, the localhost fallback, dynamic port selection, and struct field population.

Which issue(s) this PR fixes:
Fixes #1879

Special notes for your reviewer:

NONE

Does this PR introduce a user-facing change?:

NONE

@kmesh-bot kmesh-bot added the kind/bug Something isn't working label Aug 18, 2026
@kmesh-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lizhencheng9527 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kmesh-bot

Copy link
Copy Markdown
Collaborator

Welcome @Samyra312007! It looks like this is your first PR to kmesh-net/kmesh 🎉

…d args

Signed-off-by: Samyra312007 <samayra312007@gmail.com>
@Samyra312007
Samyra312007 force-pushed the fix/portforward-flag-init branch from 55d0a9e to 8d057b8 Compare August 18, 2026 14:31
@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.63158% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.95%. Comparing base (5bf8ed1) to head (10c1b38).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
pkg/kube/portforwarder.go 47.05% 9 Missing ⚠️

❌ Your patch check has failed because the patch coverage (52.63%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Files with missing lines Coverage Δ
pkg/kube/client.go 38.98% <100.00%> (+38.98%) ⬆️
pkg/kube/portforwarder.go 27.08% <47.05%> (+27.08%) ⬆️

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae15e8a...10c1b38. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LiZhenCheng9527

Copy link
Copy Markdown
Contributor

/retest

Comment thread pkg/kube/client.go
@kmesh-bot kmesh-bot added size/L and removed size/M labels Sep 19, 2026
…rwarder config loader wrapper

Signed-off-by: Samyra312007 <samayra312007@gmail.com>
@Samyra312007
Samyra312007 force-pushed the fix/portforward-flag-init branch from 639da56 to 8fff353 Compare September 19, 2026 11:59
Signed-off-by: Samyra312007 <samayra312007@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pkg/kube: NewPortForwarder ignores provided namespace and localAddress

3 participants