resource

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MPL-2.0 Imports: 12 Imported by: 59

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) (any, error)

MarshalYAML marshals resource to YAML definition.

func String

func String(r Resource) string

String returns representation suitable for %s formatting.

Types

type Annotations added in v0.2.0

type Annotations struct {
	kv.KV
}

Annotations is a set free-form of key-value pairs.

Order of keys is not guaranteed.

Annotations support copy-on-write semantics, so metadata copies share common Annotations as long as possible.

func (Annotations) Equal added in v0.2.0

func (annotations Annotations) Equal(other Annotations) bool

Equal checks Annotations for equality.

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() any

Spec implements resource.Resource.

func (*Any) Value

func (a *Any) Value() any

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) 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) Has added in v0.3.0

func (fins Finalizers) Has(fin Finalizer) bool

Has returns true if fin is present in the list of finalizers.

func (*Finalizers) Remove

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

Remove a (unique) Finalizer from the set.

func (*Finalizers) Set added in v0.3.0

func (fins *Finalizers) Set(other Finalizers)

Set copies the finalizers from the other.

type ID

type ID = string

ID is a resource ID.

type IDQuery added in v0.3.0

type IDQuery struct {
	Regexp *regexp.Regexp
}

IDQuery is the query on the resource ID.

func (IDQuery) Matches added in v0.3.0

func (query IDQuery) Matches(md Metadata) bool

Matches if the resource ID matches the ID query.

type IDQueryOption added in v0.3.0

type IDQueryOption func(*IDQuery)

IDQueryOption allows to build an IDQuery with functional parameters.

func IDRegexpMatch added in v0.3.0

func IDRegexpMatch(re *regexp.Regexp) IDQueryOption

IDRegexpMatch checks that the ID matches the regexp.

type Kind

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

Kind is a Pointer minus resource ID.

type LabelOp

type LabelOp int

LabelOp is a match operation on labels.

const (
	// Label with the key exists.
	LabelOpExists LabelOp = iota
	// Label with the key matches the value.
	LabelOpEqual
	// Label value is in the set.
	LabelOpIn
	// Label value is less.
	LabelOpLT
	// Label value is less or equal.
	LabelOpLTE
	// Label value is less than number.
	LabelOpLTNumeric
	// Label value is less or equal numeric.
	LabelOpLTENumeric
)

LabelOp values.

type LabelQueries added in v0.3.3

type LabelQueries []LabelQuery

LabelQueries is the list of label queries.

func (LabelQueries) Matches added in v0.3.3

func (queries LabelQueries) Matches(labels Labels) bool

Matches iterates through the list of label queries and matches the labels using OR condition.

type LabelQuery

type LabelQuery struct {
	Terms []LabelTerm
}

LabelQuery is a set of LabelTerms applied with AND semantics.

func (LabelQuery) Matches

func (query LabelQuery) Matches(labels Labels) bool

Matches if the metadata labels matches the label query.

type LabelQueryOption

type LabelQueryOption func(*LabelQuery)

LabelQueryOption allows to build a LabelQuery with functional parameters.

func LabelEqual

func LabelEqual(label, value string, opts ...TermOption) LabelQueryOption

LabelEqual checks that the label is set to the specified value.

func LabelExists

func LabelExists(label string, opts ...TermOption) LabelQueryOption

LabelExists checks that the label is set.

func LabelIn added in v0.3.2

func LabelIn(label string, set []string, opts ...TermOption) LabelQueryOption

LabelIn checks that the label value is in the provided set.

func LabelLT added in v0.3.2

func LabelLT(label, value string, opts ...TermOption) LabelQueryOption

LabelLT checks that the label value is less than value, peforms string comparison.

func LabelLTE added in v0.3.2

func LabelLTE(label, value string, opts ...TermOption) LabelQueryOption

LabelLTE checks that the label value is less or equal to value, peforms string comparison.

func LabelLTENumeric added in v0.3.2

func LabelLTENumeric(label, value string, opts ...TermOption) LabelQueryOption

