Skip to content

feat: add kubectl plugin for diagnosing kgateway policies #11292

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 2 commits into
base: main
Choose a base branch
from

Conversation

MayorFaj
Copy link
Contributor

@MayorFaj MayorFaj commented May 27, 2025

Description

CLI-Based Policy Diagnostics Enhancement

Summary

This proposal addresses the issue where TrafficPolicy resources that reference non-existing targets do not provide clear status information or logging to help users diagnose attachment problems. We propose building CLI diagnostic capabilities to provide comprehensive policy analysis and troubleshooting tools.

Motivation

Current Problems

  1. Poor Visibility: Users have limited insight into why policies aren't working as expected
  2. Debugging Difficulty: No systematic way to analyze policy attachment issues across the cluster

Goals

  • Provide immediate diagnostic feedback for policy attachment issues
  • Enable proactive identification of configuration problems
  • Support both development and production troubleshooting workflows
  • Integrate seamlessly with existing kubectl workflows

Proposal

CLI-First Approach

Rather than expanding the Status API or adding complex controller logging, we propose enhancing the existing CLI diagnostic capabilities as the primary mechanism for policy troubleshooting.

Rationale

  1. Immediate Feedback: CLI tools provide instant analysis without waiting for controller reconciliation
  2. Rich Output: Can provide detailed explanations and remediation suggestions
  3. Flexible Deployment: Works in any environment with kubectl access
  4. CI/CD Integration: Easy to integrate into deployment pipelines for validation

Implementation Strategy

1. Enhanced kubectl Plugin

Build the kubectl-kgateway plugin with comprehensive diagnostic capabilities:

# Analyze specific policy
kubectl kgateway policy gw-policy -n kgateway-test

# Analyze all policies in namespace
kubectl kgateway policy -n production

# Cluster-wide analysis
kubectl kgateway policy --all-namespaces

2. Core Diagnostic Features

Policy Status Analysis:

  • Attachment status (attached/unattached)
  • Ancestor reference validation
  • Target reference existence checks
  • Target selector matching analysis

Target Resource Validation:

  • Verify target resources exist
  • Check parent reference chains (HTTPRoute → Gateway)
  • Validate resource relationships

Common Issues Detection:

  • Empty target references/selectors
  • Misconfigured label selectors
  • Missing parent resources
  • Cross-namespace reference issues

Advantages Over Alternatives

vs. Enhanced Status API

  • Immediate availability: No controller changes required
  • Rich formatting: Better user experience than structured status
  • Backward compatibility: No API changes needed

vs. Controller Logging

  • Targeted analysis: On-demand rather than constant logging
  • User-friendly: Structured output vs. log parsing
  • Remediation guidance: Actionable suggestions

vs. New CRDs/Controllers

  • Simplicity: Leverages existing resources
  • Performance: No additional cluster resources
  • Maintainability: Simpler implementation and testing

Change Type

/kind feature

Changelog

None

Additional Notes

Signed-off-by: MayorFaj <mayorfaj@gmail.com>
@github-actions github-actions bot added do-not-merge/release-note-invalid Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. release-note-none and removed do-not-merge/release-note-invalid Indicates that a PR should not merge because it's missing one of the release note labels. labels May 27, 2025
Signed-off-by: MayorFaj <mayorfaj@gmail.com>
@MayorFaj
Copy link
Contributor Author

@shashankram @ymesika your input is required and appreciated, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant