storage

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAmbiguousFind is returned when the user requested one object from a List+Filter process.
	ErrAmbiguousFind = errors.New("two or more results were aquired when one was expected")
	// ErrNotFound is returned when the requested resource wasn't found.
	ErrNotFound = errors.New("resource not found")
	// ErrAlreadyExists is returned when when WriteStorage.Create is called for an already stored object.
	ErrAlreadyExists = errors.New("resource already exists")
)

ContentTypes describes the connection between file extensions and a content types.

View Source
var (
	// ErrNotTracked is returned when the requested resource wasn't found.
	ErrNotTracked = fmt.Errorf("untracked object: %w", ErrNotFound)
)

Functions

func DecodePartialObjects

func DecodePartialObjects(rc io.ReadCloser, scheme *kruntime.Scheme, allowMultiple bool, defaultGVK *schema.GroupVersionKind) ([]runtime.PartialObject, error)

DecodePartialObjects reads any set of frames from the given ReadCloser, decodes the frames into PartialObjects, validates that the decoded objects are known to the scheme, and optionally sets a default group

Types

type GenericMappedRawStorage

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

GenericMappedRawStorage is the default implementation of a MappedRawStorage, it stores files in the given directory via a path translation map.

func (*GenericMappedRawStorage) AddMapping

func (r *GenericMappedRawStorage) AddMapping(key ObjectKey, path string)

func (*GenericMappedRawStorage) Checksum

func (r *GenericMappedRawStorage) Checksum(key ObjectKey) (string, error)

This returns the modification time as a UnixNano string. If the file doesn't exist, returns ErrNotFound + ErrNotTracked.

func (*GenericMappedRawStorage) ContentType

func (r *GenericMappedRawStorage) ContentType(key ObjectKey) (ct serializer.ContentType)

func (*GenericMappedRawStorage) Delete

func (r *GenericMappedRawStorage) Delete(key ObjectKey) (err error)

If the file doesn't exist, returns ErrNotFound + ErrNotTracked.

func (*GenericMappedRawStorage) Exists

func (r *GenericMappedRawStorage) Exists(key ObjectKey) bool

func (*GenericMappedRawStorage) GetKey

func (r *GenericMappedRawStorage) GetKey(path string) (ObjectKey, error)

func (*GenericMappedRawStorage) List

func (r *GenericMappedRawStorage) List(kind KindKey) ([]ObjectKey, error)

func (*GenericMappedRawStorage) Read

func (r *GenericMappedRawStorage) Read(key ObjectKey) ([]byte, error)

If the file doesn't exist, returns ErrNotFound + ErrNotTracked.

func (*GenericMappedRawStorage) RemoveMapping

func (r *GenericMappedRawStorage) RemoveMapping(key ObjectKey)

func (*GenericMappedRawStorage) SetMappings

func (r *GenericMappedRawStorage) SetMappings(m map[ObjectKey]string)

func (*GenericMappedRawStorage) WatchDir

func (r *GenericMappedRawStorage) WatchDir() string

func (*GenericMappedRawStorage) Write

func (r *GenericMappedRawStorage) Write(key ObjectKey, content []byte) error

type GenericRawStorage

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

GenericRawStorage is a rawstorage which stores objects as JSON files on disk, in the form: <dir>/<kind>/<identifier>/metadata.json. The GenericRawStorage only supports one GroupVersion at a time, and will error if given any other resources

func (*GenericRawStorage) Checksum

func (r *GenericRawStorage) Checksum(key ObjectKey) (string, error)

This returns the modification time as a UnixNano string If the file doesn't exist, return ErrNotFound

func (*GenericRawStorage) ContentType

func (*GenericRawStorage) Delete

func (r *GenericRawStorage) Delete(key ObjectKey) error

func (*GenericRawStorage) Exists

func (r *GenericRawStorage) Exists(key ObjectKey) bool

func (*GenericRawStorage) GetKey

func (r *GenericRawStorage) GetKey(p string) (ObjectKey, error)

func (*GenericRawStorage) List

func (r *GenericRawStorage) List(kind KindKey) ([]ObjectKey, error)

func (*GenericRawStorage) Read

func (r *GenericRawStorage) Read(key ObjectKey) ([]byte, error)

func (*GenericRawStorage) WatchDir

func (r *GenericRawStorage) WatchDir() string

func (*GenericRawStorage) Write

func (r *GenericRawStorage) Write(key ObjectKey, content []byte) error

