scratchnamespace

package
v0.1.0-c02.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Restore scratch namespace lifecycle

scratchnamespace provides the portable Kubernetes namespace lifecycle for an isolated restore. The caller supplies its existing durable operation checkpoint store, a Kubernetes runner, clock, and context-aware wait function. It must hold one exclusive operation lock across create, restore work, and cleanup. The package does not introduce a second journal or select an installation, credential source, backup target, or production namespace.

Create first proves absence and persists a create intent with the operation, approval scope, required labels, and a random nonce. It server-dry-runs the manifest, creates the namespace, and records the returned UID/resourceVersion. A lost or malformed create response is reconciled by reading the namespace and matching the durable nonce and ownership fields. A previously recorded UID cannot be replaced on replay.

Register cleanup before calling Create. Cleanup can recover the uncertain create window from the persisted intent after a process restart. It verifies the current namespace's original UID and ownership, journals the current resourceVersion, and submits a foreground raw API delete with both UID and resourceVersion preconditions. A conflict leaves its intent intact; a later replay may journal a fresh version of the same original UID. It never removes the source backup or deletes a replacement namespace.

Completion requires two successful namespace-absence reads separated by at least 30 seconds, followed by a durable cleanup receipt. Replay returns that receipt only if the namespace is still absent. Missing or conflicting state, failed reads, ownership drift, a replaced UID, and failed quiet windows remain errors. Labels stored in the original create intent remain required for cleanup; callers cannot relax them by passing different labels later.

This receipt proves the namespace lifecycle. Callers must separately verify restored data, backup retention, network isolation, applicable volume/PV and provider-resource cleanup, and installation health. A removed namespace alone does not establish those outcomes.

Documentation

Overview

Package scratchnamespace owns one isolated restore namespace through a durable create fence and exact Kubernetes deletion preconditions. It never adopts a namespace using its name alone. Callers supply their existing operation checkpoint store and retain it until cleanup is verified.

Index

Constants

View Source
const (
	QuietWindow = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding

type Binding struct {
	OperationID string `json:"operationId"`
	Namespace   string `json:"namespace"`
	ScopeSHA256 string `json:"scopeSha256"`
}

type CleanupReceipt

type CleanupReceipt struct {
	StartedAt                  string  `json:"startedAt"`
	CompletedAt                string  `json:"completedAt"`
	Complete                   bool    `json:"complete"`
	TwoSweepQuietWindowSeconds int     `json:"twoSweepQuietWindowSeconds"`
	Sweeps                     []Sweep `json:"sweeps"`
}

func Cleanup

func Cleanup(ctx context.Context, opts Options) (CleanupReceipt, error)

Cleanup can be called after Create returns any error, or from a later cleanup-only invocation after process death. A missing create intent never authorizes deletion. The latest resourceVersion is journaled before each exact delete, so legitimate status updates can be handled on a later replay without weakening the original UID fence.

type Identity

type Identity struct {
	Name            string `json:"name"`
	UID             string `json:"uid"`
	ResourceVersion string `json:"resourceVersion"`
}

func Create

func Create(ctx context.Context, opts Options) (Identity, error)

Create persists the namespace manifest identity before submitting a create. On replay or an uncertain response, it adopts only the matching durable random nonce and approval scope; an already checkpointed UID cannot change.

type Options

type Options struct {
	Binding Binding
	Labels  map[string]string
	State   State
	Runner  Runner
	Now     func() time.Time
	Sleep   func(context.Context, time.Duration) error
}

type Runner

type Runner interface {
	Run(context.Context, []string, []byte) ([]byte, error)
}

type State

type State interface {
	Checkpoint(string) (json.RawMessage, bool, error)
	WriteCheckpoint(string, json.RawMessage) error
}

State is satisfied by the adapter's write-once, fsync-backed checkpoint store. WriteCheckpoint must reject a different value at an existing name. Callers must serialize users of one operation's state, including cleanup.

type Sweep

type Sweep struct {
	ObservedAt      string `json:"observedAt"`
	InventorySHA256 string `json:"inventorySha256"`
	NamespaceCount  int    `json:"namespaceCount"`
}

Jump to

Keyboard shortcuts

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