WorkingDirectory icon
Clone icon
OutputValues icon
TopicList icon
Loop icon
TopicDescribe icon
Script icon
Docker icon
Log icon
If icon
Fail icon
SlackIncomingWebhook icon
Pause icon
Set icon
Switch icon
TopicCreate icon
TopicUpdate icon
TopicCreatePartitions icon
Assert icon
Schedule icon
Webhook icon

Kafka Topic GitOps Reconciler with Unsafe Change Refusal

Reconcile Kafka topics with a YAML file in Git. Create topics, add partitions, set configs, refuse unsafe changes and verify each change.

Categories
Infrastructure

Teams keep Kafka topic definitions in Git and review them by pull request. A manual apply can skip a topic or cut retention on the wrong topic. This flow applies the merged file and checks the result on the broker.

How it works

  1. The git_push webhook starts the flow after a merge. The hourly schedule finds manual changes.
  2. clone gets the branch and desired parses the YAML file.
  3. list_topics and describe_live read the live partitions, replication factor and configs.
  4. plan sorts each difference. A partition decrease, a replication factor change or an unknown key on an existing topic is refused. A retention decrease, a cleanup.policy change or new partitions on a keyed: true topic need approval.
  5. refuse_unsafe fails the run before any change if an entry is refused or invalid.
  6. approval_gate posts gated changes to Slack and pauses. A rejected plan is kept in KV and is not asked again.
  7. apply runs TopicCreate, TopicCreatePartitions or TopicUpdate. verify describes each topic again and fails on a different value.
  8. report posts the changes and the Git commit. save_state writes the result to KV.

What you get

  • Topics that match the reviewed file, with the commit in each report.
  • No partition decrease and no replication factor change.
  • An approval before a change that deletes data or moves keys.
  • Topics not in Git are listed, never deleted.

Who it's for

  • Platform teams that run Kafka or Redpanda for many services.

Why orchestrate this with Kestra

  • Approval, KV state, retries and verification are in one YAML file, with history for each run.

Prerequisites

  • A Kafka or Redpanda cluster, with permission to create and alter topics.
  • A Git file like topics: {orders.v1: {partitions: 6, configs: {retention.ms: 604800000}}}, with an optional defaults map.
  • A Docker task runner for the plan script.

Secrets

  • GIT_USERNAME, GIT_TOKEN: read access to the repository.
  • SLACK_WEBHOOK_URL: approvals, reports and failures.
  • KAFKA_TOPICS_WEBHOOK_KEY: key of the git_push webhook.

Quick start

  1. Create the secrets.
  2. Set bootstrap_servers, cluster, repo_url and state_file.
  3. Execute the flow and read the plan_summary log.
  4. Add the webhook to the Git push event and enable hourly.

How to extend

  • Add SASL or TLS keys to the AdminClient properties.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.