registry

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package registry implements the Epoch snapshot registry backed by an S3-compatible object store.

vk-cocoon Integration

vk-cocoon imports this package to automatically pull snapshots before cloning VMs.

Setup in vk-cocoon's main.go or provider initialization:

import "github.com/cocoonstack/epoch/registry"

// Create puller — reads object store settings from a k8s ConfigMap.
puller, err := registry.NewPuller("/var/lib/cocoon", "prod", "agent-env")
if err != nil {
    log.WithFunc("main").Fatalf(ctx, err, "epoch puller: %v", err)
}

// Pre-warm known snapshots at startup (non-blocking).
puller.PreWarm(ctx, []string{"sre-agent-bot", "sre-agent-diagnosis"})

In the provider's CreatePod, before calling `cocoon vm clone`:

// Ensure snapshot is available locally before cloning.
if err := puller.EnsureSnapshot(ctx, image); err != nil {
    return fmt.Errorf("epoch ensure %s: %w", image, err)
}
// Now safe to: cocoon vm clone --cold <image>

The Puller is thread-safe, idempotent, and caches pull results. Subsequent calls for the same snapshot return immediately.

Package registry implements the Epoch snapshot registry backed by an S3-compatible object store.

It handles push/pull of Cocoon snapshots as content-addressable artifacts:

  • Blobs are stored at epoch/blobs/sha256/{digest}
  • Manifests at epoch/manifests/{name}/{tag}.json
  • Catalog at epoch/catalog.json

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Puller

type Puller struct {
	// contains filtered or unexported fields
}

Puller is a high-level helper for vk-cocoon integration. It provides automatic snapshot pulling with caching and pre-warming.

func NewPuller

func NewPuller(cocoonRootDir, namespace, configmap string) (*Puller, error)

NewPuller creates a Puller for use by vk-cocoon. It reads object store credentials from the given k8s ConfigMap.

func NewPullerFromConfig

func NewPullerFromConfig(cfg *objectstore.Config, cocoonRootDir string) (*Puller, error)

NewPullerFromConfig creates a Puller with explicit object store config.

func (*Puller) EnsureSnapshot

func (p *Puller) EnsureSnapshot(ctx context.Context, name string) error

EnsureSnapshot ensures a snapshot is available locally. If not present, pulls it from Epoch. Thread-safe and idempotent.

func (*Puller) EnsureSnapshotTag

func (p *Puller) EnsureSnapshotTag(ctx context.Context, name, tag string) error

EnsureSnapshotTag ensures a specific tag of a snapshot is available locally.

func (*Puller) ListRemote

func (p *Puller) ListRemote(ctx context.Context) ([]string, error)

ListRemote returns all repositories in the remote registry.

func (*Puller) PreWarm

func (p *Puller) PreWarm(ctx context.Context, snapshots []string)

PreWarm pulls multiple snapshots concurrently at startup. Non-blocking — runs in the background.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is the Epoch snapshot registry.

func New

func New(client *objectstore.Client) *Registry

New creates a registry backed by the given object store client.

func NewFromConfigMap

func NewFromConfigMap(namespace, configmap string) (*Registry, error)

NewFromConfigMap creates a registry using object store credentials from a k8s ConfigMap.

func NewFromEnv

func NewFromEnv() (*Registry, error)

NewFromEnv creates a registry using object store credentials from the environment.

func (*Registry) BlobExists

func (r *Registry) BlobExists(ctx context.Context, digest string) (bool, error)

BlobExists checks if a blob exists in the registry.

func (*Registry) BlobSize

func (r *Registry) BlobSize(ctx context.Context, digest string) (int64, error)

BlobSize returns the actual size of a blob.

func (*Registry) DeleteBlob

func (r *Registry) DeleteBlob(ctx context.Context, digest string) error

DeleteBlob removes a blob from the object store.

func (*Registry) DeleteManifest

func (r *Registry) DeleteManifest(ctx context.Context, name, tag string) error

DeleteManifest removes a manifest.

func (*Registry) GetCatalog

func (r *Registry) GetCatalog(ctx context.Context) (*manifest.Catalog, error)

GetCatalog returns the global catalog.

func (*Registry) ListTags

func (r *Registry) ListTags(ctx context.Context, name string) ([]string, error)

ListTags returns all tags for a repository.

func (*Registry) ManifestJSON

func (r *Registry) ManifestJSON(ctx context.Context, name, tag string) ([]byte, error)

ManifestJSON returns the raw JSON bytes of a manifest without parsing.

func (*Registry) Pull

func (r *Registry) Pull(ctx context.Context, paths *cocoon.Paths, name, tag string, progress func(string)) (*manifest.Manifest, error)

Pull downloads a snapshot from Epoch and writes it to Cocoon's snapshot directory.

func (*Registry) PullBlob

func (r *Registry) PullBlob(ctx context.Context, digest, destPath string) error

PullBlob downloads a blob to a local file. Handles both regular and split (>5GB) blobs transparently.

func (*Registry) PullManifest

func (r *Registry) PullManifest(ctx context.Context, name, tag string) (*manifest.Manifest, error)

PullManifest downloads and parses a manifest.

func (*Registry) Push

func (r *Registry) Push(ctx context.Context, paths *cocoon.Paths, snapshotName, tag string, progress func(string)) (*manifest.Manifest, error)

Push uploads a Cocoon snapshot to the Epoch registry.

func (*Registry) PushBlob

func (r *Registry) PushBlob(ctx context.Context, filePath string) (string, int64, error)

PushBlob uploads a file as a content-addressable blob. Returns the SHA-256 hex digest and size. Computes the hash in a single pass using io.TeeReader to avoid reading the file twice.

func (*Registry) PushBlobFromStream

func (r *Registry) PushBlobFromStream(ctx context.Context, digest string, body io.Reader, size int64) error

PushBlobFromStream uploads a blob from a stream. The digest must be pre-computed by the caller. For large files (>4GB), it spools to a temp file and uses multipart upload.

func (*Registry) PushManifest

func (r *Registry) PushManifest(ctx context.Context, m *manifest.Manifest) error

PushManifest uploads a manifest for name:tag.

func (*Registry) PushManifestJSON

func (r *Registry) PushManifestJSON(ctx context.Context, name, tag string, data []byte) error

PushManifestJSON uploads a manifest from raw JSON bytes and updates the catalog.

func (*Registry) StreamBlob

func (r *Registry) StreamBlob(ctx context.Context, digest string) (io.ReadCloser, int64, error)

StreamBlob returns a streaming reader for a blob from object storage. Caller must close the returned ReadCloser.

Jump to

Keyboard shortcuts

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