cache

package
v0.0.0-...-5272525 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

This package implements an image metadata cache given a backing k-v store.

The interface `Client` stands in for the k-v store (e.g., memcached, in the subpackage); `Cache` implements registry.Registry given a `Client`.

The `Warmer` is for continually refreshing the cache by fetching new metadata from the original image registries.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotCached = &fluxerr.Error{
		Type: fluxerr.Missing,
		Err:  errors.New("item not in cache"),
		Help: `Image not yet cached

It takes time to initially cache all the images. Please wait.

If you have waited for a long time, check the Flux logs. Potential
reasons for the error are: no internet, no cache, error with the remote
repository.
`,
	}
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Reader     Reader
	Decorators []Decorator
}

Cache is a local cache of image metadata.

func (*Cache) GetImage

func (c *Cache) GetImage(id image.Ref) (image.Info, error)

GetImage gets the manifest of a specific image ref, from its registry.

func (*Cache) GetImageRepositoryMetadata

func (c *Cache) GetImageRepositoryMetadata(id image.Name) (image.RepositoryMetadata, error)

GetImageRepositoryMetadata returns the metadata from an image repository (e.g,. at "docker.io/fluxcd/flux")

type Client

type Client interface {
	Reader
	Writer
}

func InstrumentClient

func InstrumentClient(c Client) Client

type Decorator

type Decorator interface {
	// contains filtered or unexported methods
}

Decorator is for decorating an ImageRepository before it is returned.

type ImageRepository

type ImageRepository struct {
	image.RepositoryMetadata
	LastError  string
	LastUpdate time.Time
}

ImageRepository holds the last good information on an image repository.

Whenever we successfully fetch a set (partial or full) of image metadata, `LastUpdate`, `Tags` and `Images` shall each be assigned a value, and `LastError` will be cleared.

If we cannot for any reason obtain the set of image metadata, `LastError` shall be assigned a value, and the other fields left alone.

It's possible to have all fields populated: this means at some point it was successfully fetched, but since then, there's been an error. It's then up to the caller to decide what to do with the value (show the images, but also indicate there's a problem, for example).

type Keyer

type Keyer interface {
	Key() string
}

An interface to provide the key under which to store the data Use the full path to image for the memcache key because there might be duplicates from other registries

func NewManifestKey

func NewManifestKey(image image.CanonicalRef) Keyer

func NewRepositoryKey

func NewRepositoryKey(repo image.CanonicalName) Keyer

type Reader

type Reader interface {
	// GetKey gets the value at a key, along with its refresh deadline
	GetKey(k Keyer) ([]byte, time.Time, error)
}

type StringSet

type StringSet map[string]struct{}

StringSet is a set of strings.

func NewStringSet

func NewStringSet(ss []string) StringSet

NewStringSet returns a StringSet containing exactly the strings given as arguments.

func (StringSet) Subset

func (s StringSet) Subset(t StringSet) bool

Subset returns true if `s` is a subset of `t` (including the case of having the same members).

type TimestampLabelWhitelist

type TimestampLabelWhitelist []string

TimestampLabelWhitelist contains a string slice of glob patterns. Any canonical image reference that matches one of the glob patterns will prefer creation timestamps from labels over the one it received from the registry.

type Warmer

type Warmer struct {
	Trace    bool
	Priority chan image.Name
	Notify   func()
	// contains filtered or unexported fields
}

Warmer refreshes the information kept in the cache from remote registries.

func NewWarmer

func NewWarmer(cf registry.ClientFactory, cacheClient Client, burst int) (*Warmer, error)

NewWarmer creates cache warmer that (when Loop is invoked) will periodically refresh the values kept in the cache.

func (*Warmer) Loop

func (w *Warmer) Loop(logger log.Logger, stop <-chan struct{}, wg *sync.WaitGroup, imagesToFetchFunc func() registry.ImageCreds)

Loop continuously gets the images to populate the cache with, and populate the cache with them.

type Writer

type Writer interface {
	// SetKey sets the value at a key, along with its refresh deadline
	SetKey(k Keyer, deadline time.Time, v []byte) error
}

Directories

Path Synopsis
This package implements an image DB cache using memcached.
This package implements an image DB cache using memcached.

Jump to

Keyboard shortcuts

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