type GenericStorage

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

GenericStorage implements the Storage interface

func (*GenericStorage) Checksum

func (s *GenericStorage) Checksum(key ObjectKey) (string, error)

Checksum returns a string representing the state of an Object on disk

func (*GenericStorage) Close

func (s *GenericStorage) Close() error

Close closes all underlying resources (e.g. goroutines) used; before the application exits

func (*GenericStorage) Count

func (s *GenericStorage) Count(kind KindKey) (uint64, error)

Count counts the Objects for the specific kind

func (*GenericStorage) Create

func (s *GenericStorage) Create(obj runtime.Object) error

func (*GenericStorage) Delete

func (s *GenericStorage) Delete(key ObjectKey) error

Delete removes an Object from the storage

func (*GenericStorage) Find

func (s *GenericStorage) Find(kind KindKey, opts ...filter.ListOption) (runtime.Object, error)

Find does a List underneath, also using filters, but always returns one object. If the List underneath returned two or more results, ErrAmbiguousFind is returned. If no match was found, ErrNotFound is returned.

func (*GenericStorage) Get

func (s *GenericStorage) Get(key ObjectKey) (runtime.Object, error)

Get returns a new Object for the resource at the specified kind/uid path, based on the file content

func (*GenericStorage) GetMeta

func (s *GenericStorage) GetMeta(key ObjectKey) (runtime.PartialObject, error)

TODO: Verify this works GetMeta returns a new Object's APIType representation for the resource at the specified kind/uid path

func (*GenericStorage) List

func (s *GenericStorage) List(kind KindKey, opts ...filter.ListOption) ([]runtime.Object, error)

List lists Objects for the specific kind. Optionally, filters can be applied (see the filter package for more information, e.g. filter.NameFilter{} and filter.UIDFilter{})

func (*GenericStorage) ListMeta

func (s *GenericStorage) ListMeta(kind KindKey) (result []runtime.PartialObject, walkerr error)

ListMeta lists all Objects' APIType representation. In other words, only metadata about each Object is unmarshalled (uid/name/kind/apiVersion). This allows for faster runs (no need to unmarshal "the world"), and less resource usage, when only metadata is unmarshalled into memory

func (*GenericStorage) ObjectKeyFor

func (s *GenericStorage) ObjectKeyFor(obj runtime.Object) (ObjectKey, error)

func (*GenericStorage) Patch

func (s *GenericStorage) Patch(key ObjectKey, patch []byte) error

Patch performs a strategic merge patch on the object with the given UID, using the byte-encoded patch given

func (*GenericStorage) RawStorage

func (s *GenericStorage) RawStorage() RawStorage

RawStorage returns the RawStorage instance backing this Storage

func (*GenericStorage) Serializer

func (s *GenericStorage) Serializer() serializer.Serializer

func (*GenericStorage) Update

func (s *GenericStorage) Update(obj runtime.Object) error

type KindKey

type KindKey interface {
	// String implements fmt.Stringer
	String() string

	GetGroup() string
	GetVersion() string
	GetKind() string
	GetGVK() schema.GroupVersionKind

	EqualsGVK(kind KindKey, respectVersion bool) bool
}

func NewKindKey

func NewKindKey(gvk schema.GroupVersionKind) KindKey

type MappedRawStorage

type MappedRawStorage interface {
	RawStorage

	// AddMapping binds a Key's virtual path to a physical file path
	AddMapping(key ObjectKey, path string)
	// RemoveMapping removes the physical file
	// path mapping matching the given Key
	RemoveMapping(key ObjectKey)

	// SetMappings overwrites all known mappings
	SetMappings(m map[ObjectKey]string)
}

MappedRawStorage is an interface for RawStorages which store their data in a flat/unordered directory format like manifest directories.

func NewGenericMappedRawStorage

func NewGenericMappedRawStorage(dir string) MappedRawStorage

type ObjectKey

type ObjectKey interface {
	KindKey
	runtime.Identifyable
}

func NewObjectKey

func NewObjectKey(kind KindKey, id runtime.Identifyable) ObjectKey

type RawStorage

