resource

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidServiceID = errors.New("invalid service ID")

	LegacyServiceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$")
	// The namespace and name components are (apparently
	// non-normatively) defined in
	// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md
	// In practice, more punctuation is used than allowed there;
	// specifically, people use underscores as well as dashes and dots, and in names, colons.
	IDRegexp            = regexp.MustCompile("^(<cluster>|[a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
	UnqualifiedIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
)

Functions

func ChangesForPolicyUpdate

func ChangesForPolicyUpdate(workload Workload, update PolicyUpdate) (map[string]string, error)

ChangeForPolicyUpdate evaluates a policy update with respect to a workload. The reason this exists at all is that an `Update` can include qualified policies, for example "tag all containers"; and to make actual changes, we need to examine the workload to which it's to be applied.

This also translates policy deletion to empty values (i.e., `""`), to make it easy to use as command-line arguments or environment variables. When represented in manifests, policies are expected to have a non-empty value when present, even if it's `"true"`; so an empty value can safely denote deletion.

Types

type Container

type Container struct {
	Name  string
	Image image.Ref
}

type ID

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

ID is an opaque type which uniquely identifies a resource in an orchestrator.

func MakeID

func MakeID(namespace, kind, name string) ID

MakeID constructs a ID from constituent components.

func MustParseID

func MustParseID(s string) ID

MustParseID constructs a ID from a string representation, panicing if the format is invalid.

func ParseID

func ParseID(s string) (ID, error)

ParseID constructs a ID from a string representation if possible, returning an error value otherwise.

func ParseIDOptionalNamespace

func ParseIDOptionalNamespace(namespace, s string) (ID, error)

ParseIDOptionalNamespace constructs a ID from either a fully qualified string representation, or an unqualified kind/name representation and the supplied namespace.

func (ID) Components

func (id ID) Components() (namespace, kind, name string)

Components returns the constituent components of a ID

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON encodes a ID as a JSON string. This is done to maintain backwards compatibility with previous flux versions where the ID is a plain string.

func (ID) MarshalText

func (id ID) MarshalText() (text []byte, err error)

MarshalText encodes a ID as a flat string; this is required because ResourceIDs are sometimes used as map keys.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON decodes a ID from a JSON string. This is done to maintain backwards compatibility with previous flux versions where the ID is a plain string.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(text []byte) error

MarshalText decodes a ID from a flat string; this is required because ResourceIDs are sometimes used as map keys.

type IDSet

type IDSet map[ID]struct{}

func (IDSet) Add

func (s IDSet) Add(ids []ID)

func (IDSet) Contains

func (s IDSet) Contains(id ID) bool

func (IDSet) Intersection

func (s IDSet) Intersection(others IDSet) IDSet

func (IDSet) String

func (s IDSet) String() string

func (IDSet) ToSlice

func (s IDSet) ToSlice() IDs

func (IDSet) Without

func (s IDSet) Without(others IDSet) IDSet

type IDs

type IDs []ID

func (IDs) Contains

func (ids IDs) Contains(id ID) bool

func (IDs) Intersection

func (ids IDs) Intersection(others IDSet) IDSet

func (IDs) Len

func (p IDs) Len() int

func (IDs) Less

func (p IDs) Less(i, j int) bool

func (IDs) Sort

func (p IDs) Sort()

func (IDs) Swap

func (p IDs) Swap(i, j int)

func (IDs) Without

func (ids IDs) Without(others IDSet) (res IDs)

type PolicyUpdate

type PolicyUpdate struct {
	Add    policy.Set `json:"add"`
	Remove policy.Set `json:"remove"`
}

type PolicyUpdates

type PolicyUpdates map[ID]PolicyUpdate

type Resource

type Resource interface {
	ResourceID() ID       // name, to correlate with what's in the cluster
	Policies() policy.Set // policy for this resource; e.g., whether it is locked, automated, ignored
	Source() string       // where did this come from (informational)
	Bytes() []byte        // the definition, for sending to cluster.Sync
}

For the minute we just care about

type Workload

type Workload interface {
	Resource
	Containers() []Container
	// SetContainerImage mutates this workload so that the container
	// named has the image given. This is not expected to have an
	// effect on any underlying file or cluster resource.
	SetContainerImage(container string, ref image.Ref) error
}

Jump to

Keyboard shortcuts

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