ceph-testcontainers-go

module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: MIT

README

ceph-testcontainers-go

Testcontainers for Go modules that run a real, disposable Ceph cluster for integration tests. The cluster runs the official Ceph daemons in containers: one MON, one MGR and two OSDs by default, plus RBD pools, CephFS filesystems with MDS daemons, and RGW gateways when you ask for them. Tests prepare and change the server side through typed Go APIs. Your application talks to the cluster with its own client: go-ceph, librados, librbd, libcephfs, the Ceph CLI or an S3 SDK.

The modules control Ceph through the CLIs inside the containers. They have no go-ceph, librados or cgo dependency and build with CGO_ENABLED=0. The Ceph daemons need no privileged mode, host disks, LVM or systemd: each OSD stores its data in a sparse BlueStore file inside its container by default. MemStore and memory-backed BlueStore are also available for faster disposable fixtures.

Releases follow semantic versioning. Before v1.0.0, a minor release may change the API without aliases for the old names. Final release notes are available with the published releases.

Documentation for a published release is available at its Git tag.

Packages

  • ceph: the cluster. MON, MGR and OSD topology, pools, Cephx identities, configuration, health and diagnostics.
  • rbd: RBD pools and namespaces, image watchers and locks, backup and restore.
    • rbd/mirror: rbd-mirror replication between two clusters.
  • cephfs: filesystems and MDS topology, subvolumes, snapshots and clones, client authorization and sessions.
  • rgw: S3 and Swift gateways, users, accounts and quotas, placement and storage classes.
    • rgw/multisite: realms, zonegroups and zones, period transfer, sync status and sync policy.
  • fault: container pause, network delay, loss, rate, packet faults and endpoint interruption on existing fixtures.
  • override: reversible cluster-wide changes with restoration handles (blocklist, full ratios, MGR modules, OSD flags, debug levels, central configuration, messenger policy).
  • capture: opt-in packet capture on one container endpoint.

Every fixture package is a Testcontainers for Go module with one Run(ctx, image, opts...). In ceph and the service packages it returns a Container that embeds testcontainers.Container; the service packages build on ceph: their Container embeds *ceph.Container, and their options can be passed to ceph.Run together. The two-cluster fixtures start their daemons as Testcontainers containers on two existing clusters: rbd/mirror and cephfs/mirror return a *Mirror that embeds the first mirror daemon's testcontainers.Container, and rgw/multisite returns a *Fixture whose Source and Destination gateways are containers, while the Fixture itself embeds none. fault, override and capture start no fixture of their own; they act on or observe containers that already exist.

Requirements

  • Go 1.26 or later; use a patched toolchain. The repository selects Go 1.26.9 for its own checks. A consumer must select its own toolchain; the toolchain line of this repository does not set it.
  • A Docker engine that runs Linux containers. Docker Desktop works. Host networking has extra requirements, described in the host network guide.
  • Access to pull the Ceph image and the Ryuk image.

The default image is the published, pruned official Tentacle 20.2.4 aggregate, pinned to its AMD64/ARM64 index digest as ceph.DefaultImage. Explicit ceph.ImageSet selections use essential + client for ordinary RADOS/RBD and add CephFS, mirror/cache or RGW images only for those features. Runtime CI uses these dependency roles directly. Squid 19.2.x also works, with the differences listed in the releases guide.

Installation

go get github.com/JSYoo5B/ceph-testcontainers-go/ceph@latest

Add rbd, cephfs or rgw the same way when you need them.

Quick start

package app_test

import (
	"testing"

	"github.com/JSYoo5B/ceph-testcontainers-go/ceph"
	"github.com/testcontainers/testcontainers-go"
)

func TestWithCeph(t *testing.T) {
	ctx := t.Context()
	cluster, err := ceph.Run(ctx, ceph.DefaultImage,
		ceph.WithClusterConfig(ceph.ClusterConfig{}.WithPools(ceph.PoolConfig{Name: "app"})),
	)
	testcontainers.CleanupContainer(t, cluster)
	if err != nil {
		t.Fatal(err)
	}
	if err := cluster.WaitForClean(ctx); err != nil {
		t.Fatal(err)
	}

	// Give a native client the cluster's ceph.conf and an admin keyring.
	cfg, err := cluster.ConnectionConfig(ctx)
	if err != nil {
		t.Fatal(err)
	}
	_ = cfg
}

The service packages start a cluster with their own defaults:

// An initialized RBD pool named rbd.
volumes, err := rbd.Run(ctx, ceph.DefaultImage)

// The filesystem tc-cephfs with one active MDS.
files, err := cephfs.Run(ctx, ceph.DefaultImage)

// One S3 gateway with a generated test user.
objects, err := rgw.Run(ctx, ceph.DefaultImage)
gateways, err := rgw.Gateways(ctx, objects.Container)
if err != nil {
	t.Fatal(err)
}
gateway := gateways[0] // AccessKey, SecretKey and Region
endpoint, err := gateway.S3Endpoint(ctx)

To serve several services from one cluster, pass their options to ceph.Run:

cluster, err := ceph.Run(ctx, ceph.DefaultImage,
	rbd.WithPools(ceph.PoolConfig{Name: "volumes"}),
	cephfs.WithFilesystems(cephfs.Config{Name: "shared"}),
	rgw.WithGateways(rgw.Config{Name: "s3"}),
)

Documentation

Guides for tasks that span packages:

  • API purpose and purpose tags: what the API is for, what each purpose tag means, and how an API declares its tags.
  • Ceph cluster configuration and Ceph cluster operations: the ceph concepts that span several APIs; each API is documented in its godoc.
  • Fault injection: stopping, pausing and disconnecting daemons and clients, delaying or dropping messages, fencing, full clusters and damaged replicas.
  • Host network: bridge and host networking, and connecting native clients from the test process.
  • Releases and images: supported Ceph releases, role images and image requirements.
  • Contexts and cleanup: how contexts bound calls, what each fixture owns, and how to restore temporary changes.
  • Running native commands: how to do anything the typed API does not cover with the Ceph CLIs inside the containers.
  • Fixtures for Messenger client tests: the profiles, daemon controls and differences for testing a Messenger client implementation against native daemons.
  • Classified errors: telling a refused request, a feature the release lacks, a missing image tool, an engine limit and a failed native command apart with errors.Is and errors.As.
  • Bug compatibility: the registered ceph_bug_<id> tags and the policy for adding one.

For contributors:

  • Testing: running and writing unit and integration tests.
  • CI: the GitHub Actions workflows and how to read a failing batch.
  • Preparing a release: the scope, evidence and publication checks for a candidate.

ceph-testcontainers-images checks Ceph images against the requirements of these modules and publishes smaller role images (essential, client, cephfs, rbd-aux, rgw, and the aggregate all) extracted from the official images.

License

The modules are licensed under the MIT License, like Testcontainers for Go.

They do not contain or link Ceph. Tests pull the Ceph container images at run time and run the daemons and CLIs inside them; Ceph in those images is under its own licenses, mainly LGPL-2.1 and LGPL-3.0 with some GPL-2.0 parts. Images that a test selects with ImageOptions.WithImageSet, ImageOptions.WithRGWImage or ImageOptions.WithCephFSImage keep the licenses of whoever publishes them.

Directories

