/podsmith

Podsmith is a Python toolkit for managing Kubernetes-based test dependencies, enabling dynamic or pre-provisioned environments for integration testing.

Primary LanguagePythonMIT LicenseMIT

Podsmith

Podsmith is a Python toolkit for managing Kubernetes-based test dependencies, enabling dynamic or pre-provisioned environments for integration testing.

Inspired by (and supports using) Testcontainers, Podsmith lets you define service dependencies as code and run your tests locally or remotely, with full control over whether resources are deployed on-the-fly or expected to be pre-provisioned.


โœจ Features

  • ๐Ÿ›  Deploy Kubernetes resources from Python definitions
  • ๐Ÿ” Optionally reuse existing resources
  • โณ Built-in support for readiness checks (e.g., pod status, HTTP, service endpoints)
  • ๐Ÿงช Integrates with pytest
  • ๐Ÿš€ Works with local clusters (e.g., k3s, kind) or remote (using kubectl)

โœจ Planned Features

  • ๐Ÿ“ฆ Snapshot current test environment for reusable kubernetes manifests
  • ๐Ÿณ Pre-build test images locally for publishing to pre-populate a docker registry.

๐Ÿ”ง Installation

pip install podsmith

๐Ÿš€ Quickstart

Simple example to deploy a redis testcontainer as a Kubernetes Pod.

from podsmith import Pod
from testcontainers.redis import RedisContainer

redis_container = RedisContainer()

with Pod("redis").with_testcontainer(redis_container, service_port_map={redis_container.port: "redis"}) as redis:
    # Port-forward from k8s cluster to localhost, only needed if test needs to connect to the service directly.
    with redis.port_forward("redis") as port:
        url = f"redis://127.0.0.1:{port}"
        # Use redis service in your test

This example deploys a redis pod using a testcontainer as template, and register a Service manifest for the redis service port. When the context manager exits, the pod is deleted.


๐Ÿ“ธ (Planned) Snapshot Test Manifests

WIP -- AI generated example, not accurate.

Generate a manifest snapshot of your test environment:

podsmith snapshot --namespace test-env --output ./snapshots/

Apply in CI:

kubectl apply -f ./snapshots/

๐Ÿ“š (Wishful thinking) Documentation


๐Ÿ“ License

MIT License


๐Ÿค Contributing

Contributions, ideas, and bug reports are welcome! Please open an issue or PR on GitHub.