Skip to content

feat: in-cluster config support + cluster observability tools#109

Merged
basebandit merged 6 commits into
mainfrom
feat/in-cluster-support
Jun 8, 2026
Merged

feat: in-cluster config support + cluster observability tools#109
basebandit merged 6 commits into
mainfrom
feat/in-cluster-support

Conversation

@basebandit

@basebandit basebandit commented Feb 1, 2026

Copy link
Copy Markdown
Owner

Description

Production-readiness work, rebased on top of the MCP 2025-06-18 modernization (#123). Two related feature sets:

In-cluster Kubernetes configuration

  • -in-cluster flag uses the pod service account credentials when running inside the cluster.
  • Namespace auto-detected from the service account file.
  • rest.Config stored per context so port-forwarding works under in-cluster config.
  • Unit tests for LoadInClusterConfig + docs.

Cluster observability & node management (9 new tools)

  • Events: list_events (filter by namespace, type, involved object).
  • Nodes: list_nodes, get_node, cordon_node, uncordon_node, drain_node (evicts via the eviction API; skips DaemonSet and mirror pods).
  • Cluster health: cluster_health (node readiness + pod phase summary), node_metrics, pod_metrics (query metrics.k8s.io via the dynamic client; degrade gracefully when metrics-server is absent).
  • Tools carry MCP annotations (read-only / destructive / idempotent).

Type of change

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Tests

  • go build ./..., go vet ./..., go test ./... all green.
  • Fake-client unit tests for events/nodes/health + tool registration tests.

Follow-ups (separate PRs)

  • Storage (PV/PVC) + StorageClass + RBAC + CRD / API-discovery tools
  • Bearer-token auth on HTTP transports
  • Dockerfile + GHCR image build
  • deploy/ manifests + RBAC

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

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.

Pull request overview

This PR adds support for running kai inside a Kubernetes cluster using in-cluster configuration. This enables the application to authenticate using the service account mounted in the pod, eliminating the need for external kubeconfig files when deployed in-cluster.

Changes:

  • Added a new -in-cluster command-line flag to enable in-cluster configuration mode
  • Implemented LoadInClusterConfig method to configure Kubernetes clients using in-cluster authentication
  • Added comprehensive test coverage for the new in-cluster configuration functionality

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cmd/kai/main.go Added -in-cluster flag and conditional logic to load either in-cluster or kubeconfig-based configuration
cluster/manager.go Implemented LoadInClusterConfig method with client creation, connection testing, and context management
cluster/manager_test.go Added test suite covering edge cases including duplicate context names and default naming behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cluster/manager.go
Comment thread cluster/manager.go Outdated

Copilot AI commented Feb 1, 2026

Copy link
Copy Markdown

@basebandit I've opened a new pull request, #110, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Feb 1, 2026

Copy link
Copy Markdown

@basebandit I've opened a new pull request, #111, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Feb 1, 2026

Copy link
Copy Markdown

@basebandit I've opened a new pull request, #112, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Feb 1, 2026

Copy link
Copy Markdown

@basebandit I've opened a new pull request, #113, to work on those changes. Once the pull request is ready, I'll request review from you.

@sonarqubecloud

sonarqubecloud Bot commented Feb 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
45.3% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cluster/manager.go
Comment thread cluster/manager_test.go
@basebandit basebandit requested a review from Copilot February 2, 2026 19:42

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@basebandit basebandit force-pushed the feat/in-cluster-support branch 2 times, most recently from e46f970 to 1bb7de5 Compare June 8, 2026 14:07
@basebandit basebandit changed the title Feat/in cluster support feat: in-cluster config support + cluster observability tools Jun 8, 2026
@basebandit basebandit force-pushed the feat/in-cluster-support branch 3 times, most recently from 7acc774 to 22ba5d7 Compare June 8, 2026 14:51
Add list_events with namespace, type, and involved-object filtering.

Add node management tools:
- list_nodes
- get_node
- cordon_node
- uncordon_node
- drain_node

Drain operations use the eviction API and skip DaemonSet and mirror pods.

Add cluster_health for node readiness and pod phase summaries.

Add node_metrics and pod_metrics using the metrics.k8s.io API through the dynamic client, with graceful degradation when metrics-server is unavailable.

Annotate tools with MCP metadata (read-only, destructive, idempotent) and add fake-client unit tests and tool registration tests.
SonarCloud quality gate failed: new code coverage was 50.9% (< 80%). The
new event/node/health tool handlers and several cluster paths (health
metrics, node Get/Drain, event timestamp fallbacks) lacked direct tests,
and CI measures coverage per-package so registration tests did not count.

Add fake-client tests covering the tool handlers end-to-end plus the
cluster-level node metrics, drain (skip + eviction) and event formatting
paths. New-file coverage now ~90% (cluster 80.2%, tools 85.8%).
@basebandit basebandit force-pushed the feat/in-cluster-support branch from 22ba5d7 to 5c41a99 Compare June 8, 2026 14:52
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

@basebandit basebandit merged commit 90e78fb into main Jun 8, 2026
9 checks passed
@basebandit basebandit deleted the feat/in-cluster-support branch June 8, 2026 14:55
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.

3 participants