LabelLTENumeric checks that the label value is less or equal to value, peforms numeric comparison, if possible.

func LabelLTNumeric added in v0.3.2

func LabelLTNumeric(label, value string, opts ...TermOption) LabelQueryOption

LabelLTNumeric checks that the label value is less than value, peforms numeric comparison, if possible.

func RawLabelQuery

func RawLabelQuery(query LabelQuery) LabelQueryOption

RawLabelQuery sets the label query to the verbatim value.

type LabelTerm

type LabelTerm struct {
	Key    string
	Value  []string
	Op     LabelOp
	Invert bool
}

LabelTerm describes a filter on metadata labels.

type Labels

type Labels struct {
	kv.KV
}

Labels is a set free-form of key-value pairs.

Order of keys is not guaranteed.

Labels support copy-on-write semantics, so metadata copies share common labels as long as possible. Labels support querying with LabelTerm.

func (Labels) Equal

func (labels Labels) Equal(other Labels) bool

Equal checks labels for equality.

func (Labels) Matches

func (labels Labels) Matches(term LabelTerm) bool

Matches if labels match the LabelTerm.

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) Annotations added in v0.2.0

func (md *Metadata) Annotations() *Annotations

Annotations returns a reference to the annotations.

func (Metadata) Copy

func (md Metadata) Copy() Metadata

Copy returns metadata copy.

func (Metadata) Created

func (md Metadata) Created() time.Time

Created returns resource creation timestamp.

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

func (md *Metadata) Labels() *Labels

Labels returns a reference to the labels.

func (*Metadata) MarshalYAML

func (md *Metadata) MarshalYAML() (any, 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) SetCreated added in v0.2.0

func (md *Metadata) SetCreated(t time.Time)

SetCreated sets the resource create timestamp.

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) SetUpdated added in v0.2.0

func (md *Metadata) SetUpdated(t time.Time)

SetUpdated sets the resource update timestamp.

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) UnmarshalYAML added in v0.2.0

func (md *Metadata) UnmarshalYAML(value *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler interface.

func (Metadata) Updated

func (md Metadata) Updated() time.Time

Updated returns resource update timestamp.

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
	GetCreated() *timestamppb.Timestamp
	GetUpdated() *timestamppb.Timestamp
	GetAnnotations() map[string]string
	GetLabels() map[string]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 {
	// Metadata for the resource.
	//
	// Metadata.Version should change each time Spec changes.
	Metadata() *Metadata

	// Opaque data resource contains.
	Spec() any

	// 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 TermOption added in v0.3.2

type TermOption int

TermOption defines additional term options.

const (
	// NotMatches the condition.
	NotMatches TermOption = iota
)

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() any

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) Next added in v0.2.0

func (v Version) Next() Version

Next returns a new incremented version.

func (Version) String

func (v Version) String() string

func (Version) Value added in v0.2.0

func (v Version) Value() uint64

Value returns the underlying version number. Returns 0 if the version is undefined.

Directories

Path Synopsis
Package handle provides a way to wrap "handle/descriptor-like" resources.
Package handle provides a way to wrap "handle/descriptor-like" resources.
internal
compare
Package compare implements term operation helpers.
Package compare implements term operation helpers.
kv
Package kv implements core key-value type as a base for labels and annotations.
Package kv implements core key-value type as a base for labels and annotations.
Package kvutils provides utilities to internal/kv package.
Package kvutils provides utilities to internal/kv package.
Package meta provides definition of core metadata resources.
Package meta provides definition of core metadata resources.
spec
Package spec contains resource specs for the meta resources.
Package spec contains resource specs for the meta resources.
Package protobuf provides a bridge between resources and protobuf interface.
Package protobuf provides a bridge between resources and protobuf interface.
Package rtestutils provides utilities for testing with resource API.
Package rtestutils provides utilities for testing with resource API.
Package typed generic based resource definition.
Package typed generic based resource definition.

Jump to

Keyboard shortcuts

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