Skip to content

fix(ctl): validate monitoring flags before connecting to cluster - #1966

Open
Norway-02 wants to merge 1 commit into
kmesh-net:mainfrom
Norway-02:fix/ctl-monitoring-early-flag-validation
Open

Norway-02 wants to merge 1 commit into
kmesh-net:mainfrom
Norway-02:fix/ctl-monitoring-early-flag-validation

Conversation

@Norway-02

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:
Previously, ControlMonitoring attempted to initialize the Kubernetes client via utils.CreateKubeClient() before checking whether any monitoring flags were supplied and before validating their values.

When executed without valid flags (or in offline/local environments without kubeconfig), running kmeshctl monitoring failed with a generic client initialization error instead of clearly notifying the user about missing flags (no parameters. Need --accesslog, --workloadMetrics, --connectionMetrics or --all).

Furthermore, invalid flag values (values other than "enable" or "disable") were previously only caught downstream inside the per-pod loop after starting port-forwarding to each daemon.

This PR fixes this by:

  1. Validating that at least one monitoring flag is provided before attempting Kubernetes client creation.
  2. Validating flag values ("enable" or "disable") up front before making cluster connections.
  3. Supporting client injection via setKubeClient for testability.
  4. Adding unit test coverage in ctl/monitoring/monitoring_test.go covering parameter validation, invalid values, and error returns.

Which issue(s) this PR fixes:
None

Special notes for your reviewer:
All unit tests in ctl/monitoring pass cleanly and make copyright-check passes.

Does this PR introduce a user-facing change?:

kmeshctl monitoring now validates flags and parameters before connecting to the cluster.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 05:11
@kmesh-bot kmesh-bot added the kind/bug Something isn't working label Oct 17, 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Norway-02

Copy link
Copy Markdown
Contributor Author

/cc @LiZhenCheng9527

@LiZhenCheng9527 This PR is ready for review, thank you!

Previously, ControlMonitoring attempted to initialize the Kubernetes
client via utils.CreateKubeClient() before checking whether any flags
were supplied and before validating their values. When executed in an
offline environment or without kubeconfig, commands without arguments or
with invalid flags failed with a generic client initialization error
instead of reporting the missing or invalid flags.

Furthermore, invalid flag values (values other than "enable" or
"disable") were only caught downstream inside the per-pod loop after
starting port-forwarding to each daemon.

Fix this by:
1. Validating that at least one monitoring flag is provided before
   initializing the Kubernetes client.
2. Validating flag values ("enable" or "disable") up front.
3. Supporting client injection via setKubeClient for unit testing.
4. Adding unit test coverage in ctl/monitoring/monitoring_test.go for
   missing parameters and invalid flag values.

Signed-off-by: Norway-02 <anshulkhetade02@gmail.com>
@Norway-02
Norway-02 force-pushed the fix/ctl-monitoring-early-flag-validation branch from 7fb5e12 to 579df22 Compare October 22, 2026 04:59
Copilot AI balanced review requested due to automatic review settings October 22, 2026 04:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.84%. Comparing base (c48f7f0) to head (579df22).
⚠️ Report is 3 commits behind head on main.
see 1 file 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 b25c1a2...579df22. Read the comment docs.

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

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/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants