Skip to content

Latest commit

 

History

History
216 lines (161 loc) · 8.32 KB

README.md

File metadata and controls

216 lines (161 loc) · 8.32 KB

kit - Kubernetes Integration Testing

This is a proof of concept built with the help of Claude. It is not intended for production use. The final version may differ entirely from what is currently in this repository.

Lightweight tool for creating simulated Kubernetes clusters using kwok and deploying OpenShift components into them. Workload pods run as real containers via podman, while the control plane is simulated.

Prerequisites

  • Go 1.26+
  • podman (rootless)
  • kwokctl is downloaded automatically on first use

Build

make all       # build the binary to ./bin/kit
make clean     # remove build artifacts

Usage

kit runs as a daemon that manages cluster lifecycle via gRPC.

Starting and stopping the daemon

./bin/kit start              # start the daemon in the background
./bin/kit start --foreground # start in the foreground (useful for debugging)
./bin/kit stop               # stop the daemon

Before launching a new version of kit, make sure the old daemon is stopped:

./bin/kit stop
make all
./bin/kit start

Daemon logs

./bin/kit logs        # show recent logs
tail -f ~/.local/share/openshift-kit/daemon.log

Creating a cluster

There are two providers: kwok (lightweight, simulated control plane) and kind (full Kubernetes cluster via kind).

kwok (default)

./bin/kit cluster create test-cluster \
  --pull-secret ~/mco-dev/pull-secret

kind

./bin/kit cluster create test-cluster \
  --provider kind \
  --pull-secret ~/mco-dev/pull-secret \
  --workers 2

Kubernetes version

Both providers accept --kube-version to pin the Kubernetes version of the cluster control plane, either a minor (e.g. v1.36) or an exact version (e.g. v1.36.4). The version the control plane ends up running is reported in KitCluster.status.kubeVersion.

Deploying operators

Operator deployment is driven by KitCluster spec and DeploymentPlan resources. The simplest path is passing the release image and the kit CRs (deployment plans, resource collections) directly to create: the cluster comes up with everything applied and ready, in one command.

./bin/kit cluster create test-cluster \
  --pull-secret ~/mco-dev/pull-secret \
  --image quay.io/openshift-release-dev/ocp-release:5.0.0-x86_64 \
  --feature-set TechPreviewNoUpgrade \
  -f deploymentplan.yaml

-f is repeatable and accepts a file, a directory, or - for stdin; each may contain several YAML documents. By default the command waits until the applied resources report Ready (--no-wait skips the wait, --timeout bounds it). Only kit CRs are accepted: kit CRDs are installed by the controller during bootstrap and payload CRDs come from the release image, so neither is passed as a resource.

On failure the cluster is left running for debugging; destroy it with kit cluster destroy.

A DeploymentPlan declares an ordered sequence of steps. Each step is either a ResourceCollection (rendered templates) or a set of manifests filtered from the release image:

apiVersion: kit.openshift.io/v1alpha1
kind: DeploymentPlan
metadata:
  name: mco-deployment
spec:
  steps:
    - name: default-collection
      collection:
        source: openshift-default
    - name: mco-collection
      collection:
        source: openshift-mco
    - name: machine-config-operator
      release:
        filenameRegex: machine-config

Interacting with the cluster

export KUBECONFIG=$(./bin/kit cluster kubeconfig test-cluster)
kubectl get pods -A
kubectl logs -n openshift-machine-config-operator <pod-name>

Destroying a cluster

./bin/kit cluster destroy test-cluster

Using kit from Go

The CLI is a thin wrapper over the public client package, github.com/openshift-eng/kubernetes-integration-testing/daemon/client. Add it with:

go get github.com/openshift-eng/kubernetes-integration-testing/daemon/client@main

It connects to the daemon (starting it if needed) and offers the same operations:

import "github.com/openshift-eng/kubernetes-integration-testing/daemon/client"

c, err := client.Connect(ctx)
if err != nil {
    return err
}
defer func() { _ = c.Close() }()

cl, err := c.Create(ctx,
    client.WithName("test-cluster"),
    client.WithPullSecret("/path/to/pull-secret"),
    client.WithResources(client.FromFS(manifests, "deploymentplan.yaml")),
)
// cl.Kubeconfig is the path of the cluster kubeconfig file, and
// cl.Applied lists the resources applied at creation.

where manifests is an embed.FS (//go:embed), so a suite ships its kit CRs inside the binary. client.FromFiles and client.FromString are available for paths and inline manifests.

Connect starts the daemon if needed and only returns once the daemon answers RPCs, so a returned Client is ready to use. Set a deadline on the context to bound the wait.

Programs that are not the kit binary itself (for example test binaries) must tell the client where to find the kit executable to spawn the daemon: set KIT_BINARY or pass client.WithBinary(path).

Module layout

The repository is a multi-module workspace.

Module Holds Depends on
daemon The daemon's public surface: the gRPC API it serves (daemon/grpc), the on-disk state layout that locates a running instance (daemon/state), and the client that drives it (daemon/client). No validation rules, no Kubernetes dependencies. —
api The kit CR types (KitCluster, DeploymentPlan, ResourceCollection, Agent...) and the CRD manifests generated from them. Kubernetes API machinery
root The daemon implementation, CLI, controller and agent. both of the above

The split exists so that consuming the client stays cheap: a test suite that imports it pulls grpc and little else instead of client-go, controller-runtime and the rest of the Kubernetes API machinery.

Suites that want to author kit CRs with Go types instead of YAML can additionally import api, which is where the Kubernetes dependencies come from, and serialize the result through client.FromBytes.

Neither published module depends on another module of this repository, and that is deliberate. An intra-repository dependency would have to name a version, which a local replace never provides, so consumers would need release tags to resolve it. As it stands they can fetch straight from a branch, which matches how kit is shipped:

go get github.com/openshift-eng/kubernetes-integration-testing/daemon/client@main
go get github.com/openshift-eng/kubernetes-integration-testing/api@main

The root module is wired to the other two with local replace directives so it always builds from the working tree. Nothing outside this repository consumes it, so the placeholder versions those replaces produce never reach anyone.

The daemon validates every request it serves, and the client forwards arguments untouched rather than checking them itself. Nothing the daemon decides, such as which cluster names and Kubernetes versions are accepted, is duplicated client-side, so a client and a daemon built from different revisions can never disagree about what is valid.

Each module forbids the ones it must not depend on by replacing them with a path that does not exist, so an accidental import fails with an explicit error instead of quietly reaching consumers.

Architecture

  • kwok simulates the Kubernetes control plane (etcd, API server, controller-manager, scheduler) as podman containers on a shared podman network.
  • kit controller watches for pods claimed by kwok fake nodes and starts real containers for them via podman.
  • Service DNS is provided by podman's aardvark-dns: each pod gets --network-alias entries matching Kubernetes service DNS conventions (<svc>.<ns>.svc.cluster.local).
  • Volume materialization: Secrets and ConfigMaps are fetched from the API and bind-mounted into containers.
  • Service certificates: a controller-runtime reconciler watches Services with the service.beta.openshift.io/serving-cert-secret-name annotation and auto-generates TLS secrets, replicating the OpenShift service-ca-operator behavior.
  • DeploymentPlan: an ordered pipeline of collection and release steps with automatic retry on failure.
  • ResourceCollection: templated Kubernetes manifests with cert helper functions, rendered and applied by the collection reconciler.