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 ¶
- type Puller
- type Registry
- func (r *Registry) BlobExists(ctx context.Context, digest string) (bool, error)
- func (r *Registry) BlobSize(ctx context.Context, digest string) (int64, error)
- func (r *Registry) DeleteBlob(ctx context.Context, digest string) error
- func (r *Registry) DeleteManifest(ctx context.Context, name, tag string) error
- func (r *Registry) GetCatalog(ctx context.Context) (*manifest.Catalog, error)
- func (r *Registry) ListTags(ctx context.Context, name string) ([]string, error)
- func (r *Registry) ManifestJSON(ctx context.Context, name, tag string) ([]byte, error)
- func (r *Registry) Pull(ctx context.Context, paths *cocoon.Paths, name, tag string, ...) (*manifest.Manifest, error)
- func (r *Registry) PullBlob(ctx context.Context, digest, destPath string) error
- func (r *Registry) PullManifest(ctx context.Context, name, tag string) (*manifest.Manifest, error)
- func (r *Registry) Push(ctx context.Context, paths *cocoon.Paths, snapshotName, tag string, ...) (*manifest.Manifest, error)
- func (r *Registry) PushBlob(ctx context.Context, filePath string) (string, int64, error)
- func (r *Registry) PushBlobFromStream(ctx context.Context, digest string, body io.Reader, size int64) error
- func (r *Registry) PushManifest(ctx context.Context, m *manifest.Manifest) error
- func (r *Registry) PushManifestJSON(ctx context.Context, name, tag string, data []byte) error
- func (r *Registry) StreamBlob(ctx context.Context, digest string) (io.ReadCloser, int64, error)
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 ¶
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 ¶
EnsureSnapshot ensures a snapshot is available locally. If not present, pulls it from Epoch. Thread-safe and idempotent.
func (*Puller) EnsureSnapshotTag ¶
EnsureSnapshotTag ensures a specific tag of a snapshot is available locally.
func (*Puller) ListRemote ¶
ListRemote returns all repositories in the remote registry.
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 ¶
NewFromConfigMap creates a registry using object store credentials from a k8s ConfigMap.
func NewFromEnv ¶
NewFromEnv creates a registry using object store credentials from the environment.
func (*Registry) BlobExists ¶
BlobExists checks if a blob exists in the registry.
func (*Registry) DeleteBlob ¶
DeleteBlob removes a blob from the object store.
func (*Registry) DeleteManifest ¶
DeleteManifest removes a manifest.
func (*Registry) GetCatalog ¶
GetCatalog returns the global catalog.
func (*Registry) ManifestJSON ¶
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 ¶
PullBlob downloads a blob to a local file. Handles both regular and split (>5GB) blobs transparently.
func (*Registry) PullManifest ¶
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 ¶
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 ¶
PushManifest uploads a manifest for name:tag.
func (*Registry) PushManifestJSON ¶
PushManifestJSON uploads a manifest from raw JSON bytes and updates the catalog.
func (*Registry) StreamBlob ¶
StreamBlob returns a streaming reader for a blob from object storage. Caller must close the returned ReadCloser.