storage

package
v0.0.0-...-f0fc148 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Formats = map[string]Format{
	".json": FormatJSON,
	".yaml": FormatYAML,
	".yml":  FormatYAML,
}

Formats describes the connection between file extensions and a encoding formats.

Functions

This section is empty.

Types

type AnyKey

type AnyKey fmt.Stringer

This can be used to match either of the keys

type Format

type Format uint8

Format is an enum describing the format of data in a file. This is used by Storages to determine the encoding format for a file.

const (
	FormatJSON Format = iota
	FormatYAML
)

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 Key, path string)

func (*GenericMappedRawStorage) Checksum

func (r *GenericMappedRawStorage) Checksum(key Key) (s string, err error)

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

func (*GenericMappedRawStorage) Delete

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

func (*GenericMappedRawStorage) Exists

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

func (*GenericMappedRawStorage) Format

func (r *GenericMappedRawStorage) Format(key Key) (f Format)

func (*GenericMappedRawStorage) GetKey

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

func (*GenericMappedRawStorage) List

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

func (*GenericMappedRawStorage) Read

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

func (*GenericMappedRawStorage) RemoveMapping

func (r *GenericMappedRawStorage) RemoveMapping(key Key)

func (*GenericMappedRawStorage) WatchDir

func (r *GenericMappedRawStorage) WatchDir() string

func (*GenericMappedRawStorage) Write

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

type GenericRawStorage

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

func (*GenericRawStorage) Checksum

func (r *GenericRawStorage) Checksum(key Key) (s string, err error)

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

func (*GenericRawStorage) Delete

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

func (*GenericRawStorage) Exists

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

func (*GenericRawStorage) Format

func (r *GenericRawStorage) Format(key Key) Format

func (*GenericRawStorage) GetKey

func (r *GenericRawStorage) GetKey(p string) (key Key, err error)

func (*GenericRawStorage) List

func (r *GenericRawStorage) List(key KindKey) ([]Key, error)

func (*GenericRawStorage) Read

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

func (*GenericRawStorage) WatchDir

func (r *GenericRawStorage) WatchDir() string

func (*GenericRawStorage) Write

func (r *GenericRawStorage) Write(key Key, 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(gvk schema.GroupVersionKind, uid runtime.UID) (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

Count counts the Objects for the specific kind

func (*GenericStorage) Delete

func (s *GenericStorage) Delete(gvk schema.GroupVersionKind, uid runtime.UID) error

Delete removes an Object from the storage

func (*GenericStorage) Get

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

func (*GenericStorage) GetMeta

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(gvk schema.GroupVersionKind) (result []runtime.Object, walkerr error)

List lists Objects for the specific kind

func (*GenericStorage) ListMeta

func (s *GenericStorage) ListMeta(gvk schema.GroupVersionKind) (result []runtime.Object, 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) New

New creates a new Object for the specified kind TODO: Create better error handling if the GVK specified is not recognized

func (*GenericStorage) Patch

func (s *GenericStorage) Patch(gvk schema.GroupVersionKind, uid runtime.UID, 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) Set

Set saves the Object to disk

type Key

type Key struct {
	KindKey
	runtime.UID
}

Key represents the internal format of Object virtual paths

func KeyForUID

func KeyForUID(gvk schema.GroupVersionKind, uid runtime.UID) Key

func NewKey

func NewKey(kind runtime.Kind, uid runtime.UID) Key

NewKey generates a new virtual path Key for an Object

func ParseKey

func ParseKey(input string) (k Key, err error)

ParseKey parses the given string and returns a Key

func (Key) String

func (k Key) String() string

String returns the virtual path for the Object

func (Key) ToKindKey

func (k Key) ToKindKey() KindKey

ToKindKey creates a KindKey out of a Key

type KindKey

type KindKey struct {
	runtime.Kind
}

KindKey represents the internal format of Kind virtual paths

func KeyForKind

func KeyForKind(gvk schema.GroupVersionKind) KindKey

func NewKindKey

func NewKindKey(kind runtime.Kind) KindKey

NewKindKey generates a new virtual path Key for a Kind

func (KindKey) String

func (k KindKey) String() string

String returns the virtual path for the Kind

type MappedRawStorage

type MappedRawStorage interface {
	RawStorage

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

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 RawStorage

type RawStorage interface {
	// Read returns a resource's content based on key
	Read(key Key) ([]byte, error)
	// Exists checks if the resource indicated by key exists
	Exists(key Key) bool
	// Write writes the given content to the resource indicated by key
	Write(key Key, content []byte) error
	// Delete deletes the resource indicated by key
	Delete(key Key) error
	// List returns all matching resource Keys based on the given KindKey
	List(key KindKey) ([]Key, error)
	// Checksum returns a string checksum for the resource indicated by key
	Checksum(key Key) (string, error)
	// Format returns the format of the contents of the resource indicated by key
	Format(key Key) Format

	// 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) (Key, 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) RawStorage

type Storage

type Storage interface {
	// New creates a new Object for the specified kind
	New(gvk schema.GroupVersionKind) (runtime.Object, error)
	// Get returns a new Object for the resource at the specified kind/uid path, based on the file content
	Get(gvk schema.GroupVersionKind, uid runtime.UID) (runtime.Object, error)
	// GetMeta returns a new Object's APIType representation for the resource at the specified kind/uid path
	GetMeta(gvk schema.GroupVersionKind, uid runtime.UID) (runtime.Object, error)
	// Set saves the Object to disk. If the Object does not exist, the
	// ObjectMeta.Created field is set automatically
	Set(gvk schema.GroupVersionKind, obj runtime.Object) error
	// Patch performs a strategic merge patch on the Object with the given UID, using the byte-encoded patch given
	Patch(gvk schema.GroupVersionKind, uid runtime.UID, patch []byte) error
	// Delete removes an Object from the storage
	Delete(gvk schema.GroupVersionKind, uid runtime.UID) error
	// List lists Objects for the specific kind
	List(gvk schema.GroupVersionKind) ([]runtime.Object, 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(gvk schema.GroupVersionKind) ([]runtime.Object, 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(gvk schema.GroupVersionKind) (uint64, 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
	Checksum(gvk schema.GroupVersionKind, uid runtime.UID) (string, error)
	// RawStorage returns the RawStorage instance backing this Storage
	RawStorage() RawStorage
	// Serializer returns the serializer
	Serializer() serializer.Serializer
	// Close closes all underlying resources (e.g. goroutines) used; before the application exits
	Close() error
}

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) Storage

NewGenericStorage constructs a new Storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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