type RawStorage interface {
	// Read returns a resource's content based on key.
	// If the resource does not exist, it returns ErrNotFound.
	Read(key ObjectKey) ([]byte, error)
	// Exists checks if the resource indicated by key exists.
	Exists(key ObjectKey) bool
	// Write writes the given content to the resource indicated by key.
	// Error returns are implementation-specific.
	Write(key ObjectKey, content []byte) error
	// Delete deletes the resource indicated by key.
	// If the resource does not exist, it returns ErrNotFound.
	Delete(key ObjectKey) error
	// List returns all matching object keys based on the given KindKey.
	List(key KindKey) ([]ObjectKey, error)
	// Checksum returns a string checksum for the resource indicated by key.
	// If the resource does not exist, it returns ErrNotFound.
	Checksum(key ObjectKey) (string, error)
	// ContentType returns the content type of the contents of the resource indicated by key.
	ContentType(key ObjectKey) serializer.ContentType

	// WatchDir returns the path for Watchers to watch changes in.
	WatchDir() string
	// GetKey retrieves the Key containing the virtual path based
	// on the given physical file path returned by a Watcher.
	GetKey(path string) (ObjectKey, error)
}

RawStorage is a Key-indexed low-level interface to store byte-encoded Objects (resources) in non-volatile memory.

func NewGenericRawStorage

func NewGenericRawStorage(dir string, gv schema.GroupVersion, ct serializer.ContentType) RawStorage

type ReadStorage

type ReadStorage interface {
	// Get returns a new Object for the resource at the specified kind/uid path, based on the file content.
	// If the resource referred to by the given ObjectKey does not exist, Get returns ErrNotFound.
	Get(key ObjectKey) (runtime.Object, error)

	// List lists Objects for the specific kind. Optionally, filters can be applied (see the filter package
	// for more information, e.g. filter.NameFilter{} and filter.UIDFilter{})
	List(kind KindKey, opts ...filter.ListOption) ([]runtime.Object, error)

	// Find does a List underneath, also using filters, but always returns one object. If the List
	// underneath returned two or more results, ErrAmbiguousFind is returned. If no match was found,
	// ErrNotFound is returned.
	Find(kind KindKey, opts ...filter.ListOption) (runtime.Object, error)

	// GetMeta returns a new Object's APIType representation for the resource at the specified kind/uid path.
	// If the resource referred to by the given ObjectKey does not exist, GetMeta returns ErrNotFound.
	GetMeta(key ObjectKey) (runtime.PartialObject, error)
	// ListMeta lists all Objects' APIType representation. In other words,
	// only metadata about each Object is unmarshalled (uid/name/kind/apiVersion).
	// This allows for faster runs (no need to unmarshal "the world"), and less
	// resource usage, when only metadata is unmarshalled into memory
	ListMeta(kind KindKey) ([]runtime.PartialObject, error)

	// Checksum returns a string representing the state of an Object on disk
	// The checksum should change if any modifications have been made to the
	// Object on disk, it can be e.g. the Object's modification timestamp or
	// calculated checksum. If the Object is not found, ErrNotFound is returned.
	Checksum(key ObjectKey) (string, error)
	// Count returns the amount of available Objects of a specific kind
	// This is used by Caches to check if all Objects are cached to perform a List
	Count(kind KindKey) (uint64, error)

	// RawStorage returns the RawStorage instance backing this Storage
	RawStorage() RawStorage
	// Serializer returns the serializer
	Serializer() serializer.Serializer

	// ObjectKeyFor returns the ObjectKey for the given object
	ObjectKeyFor(obj runtime.Object) (ObjectKey, error)
	// Close closes all underlying resources (e.g. goroutines) used; before the application exits
	Close() error
}

type Storage

type Storage interface {
	ReadStorage
	WriteStorage
}

Storage is an interface for persisting and retrieving API objects to/from a backend One Storage instance handles all different Kinds of Objects

func NewGenericStorage

func NewGenericStorage(rawStorage RawStorage, serializer serializer.Serializer, identifiers []runtime.IdentifierFactory) Storage

NewGenericStorage constructs a new Storage

type WriteStorage

type WriteStorage interface {
	// Create creates an entry for and stores the given Object in the storage. The Object must be new to the storage.
	// The ObjectMeta.CreationTimestamp field is set automatically to the current time if it is unset.
	Create(obj runtime.Object) error
	// Update updates the state of the given Object in the storage. The Object must exist in the storage.
	// The ObjectMeta.CreationTimestamp field is set automatically to the current time if it is unset.
	Update(obj runtime.Object) error

	// Patch performs a strategic merge patch on the Object with the given UID, using the byte-encoded patch given
	Patch(key ObjectKey, patch []byte) error
	// Delete removes an Object from the storage
	Delete(key ObjectKey) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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