resource

package
v0.0.0-...-86d9e09 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package resource provides core resource definition.

Index

Constants

This section is empty.

Variables

View Source
var (
	VersionUndefined = Version{}
)

Special version constants.

Functions

func Equal

func Equal(r1, r2 Resource) bool

Equal tests two resources for equality.

func IsTombstone

func IsTombstone(res Resource) bool

IsTombstone checks if resource is represented by the Tombstone.

func MarshalYAML

func MarshalYAML(r Resource) (interface{}, error)

MarshalYAML marshals resource to YAML definition.

Types

type Any

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

Any can hold data from any resource type.

func NewAnyFromProto

func NewAnyFromProto(protoMd MetadataProto, protoSpec SpecProto) (*Any, error)

NewAnyFromProto unmarshals Any from protobuf interface.

func (*Any) DeepCopy

func (a *Any) DeepCopy() Resource

DeepCopy implements resource.Resource.

func (*Any) Metadata

func (a *Any) Metadata() *Metadata

Metadata implements resource.Resource.

func (*Any) Spec

func (a *Any) Spec() interface{}

Spec implements resource.Resource.

func (*Any) String

func (a *Any) String() string

func (*Any) Value

func (a *Any) Value() interface{}

Value returns decoded value as Go type.

type Finalizer

type Finalizer = string

Finalizer is a free-form string which blocks resource destruction.

Resource can't be destroyed until all the finalizers are cleared.

type Finalizers

type Finalizers []Finalizer

Finalizers is a set of Finalizer's with methods to add/remove items.

func (*Finalizers) Add

func (fins *Finalizers) Add(fin Finalizer) (added bool)

Add a (unique) Finalizer to the set.

func (Finalizers) Empty

func (fins Finalizers) Empty() bool

Empty returns true if list of finalizers is empty.

func (*Finalizers) Remove

func (fins *Finalizers) Remove(fin Finalizer) (removed bool)

Remove a (unique) Finalizer from the set.

type ID

type ID = string

ID is a resource ID.

type Kind

type Kind interface {
	Namespace() Namespace
	Type() Type
}

Kind is a Pointer minus resource ID.

type List

type List struct {
	Items []Resource
}

List is a list of resources.

type Metadata

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

Metadata implements resource meta.

func NewMetadata

func NewMetadata(ns Namespace, typ Type, id ID, ver Version) Metadata

NewMetadata builds new metadata.

func NewMetadataFromProto

func NewMetadataFromProto(proto MetadataProto) (Metadata, error)

NewMetadataFromProto builds Metadata object from ProtoMetadata interface data.

func (*Metadata) BumpVersion

func (md *Metadata) BumpVersion()

BumpVersion increments resource version.

func (Metadata) Copy

func (md Metadata) Copy() Metadata

Copy returns metadata copy.

func (Metadata) Equal

func (md Metadata) Equal(other Metadata) bool

Equal tests two metadata objects for equality.

func (*Metadata) Finalizers

func (md *Metadata) Finalizers() *Finalizers

Finalizers returns a reference to the finalizers.

func (Metadata) ID

func (md Metadata) ID() ID

ID returns resource ID.

func (*Metadata) MarshalYAML

func (md *Metadata) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaller interface.

func (Metadata) Namespace

func (md Metadata) Namespace() Namespace

Namespace returns resource namespace.

func (Metadata) Owner

func (md Metadata) Owner() Owner

Owner returns resource owner.

func (Metadata) Phase

func (md Metadata) Phase() Phase

Phase returns current resource phase.

func (*Metadata) SetOwner

func (md *Metadata) SetOwner(owner Owner) error

SetOwner sets the resource owner.

Owner can be set only once.

func (*Metadata) SetPhase

func (md *Metadata) SetPhase(newPhase Phase)

SetPhase updates resource state.

func (*Metadata) SetVersion

func (md *Metadata) SetVersion(newVersion Version)

SetVersion updates resource version.

func (Metadata) String

func (md Metadata) String() string

String implements fmt.Stringer.

func (Metadata) Type

func (md Metadata) Type() Type

Type returns resource types.

func (Metadata) Version

func (md Metadata) Version() Version

Version returns resource version.

type MetadataProto

type MetadataProto interface {
	GetNamespace() string
	GetType() string
	GetId() string
	GetVersion() string
	GetPhase() string
	GetOwner() string
	GetFinalizers() []string
}

MetadataProto is an interface for protobuf serialization of Metadata.

type Namespace

type Namespace = string

Namespace of a resource.

type Owner

type Owner = string

Owner of the resource (controller which manages the resource).

type Phase

type Phase int

Phase represents state of the resource.

Resource might be either Running or TearingDown (waiting for the finalizers to be removed).

const (
	PhaseRunning Phase = iota
	PhaseTearingDown
)

Phase constants.

func ParsePhase

func ParsePhase(ph string) (Phase, error)

ParsePhase from string representation.

func (Phase) String

func (ph Phase) String() string

type Pointer

type Pointer interface {
	Kind

	ID() ID
}

Pointer is a Reference minus resource version.

type Reference

type Reference interface {
	fmt.Stringer

	Pointer
	Version() Version
}

Reference to a resource.

type Resource

type Resource interface {
	// String() method for debugging/logging.
	fmt.Stringer

	// Metadata for the resource.
	//
	// Metadata.Version should change each time Spec changes.
	Metadata() *Metadata

	// Opaque data resource contains.
	Spec() interface{}

	// Deep copy of the resource.
	DeepCopy() Resource
}

Resource is an abstract resource managed by the state.

Resource is uniquely identified by the tuple (Namespace, Type, ID). Resource might have additional opaque data in Spec(). When resource is updated, Version should change with each update.

type SpecProto

type SpecProto interface {
	GetYaml() []byte
}

SpecProto is a protobuf interface of resource spec.

type Tombstone

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

Tombstone is a resource without a Spec.

Tombstones are used to present state of a deleted resource.

func NewTombstone

func NewTombstone(ref Reference) *Tombstone

NewTombstone builds a tombstone from resource reference.

func (*Tombstone) DeepCopy

func (t *Tombstone) DeepCopy() Resource

DeepCopy returns self, as tombstone is immutable.

func (*Tombstone) Metadata

func (t *Tombstone) Metadata() *Metadata

Metadata for the resource.

Metadata.Version should change each time Spec changes.

func (*Tombstone) Spec

func (t *Tombstone) Spec() interface{}

Spec is not implemented for tobmstones.

func (*Tombstone) String

func (t *Tombstone) String() string

String method for debugging/logging.

func (*Tombstone) Tombstone

func (t *Tombstone) Tombstone()

Tombstone implements Tombstoned interface.

type Tombstoned

type Tombstoned interface {
	Tombstone()
}

Tombstoned is a marker interface for Tombstones.

type Type

type Type = string

Type is a resource type.

Type could be e.g. runtime/os/mount.

type Version

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

Version of a resource.

func ParseVersion

func ParseVersion(ver string) (Version, error)

ParseVersion from string representation.

func (Version) Equal

func (v Version) Equal(other Version) bool

Equal compares versions.

func (Version) String

func (v Version) String() string

Directories

Path Synopsis
Package meta provides definition of core metadata resources.
Package meta provides definition of core metadata resources.
Package protobuf provides a bridge between resources and protobuf interface.
Package protobuf provides a bridge between resources and protobuf interface.

Jump to

Keyboard shortcuts

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