Path Synopsis
Package capture records packets in one container's network namespace with an opt-in packet-capture helper, retrieves the classic pcap file and checks its structure.
Package capture records packets in one container's network namespace with an opt-in packet-capture helper, retrieves the classic pcap file and checks its structure.
Package ceph provisions disposable Ceph clusters using testcontainers-go.
Package ceph provisions disposable Ceph clusters using testcontainers-go.
Package cephfs prepares CephFS server fixtures in disposable Ceph clusters: filesystems and their MDS topology, subvolume groups, subvolumes, snapshots, clones, pins, quiesce sets and client authorization.
Package cephfs prepares CephFS server fixtures in disposable Ceph clusters: filesystems and their MDS topology, subvolume groups, subvolumes, snapshots, clones, pins, quiesce sets and client authorization.
mirror
Package mirror mirrors CephFS snapshots of selected directories from a filesystem in one Ceph cluster to a filesystem in another, with native cephfs-mirror daemons: directory enrollment, peer management, MGR reassignment, process quiescence and typed readiness observation.
Package mirror mirrors CephFS snapshots of selected directories from a filesystem in one Ceph cluster to a filesystem in another, with native cephfs-mirror daemons: directory enrollment, peer management, MGR reassignment, process quiescence and typed readiness observation.
Package fault injects dedicated faults into an existing Ceph fixture.
Package fault injects dedicated faults into an existing Ceph fixture.
internal
apiinventory/catalogue
Package catalogue derives, stores and checks the package-scoped public API catalogues under internal/apiinventory/catalogues.
Package catalogue derives, stores and checks the package-scoped public API catalogues under internal/apiinventory/catalogues.
clusteraccess
Package clusteraccess gives tests one-line access to the context-taking topology accessors of ceph.Container and rgw.
Package clusteraccess gives tests one-line access to the context-taking topology accessors of ceph.Container and rgw.
clustertest
Package clustertest holds unit-test fakes and assertions that package ceph, the service packages and internal/multicluster share.
Package clustertest holds unit-test fakes and assertions that package ceph, the service packages and internal/multicluster share.
clusterutil
Package clusterutil holds small helpers that the cluster implementation and the service packages share: context-bounded locking, polling, operation errors and keyring parsing.
Package clusterutil holds small helpers that the cluster implementation and the service packages share: context-bounded locking, polling, operation errors and keyring parsing.
dockerbridge
Package dockerbridge creates Testcontainers bridges whose allocated subnet can also accept endpoints restored to their original IP on older Engines.
Package dockerbridge creates Testcontainers bridges whose allocated subnet can also accept endpoints restored to their original IP on older Engines.
faulthook
Package faulthook gives fault operations outside package ceph the parts of a ceph.Container that are not public API: the cluster's fault registry, its mutex and the private helpers that fault operations use.
Package faulthook gives fault operations outside package ceph the parts of a ceph.Container that are not public API: the cluster's fault registry, its mutex and the private helpers that fault operations use.
hookreg
Package hookreg holds the hooks that package ceph registers for the rbd, cephfs and rgw packages, for the fault operations, for the override operations, and the hooks that package rgw registers for rgw/multisite.
Package hookreg holds the hooks that package ceph registers for the rbd, cephfs and rgw packages, for the fault operations, for the override operations, and the hooks that package rgw registers for rgw/multisite.
multicluster
Package multicluster holds helpers shared by the cross-cluster fixtures of the rbd, cephfs and rgw packages: ownership of the extra containers and network attachments they create, cluster pair validation, CLI execution and bounded locking.
Package multicluster holds helpers shared by the cross-cluster fixtures of the rbd, cephfs and rgw packages: ownership of the extra containers and network attachments they create, cluster pair validation, CLI execution and bounded locking.
naming
Package naming holds the name patterns the cluster and service packages accept for Ceph resources before passing them to a CLI.
Package naming holds the name patterns the cluster and service packages accept for Ceph resources before passing them to a CLI.
overridehook
Package overridehook gives the override package the parts of a ceph.Container that are not public API: the cluster's registry of held overrides, its mutex and one typed operation per native command.
Package overridehook gives the override package the parts of a ceph.Container that are not public API: the cluster's registry of held overrides, its mutex and one typed operation per native command.
pcapfile
Package pcapfile checks the structure of a classic pcap capture file with bounded reads.
Package pcapfile checks the structure of a classic pcap capture file with bounded reads.
rgwhook
Package rgwhook gives rgw/multisite the parts of the rgw handles that are not public API: whether a gateway can serve a user or placement handle.
Package rgwhook gives rgw/multisite the parts of the rgw handles that are not public API: whether a gateway can serve a user or placement handle.
servicehook
Package servicehook gives the rbd, cephfs and rgw packages the parts of a ceph.Container that are not public API, such as its mutex and Run-time provisioning.
Package servicehook gives the rbd, cephfs and rgw packages the parts of a ceph.Container that are not public API, such as its mutex and Run-time provisioning.
strictjson
Package strictjson reads native Ceph JSON without the silent choices of encoding/json.
Package strictjson reads native Ceph JSON without the silent choices of encoding/json.
supervised
Package supervised runs a command inside a container under a Python supervisor that bounds its run time and output, and that a canceled caller can stop without leaving the command behind.
Package supervised runs a command inside a container under a Python supervisor that bounds its run time and output, and that a canceled caller can stop without leaving the command behind.
testhelper
Package testhelper gives unit tests of the ceph, rbd, cephfs, rgw, fault, override and internal packages the synthetic cluster constructor, the privileged state accessors and the registry snapshots they need.
Package testhelper gives unit tests of the ceph, rbd, cephfs, rgw, fault, override and internal packages the synthetic cluster constructor, the privileged state accessors and the registry snapshots they need.
tools/apinaming command
Command apinaming maintains the package-scoped API catalogues under internal/apiinventory/catalogues.
Command apinaming maintains the package-scoped API catalogues under internal/apiinventory/catalogues.
tools/batchselect command
Command batchselect reports which test batches of one package a change can affect.
Command batchselect reports which test batches of one package a change can affect.
tools/lintcalibration command
Command lintcalibration runs the metric linters of issue #226 (cyclop, dupl, funlen, gocognit) through golangci-lint with a report-only configuration that keeps every diagnostic, and prints them grouped by source location.
Command lintcalibration runs the metric linters of issue #226 (cyclop, dupl, funlen, gocognit) through golangci-lint with a report-only configuration that keeps every diagnostic, and prints them grouped by source location.
tools/messengercases command
Command messengercases indexes top-level integration test declarations and their literal log markers.
Command messengercases indexes top-level integration test declarations and their literal log markers.
tools/structmetrics command
Command structmetrics reports a fixed structural measurement of named struct types: declared methods (split by exported-name and private) and direct fields per type, for chosen package directories of one source snapshot, and the per-type difference between a base and a head snapshot.
Command structmetrics reports a fixed structural measurement of named struct types: declared methods (split by exported-name and private) and direct fields per type, for chosen package directories of one source snapshot, and the per-type difference between a base and a head snapshot.
tools/tagcatalog command
Command tagcatalog reads test declarations and build expressions without importing or executing packages from the repository it inspects.
Command tagcatalog reads test declarations and build expressions without importing or executing packages from the repository it inspects.
tools/testdoublecheck command
Command testdoublecheck checks, without Docker, that every test double and test-only access point of the module says what it is, next to its declaration.
Command testdoublecheck checks, without Docker, that every test double and test-only access point of the module says what it is, next to its declaration.
tools/testsupportcheck command
Command testsupportcheck checks, without Docker, the import, seam and declaration boundary of the repository's test-only code: which packages may import the shared test helpers, which files may read the unit seam, and which declarations may appear in non-test files.
Command testsupportcheck checks, without Docker, the import, seam and declaration boundary of the repository's test-only code: which packages may import the shared test helpers, which files may read the unit seam, and which declarations may appear in non-test files.
Package override changes one cluster-wide setting of a ceph.Container for a while and puts it back.
Package override changes one cluster-wide setting of a ceph.Container for a while and puts it back.
rbd
Package rbd prepares RBD server fixtures in disposable Ceph clusters: initialized image pools, namespaces and full or incremental backup transport.
Package rbd prepares RBD server fixtures in disposable Ceph clusters: initialized image pools, namespaces and full or incremental backup transport.
internal/resourcename
Package resourcename validates the pool, namespace and image names accepted by standalone RBD operations.
Package resourcename validates the pool, namespace and image names accepted by standalone RBD operations.
mirror
Package mirror connects two Ceph clusters with native RBD mirroring: setup CLI containers, one-way pool or image mirroring in snapshot or journal mode, any number of rbd-mirror receiver daemons, and typed readiness observation.
Package mirror connects two Ceph clusters with native RBD mirroring: setup CLI containers, one-way pool or image mirroring in snapshot or journal mode, any number of rbd-mirror receiver daemons, and typed readiness observation.
rgw
Package rgw prepares RADOS Gateway fixtures in disposable Ceph clusters: gateways, S3 users, tenants and accounts, quotas, placement targets and storage classes, and native TLS.
Package rgw prepares RADOS Gateway fixtures in disposable Ceph clusters: gateways, S3 users, tenants and accounts, quotas, placement targets and storage classes, and native TLS.
multisite
Package multisite orchestrates RGW multisite fixtures across independent Ceph clusters: one realm, zones and zonegroups, period transfer, sync status and sync policies.
Package multisite orchestrates RGW multisite fixtures across independent Ceph clusters: one realm, zones and zonegroups, period transfer, sync status and sync policies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL