labels

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IDNameAll is a special label which matches all labels.
	IDNameAll = "all"
	// IDNameHost is the label used for the hostname ID.
	IDNameHost = "host"
	// IDNameWorld is the label used for the world ID.
	IDNameWorld = "world"
)
View Source
const (
	// LPCfgFileVersion represents the version of a Label Prefix Configuration File
	LPCfgFileVersion = 1
)

Variables

This section is empty.

Functions

func GetCiliumKeyFrom added in v0.9.0

func GetCiliumKeyFrom(extKey string) string

GetCiliumKeyFrom returns the label's source and key from the an extended key in the format SOURCE:KEY.

func GetExtendedKeyFrom added in v0.9.0

func GetExtendedKeyFrom(str string) string

GetExtendedKeyFrom returns the extended key of a label string. For example: `k8s:foo=bar` returns `k8s.foo` `cilium:foo=bar` returns `cilium.foo` `foo=bar` returns `cilium.foo=bar`

func LabelSliceSHA256Sum

func LabelSliceSHA256Sum(labels []*Label) (string, error)

LabelSliceSHA256Sum returns SHA256 checksum from the labels.

Types

type Label

type Label struct {
	Key   string `json:"key"`
	Value string `json:"value,omitempty"`
	// Source can be on of the values present in const.go (e.g.: CiliumLabelSource)
	Source string `json:"source"`
	// Mark element to be used to find unused labels in lists
	DeletionMark bool `json:"-"`
}

Label is the cilium's representation of a container label.

func NewLabel

func NewLabel(key string, value string, source string) *Label

NewLabel returns a new label from the given key, value and source. If source is empty, the default value will be common.CiliumLabelSource. If key starts with '$', the source will be overwritten with common.ReservedLabelSource. If key contains ':', the value before ':' will be used as source if given source is empty, otherwise the value before ':' will be deleted and unused.

func ParseLabel

func ParseLabel(str string) *Label

ParseLabel returns the label representation of the given string. The str should be in the form of Source:Key=Value or Source:Key if Value is empty. It also parses short forms, for example: $host will be Label{Key: "host", Source: "reserved", Value: ""}.

func (*Label) DeepCopy added in v0.9.0

func (l *Label) DeepCopy() *Label

DeepCopy returns a Deep copy of the receiver's label.

func (*Label) Equals

func (l *Label) Equals(b *Label) bool

Equals returns true if source, AbsoluteKey() and Value are equal and false otherwise.

func (*Label) GetExtendedKey added in v0.9.0

func (l *Label) GetExtendedKey() string

GetExtendedKey returns the key of a label with the source encoded.

func (*Label) IsAllLabel

func (l *Label) IsAllLabel() bool

IsAllLabel returns true if the label is reserved and matches with IDNameAll.

func (*Label) IsAnySource added in v0.9.0

func (l *Label) IsAnySource() bool

IsAnySource return if the label was set with source "any".

func (*Label) IsValid

func (l *Label) IsValid() bool

IsValid returns true if Key != "".

func (*Label) Matches

func (l *Label) Matches(target *Label) bool

Matches returns true if it's a special label or the label equals the target.

func (*Label) String

func (l *Label) String() string

String returns the string representation of Label in the for of Source:Key=Value or Source:Key if Value is empty.

func (*Label) UnmarshalJSON

func (l *Label) UnmarshalJSON(data []byte) error

UnmarshalJSON TODO create better explanation about unmarshall with examples

type LabelArray added in v0.9.0

type LabelArray []*Label

LabelArray is an array of labels forming a set

func NewLabelArrayFromModel added in v0.9.0

func NewLabelArrayFromModel(base []string) LabelArray

NewLabelArrayFromModel creates labels from string array.

func ParseLabelArray added in v0.9.0

func ParseLabelArray(labels ...string) LabelArray

ParseLabelArray parses a list of labels and returns a LabelArray

func ParseLabelArrayFromArray added in v0.9.0

func ParseLabelArrayFromArray(base []string) LabelArray

ParseLabelArrayFromArray converts an array of strings as labels and returns a LabelArray

func (LabelArray) Contains added in v0.9.0

func (ls LabelArray) Contains(needed LabelArray) bool

Contains returns true if all ls contains all the labels in needed. If needed contains no labels, Contains() will always return true

func (LabelArray) Get added in v0.9.0

func (ls LabelArray) Get(key string) string

Get returns the value for the provided key. Implementation of the k8s.io/apimachinery/pkg/labels.Labels interface.

func (LabelArray) Has added in v0.9.0

func (ls LabelArray) Has(key string) bool

Has returns whether the provided key exists. Implementation of the k8s.io/apimachinery/pkg/labels.Labels interface.

func (LabelArray) Lacks added in v0.9.0

func (ls LabelArray) Lacks(needed LabelArray) LabelArray

Lacks is identical to Contains but returns all missing labels

type LabelPrefix

type LabelPrefix struct {
	// Ignore if true will cause this prefix to be ignored insted of being accepted
	Ignore bool   `json:"invert"`
	Prefix string `json:"prefix"`
	Source string `json:"source"`
}

LabelPrefix is the cilium's representation of a container label.

func (LabelPrefix) Matches added in v0.9.0

func (p LabelPrefix) Matches(l *Label) bool

Matches returns true if the label is matched by the LabelPrefix. The Ignore flag has no effect at this point.

func (LabelPrefix) String

func (p LabelPrefix) String() string

String returns a human readable representation of the LabelPrefix

type LabelPrefixCfg

type LabelPrefixCfg struct {
	Version       int            `json:"version"`
	LabelPrefixes []*LabelPrefix `json:"valid-prefixes"`
	// contains filtered or unexported fields
}

LabelPrefixCfg is the label prefix configuration to filter labels of started containers.

func ParseLabelPrefixCfg added in v0.9.0

func ParseLabelPrefixCfg(prefixes []string, file string) (*LabelPrefixCfg, error)

ParseLabelPrefixCfg parses valid label prefixes from a file and from a slice of valid prefixes. Both are optional. If both are provided, both list are appended together.

func (*LabelPrefixCfg) Append

func (cfg *LabelPrefixCfg) Append(l *LabelPrefix)

Append adds an additional allowed label prefix to the configuration

func (*LabelPrefixCfg) FilterLabels

func (cfg *LabelPrefixCfg) FilterLabels(lbls Labels) Labels

FilterLabels returns Labels from the given labels that have the same source and the same prefix as one of lpc valid prefixes.

type Labels

type Labels map[string]*Label

Labels is a map of labels where the map's key is the same as the label's key.

func Map2Labels

func Map2Labels(m map[string]string, source string) Labels

Map2Labels transforms in the form: map[key(string)]value(string) into Labels. The source argument will overwrite the source written in the key of the given map. Example: l := Map2Labels(map[string]string{"k8s:foo": "bar"}, "cilium") fmt.Printf("%+v\n", l)

map[string]Label{"foo":Label{Key:"foo", Value:"bar", Source:"cilium"}}

func NewLabelsFromModel

func NewLabelsFromModel(base []string) Labels

NewLabelsFromModel creates labels from string array.

func ParseStringLabels

func ParseStringLabels(strLbls []string) Labels

ParseStringLabels returns label representations from strings.

func (Labels) AppendPrefixInKey

func (l Labels) AppendPrefixInKey(prefix string) Labels

AppendPrefixInKey appends the given prefix to all the Key's of the map and the respective Labels' Key.

func (Labels) DeepCopy

func (l Labels) DeepCopy() Labels

DeepCopy returns a deep copy of the labels.

func (Labels) DeleteMarked

func (l Labels) DeleteMarked() bool

DeleteMarked deletes the labels which have the DeletionMark set and returns true if any of them were deleted.

func (Labels) GetModel

func (l Labels) GetModel() []string

GetModel returns model with all the values of the labels.

func (Labels) MarkAllForDeletion

func (l Labels) MarkAllForDeletion()

MarkAllForDeletion marks all the labels with the DeletionMark.

func (Labels) MergeLabels

func (l Labels) MergeLabels(from Labels)

MergeLabels merges labels from into to. It overwrites all labels with the same Key as from written into to. Example: to := Labels{Label{key1, value1, source1}, Label{key2, value3, source4}} from := Labels{Label{key1, value3, source4}} to.MergeLabels(from) fmt.Printf("%+v\n", to)

Labels{Label{key1, value3, source4}, Label{key2, value3, source4}}

func (Labels) SHA256Sum

func (l Labels) SHA256Sum() string

SHA256Sum calculates l' internal SHA256Sum. For a particular set of labels is guarantee that it will always have the same SHA256Sum.

func (Labels) ToSlice

func (l Labels) ToSlice() []*Label

ToSlice returns a slice of label with the values of the given Labels' map.

type OpLabels

type OpLabels struct {
	// Active labels that are enabled and disabled but not deleted
	Custom Labels
	// Labels derived from orchestration system
	Orchestration Labels
	// Orchestration labels which have been disabled
	Disabled Labels
}

OpLabels represents the the possible types.

func NewOplabelsFromModel

func NewOplabelsFromModel(base *models.LabelConfiguration) *OpLabels

NewOplabelsFromModel creates new label from the model.

func (*OpLabels) DeepCopy

func (o *OpLabels) DeepCopy() *OpLabels

DeepCopy returns deep copy of the label.

func (*OpLabels) Enabled

func (o *OpLabels) Enabled() Labels

Enabled returns map of enabled labels.

Jump to

Keyboard shortcuts

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