Skip to main content

k8s-st8

A lightweight Python library defining a declarative language for describing Kubernetes cluster state transitions in YAML. Operations move the cluster from state to state and define a state graph. The state graph may be reversed for reversible operations.

Setup

Install pyenv and pyenv-virtualenv, then run:

./setup.sh

Setup uses Python 3.13 and a pyenv virtualenv named k8s-st8. It compiles requirements.in and requirements-dev.in into corresponding .txt files via pip-tools. ./update-deps.sh can be run if new dependencies are added. The .python-version file selects the virtualenv.

Test

Tests are written using pytest and run from the project route as follows:

pytest

Publishing

Set the TWINE_USERNAME and TWINE_PASSWORD environment variables and publish to TestPyPI or PyPI:

./publish.sh testpypi
./publish.sh pypi

Language

See examples/upgrade.yaml. A version 1 document has a name and an ordered list of steps. Each step has a unique id, a command, an explicit recovery contract, a nonempty impact list, and optional depends_on IDs. Dependencies may refer forward; a stable topological order uses the earliest ready step in the file. Add dependencies wherever ordering matters; independent steps have no implied dependency.

For a hands-on Helm installation, reversal, configuration change, and backup-based recovery on a disposable kind cluster, see the kind walkthrough.

Commands:

  • set assigns a JSON-compatible value to a string target in the managed state projection. Use a target convention such as helm/namespace/release, resource/namespace/kind/name, or config/namespace/name/key. Values can describe chart versions, Kubernetes objects, or configuration.
  • delete removes a target from the projection, including when it is absent.
  • action describes an operation outside the projection, using target as a human-readable description, for example a cluster upgrade or migration.

Recovery is an author-declared contract: reversible, compensatable, or irreversible. It is not inferred or verified. For set and delete, the default recovery restores the previous projected value or its absence. An optional undo string overrides this with a human-described recovery action. Reversible and compensatable action steps require an undo description. Irreversible steps require a snapshot string describing the prerequisite backup or snapshot; this is only a declaration, not proof it exists, covers the effects, or can be restored. An irreversible step cannot declare undo. Impacts are workload, configuration, persistent_data, infrastructure, and traffic. Declare all relevant impacts and choose recovery conservatively: restoring a Helm value or traffic setting need not reverse hooks, requests, controller behavior, or persistent and external side effects.

Python API

from k8s_st8 import load_plan, preview, state_hash

plan = load_plan("examples/upgrade.yaml")
result = preview(plan, {"traffic/production/payments": {"version": "v3", "weight_percent": 100}})
for step in result.steps:
    print(step.id, step.before_hash, step.after_hash, step.snapshot)
for step in result.recovery:
    print(step.step_id, step.command, step.target)
print(result.recovery_complete, state_hash(result.final_state))

The preview assumes all steps succeeded; it is not an execution log and does not model partial failures. Recovery runs in reverse order and stops at the first irreversible step, which appears as a manual boundary. A complete recovery list means only that no such boundary was encountered, not that recovery will succeed. No-op projection changes still appear as steps; an unchanged hash does not imply an action had no real-world effects.

Hashes are SHA-256 of canonical JSON for the entire supplied managed-state projection (sorted keys, compact UTF-8 JSON); only finite JSON values with string mapping keys are supported. Equal projections have equal hashes, including no-op sets/deletes and a projection restored to its prior value. Hashes are not cluster fingerprints: unmodeled objects, data, side effects, and drift are invisible. YAML mapping keys must be unique strings, and YAML values such as timestamps must be quoted to remain JSON-compatible strings. Plans may contain sensitive values: protect plans, state, and previews accordingly.

Metadata

Release files for k8s-st8 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k8s-st8 0.0.0
File Size Uploaded Provenance Actions
k8s_st8-0.0.0.tar.gz 22.2 kB Without provenance Details for k8s_st8-0.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for k8s-st8 0.0.0
File Interpreter ABI Platform Actions
k8s_st8-0.0.0-py3-none-any.whl Python 3 none any Details for k8s_st8-0.0.0-py3-none-any.whl

Total release size: 41.7 kB

Release files / k8s_st8-0.0.0.tar.gz

Download URL k8s_st8-0.0.0.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a584c6e544f87d750510cee98d177ee7c904f066f65043f5d48cd482c22c4e21
BLAKE2b-256 checksum
How to use checksums
cdbe2c0d613f1b609e31d2e518ebae738687751344f7566813b78a77fa9a4319
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / k8s_st8-0.0.0-py3-none-any.whl

Download URL k8s_st8-0.0.0-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bc510e4cef1ef8393798890b20203f5dfea8d862203919129aa9376333c5dde
BLAKE2b-256 checksum
How to use checksums
d45f23462283aa62a6c75f9546ff632a8f073725ae66151d84b18a4d75f1670c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for k8s-st8 0.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page