Skip to content
mohanedmohPublic

About

Kubernetes operator that keeps a Git repository and an application's files in sync through a shared PVC. Declare and Treebind pulls, commits and pushes.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Treebind

Keep a Git repository and a Kubernetes volume in sync, in both directions.

Declare a Treebind. It pulls changes from Git, commits what your application writes, and pushes it back.

CI CodeQL Release License Artifact Hub

Quickstart · Examples · Documentation · Discussions

⭐ If Treebind is useful to you, star it on GitHub. It helps other people find it.

Why Treebind

Many applications keep their state as plain files: dashboards, workflow definitions, site content, settings. People edit them in the application's own UI, so the edits have no history, no review and no rollback. GitOps tools deploy your manifests, but they do not follow the files an application writes while it runs.

Treebind puts such a directory under Git, in both directions:

  • A user saves a dashboard in the application, and Treebind commits and pushes it.
  • Someone merges a change in Git, and Treebind writes it into the application's directory.

How it works

How Treebind works: a Git repository and your application share a PVC through a sync agent. The agent pulls changes into the volume, and commits and pushes the application's edits. The operator creates the sync pod and writes Ready, Synced and Conflict on the Treebind resource.

When... Treebind...
the application writes a file waits until the file has been quiet for settleTime (5s by default), commits it as one author, and pushes it as a fast-forward
someone pushes to the branch pulls at every interval (30s by default) and writes the change into the directory, never over an edit that is not committed yet
both sides changed the same file applies your conflictPolicy: followRemote (Git wins, your commits are kept in a ref) or followLocal (the application wins, in a merge commit that keeps Git's version in the history)
it cannot decide safely stops, says why in kubectl describe (Synced, Conflict), and waits for you

Features

  • Two-way, or pull-only. bidirectional commits and pushes the application's edits. pull is a read-only mirror of the repository.
  • Safe by default. It never force-pushes and never writes over an uncommitted local edit. It refuses an update that would remove more than 100 files at once (deletion guard), and it never commits files named like secrets, such as .env and private keys.
  • Breaks echo loops. commit.maxPerHour (60 by default) stops an application and a repository that answer each other from committing for ever (echo loops).
  • Syncs exactly what you mean. repository.path syncs one directory of a monorepo, and paths.include / paths.exclude take .gitignore patterns.
  • Observable. kubectl get treebind shows Ready, Synced and Conflict. Each change of Synced and Conflict is also an event and a Prometheus metric, with alert expressions in the docs.
  • Locked down. Two operator replicas with leader election. Pods run under the restricted Pod Security level. The operator never reads a Secret and can be limited to the namespaces you name (RBAC). The chart and images are signed, with SBOMs, for amd64 and arm64.

See it work

A Treebind is one small manifest:

apiVersion: treebind.example.org/v1alpha1
kind: Treebind
metadata: {name: dashboards, namespace: monitoring}
spec:
  repository:
    url: ssh://git@github.com/acme/dashboards.git   # change: the ssh address of your repository
    branch: main                                    # change: the branch to follow
    auth:
      sshKeySecretRef: {name: deploy-key, key: id_ed25519}                    # change: your Secret with the deploy key
      knownHostsConfigMapRef: {name: git-known-hosts, key: known_hosts}       # change: your ConfigMap with the host's keys
  target:
    claimName: app-data        # change: an existing PersistentVolumeClaim
    subPath: dashboards        # change: the directory of the claim that is synced
  sync:
    direction: bidirectional
    conflictPolicy: followLocal

Write a file the way your application would:

kubectl -n demo exec app -- sh -c 'echo "Written by the application" > /data/from-the-app.txt'

A few seconds later it is a commit on the branch. This is the log on the quickstart's Git server:

d3de362 treebind-bot: treebind: sync 1 file(s)
a8b732d Developer: First commit

Push a commit from Git, and the file appears in the application's directory within the interval. The quickstart runs the whole loop on a local kind cluster, with a Git server inside the cluster, in about ten minutes. CI runs every command on that page on a kind cluster.

Install

You need Kubernetes 1.35 or later, Helm, an existing PVC, and a Git repository that you can give an ssh deploy key.

helm install treebind oci://ghcr.io/mohanedmoh/charts/treebind --version 0.0.1-alpha.5 \
  --namespace treebind-system --create-namespace --wait

Each release also publishes an install.yaml for kubectl apply, and signs the chart and both images (how to verify a release). The chart README lists what it installs and its values.

Examples

Each example is a complete, tested walk-through that starts where the quickstart ends.

Use case What it shows
Dashboards edited in the application Both directions, the author and message of the commits, and a dashboard changed in the application and in Git at the same time
A static site that Git deploys and nginx serves direction: pull, a read-only mount, and a push that is live within the interval
One directory of a monorepo repository.path, commits that change only that directory, and paths.exclude

Status and limitations

Treebind is alpha, and its releases are pre-releases. Do not use it with data you cannot lose. Read this before you use it with anything that matters.

  • The API will change. The group treebind.example.org is a placeholder (#15), and when it changes you will create every Treebind again.
  • Tested on kind. The tests run on kind clusters of one node with local-path storage. v0.0.1-alpha.5 was also tried by hand on a cluster of two nodes, with local and NFS volumes. No storage class is listed as supported yet (storage support).
  • Placement next to the application is opt-in. With a ReadWriteOnce claim on several nodes, set spec.placement.appSelector (newer than 0.0.1-alpha.5), or the scheduler can put the two on different nodes. When the application moves to another node, the operator replaces the sync pod beside it, after 30 seconds and at most once in 2 minutes (when the application moves); a Deployment needs strategy: type: Recreate to move such a claim at all.
  • The only credential is an ssh key (tokens for https: #58). The agent polls, and webhooks are planned (#61).
  • Some fields are accepted and ignored. spec.placement.mode: sidecar, spec.agent.fsGroup and spec.agent.resources.claims are not built yet, and the condition SpecSupported says so.

Documentation

Topic Page
Get started Quickstart · Credentials · Examples
How the sync behaves Pulling · Local changes and commits · Conflicts · Deletion guard · Echo loops
When something is wrong Recovering from a conflict or a rejected push · Reading the agent's status
Running it Operator replicas · RBAC · Pod Security and file ownership · Metrics and events · Deleting a Treebind
Design decisions Architecture decision records

Contributing

Contributions are welcome, and you do not need to know Kubernetes internals to start. Issues labelled good first issue are self-contained, with named files and an acceptance test. A maintainer gives a first response within three working days.

License

Apache License 2.0. See LICENSE and NOTICE.

About

Kubernetes operator that keeps a Git repository and an application's files in sync through a shared PVC. Declare and Treebind pulls, commits and pushes.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages