Skip to content

[Enhancement]: KafkaRebalance Tools #61

@kornys

Description

@kornys

Related problem

KafkaRebalance CRs drive Cruise Control rebalancing operations. They go through states (New → PendingProposal → ProposalReady → Rebalancing → Ready/NotReady) and provide optimization results. Essential for capacity planning and pre-upgrade checks.

Suggested solution

New Tools

list_kafka_rebalances

  • Parameters: namespace (optional), clusterName (optional)
  • Returns: List of rebalances: name, namespace, cluster, mode (full/add-brokers/remove-brokers/remove-disks), current state (from conditions), auto-approval status
  • K8s CRD: kafkarebalances.kafka.strimzi.io

get_kafka_rebalance

  • Parameters: namespace (optional), rebalanceName (required)
  • Returns: Detailed rebalance: mode, goals, excluded topics, broker list, concurrency settings, replication throttle, optimization result (data movement summary, load before/after), session ID, progress reference, conditions with timestamps
  • Note: Optimization result can be large — use ResponseSizeLimitFilter naturally

New Prompt

assess-upgrade-readiness

  • Parameters: cluster_name, namespace (optional), target_version (optional)
  • Workflow:
    1. Get Kafka cluster — check current versions (kafkaVersion, kafkaMetadataVersion)
    2. List node pools — verify all replicas ready, no pending changes
    3. Get Kafka metrics — check for under-replicated partitions (must be 0)
    4. Get operator status — verify operator is healthy and correct version
    5. List rebalances — check no active rebalancing in progress
    6. Get events — check for recent reconciliation failures
    7. Assess: all brokers healthy? Replication caught up? No pending operations? Operator ready?

New Files

  • KafkaRebalanceService.java@ApplicationScoped
  • KafkaRebalanceTools.java@Singleton, @Guarded
  • KafkaRebalanceSummary.java / KafkaRebalanceDetail.java — DTOs
  • AssessUpgradeReadinessPrompt.java
  • KafkaRebalanceServiceTest.java, KafkaRebalanceToolsTest.java
  • Update McpDiscoveryTest.java, PromptCompletions.java

RBAC

Add to 003-ClusterRole.yaml:

- apiGroups: ["kafka.strimzi.io"]
  resources: ["kafkarebalances"]
  verbs: ["get", "list", "watch"]

Key Notes

  • KafkaRebalance state is encoded in conditions, not a dedicated status field. Extract state from condition types.
  • Optimization result is a JSON structure within the CR status — extract key metrics (data movement GB, replica movements, leader movements).
  • The strimzi.io/rebalance annotation (approve/stop/refresh) is write-only — we never set it, only report its current value.

Verification

  1. mvn clean test — new tests pass
  2. Create KafkaRebalance CRs in various states on dev cluster
  3. Invoke list_kafka_rebalances, get_kafka_rebalance — verify state and optimization data
  4. Test assess-upgrade-readiness prompt against a healthy and unhealthy cluster

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions