cilium: github.com/cilium/cilium/pkg/labels Index | Files | Directories

package labels

import "github.com/cilium/cilium/pkg/labels"

Package api defines the API of the Cilium network policy interface

Index

Package Files

array.go arraylist.go doc.go filter.go labels.go oplabels.go

Constants

const (
    // PathDelimiter is the delimiter used in the labels paths.
    PathDelimiter = "."

    // 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"

    // IDNameCluster is the label used to identify an unspecified endpoint
    // inside the cluster
    IDNameCluster = "cluster"

    // IDNameHealth is the label used for the local cilium-health endpoint
    IDNameHealth = "health"

    // IDNameInit is the label used to identify any endpoint that has not
    // received any labels yet.
    IDNameInit = "init"

    // IDNameNone is the label used to identify no endpoint or other L3 entity.
    // It will never be assigned and this "label" is here for consistency with
    // other Entities.
    IDNameNone = "none"

    // IDNameUnmanaged is the label used to identify unmanaged endpoints
    IDNameUnmanaged = "unmanaged"

    // IDNameUnknown is the label used to to identify an endpoint with an
    // unknown identity.
    IDNameUnknown = "unknown"
)
const (
    // LabelSourceUnspec is a label with unspecified source
    LabelSourceUnspec = "unspec"

    // LabelSourceAny is a label that matches any source
    LabelSourceAny = "any"

    // LabelSourceAnyKeyPrefix is prefix of a "any" label
    LabelSourceAnyKeyPrefix = LabelSourceAny + "."

    // LabelSourceK8s is a label imported from Kubernetes
    LabelSourceK8s = "k8s"

    // LabelSourceMesos is a label imported from Mesos
    LabelSourceMesos = "mesos"

    // LabelSourceK8sKeyPrefix is prefix of a Kubernetes label
    LabelSourceK8sKeyPrefix = LabelSourceK8s + "."

    // LabelSourceContainer is a label imported from the container runtime
    LabelSourceContainer = "container"

    // LabelSourceReserved is the label source for reserved types.
    LabelSourceReserved = "reserved"

    // LabelSourceCIDR is the label source for generated CIDRs.
    LabelSourceCIDR = "cidr"

    // LabelSourceReservedKeyPrefix is the prefix of a reserved label
    LabelSourceReservedKeyPrefix = LabelSourceReserved + "."

    // LabelKeyFixedIdentity is the label that can be used to define a fixed
    // identity.
    LabelKeyFixedIdentity = "io.cilium.fixed-identity"

    // LabelSourceCiliumGenerated is for labels auto-generated by cilium without
    // user input
    LabelSourceCiliumGenerated = "cilium-generated"
)
const (
    // LPCfgFileVersion represents the version of a Label Prefix Configuration File
    LPCfgFileVersion = 1
)

Variables

var (
    // LabelHealth is the label used for health.
    LabelHealth = Labels{IDNameHealth: NewLabel(IDNameHealth, "", LabelSourceReserved)}
)

func GenerateK8sLabelString Uses

func GenerateK8sLabelString(k, v string) string

GenerateK8sLabelString generates the string representation of a label with the provided source, key, and value in the format "LabelSourceK8s:key=value".

func GetCiliumKeyFrom Uses

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 Uses

func GetExtendedKeyFrom(str string) string

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

func ParseLabelPrefixCfg Uses

func ParseLabelPrefixCfg(prefixes []string, file string) 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.

type Label Uses

type Label struct {
    Key   string `json:"key"`
    Value string `json:"value,omitempty"`
    // Source can be one of the values present in const.go (e.g.: LabelSourceContainer)
    Source string `json:"source"`
}

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

func NewLabel Uses

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 LabelSourceUnspec. If key starts with '$', the source will be overwritten with LabelSourceReserved. 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 Uses

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 ParseSelectLabel Uses

func ParseSelectLabel(str string) Label

ParseSelectLabel returns a selecting label representation of the given string. Unlike ParseLabel, if source is unspecified, the source defaults to LabelSourceAny

func (*Label) Equals Uses

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

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

func (Label) FormatForKVStore Uses

func (l Label) FormatForKVStore() string

FormatForKVStore returns the label as a formatted string, ending in a semicolon

DO NOT BREAK THE FORMAT OF THIS. THE RETURNED STRING IS USED AS PART OF THE KEY IN THE KEY-VALUE STORE.

Non-pointer receiver allows this to be called on a value in a map.

func (*Label) GetExtendedKey Uses

func (l *Label) GetExtendedKey() string

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

func (*Label) IsAllLabel Uses

func (l *Label) IsAllLabel() bool

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

func (*Label) IsAnySource Uses

func (l *Label) IsAnySource() bool

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

func (*Label) IsReservedSource Uses

func (l *Label) IsReservedSource() bool

IsReservedSource return if the label was set with source "Reserved".

func (*Label) IsValid Uses

func (l *Label) IsValid() bool

IsValid returns true if Key != "".

func (*Label) Matches Uses

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

Matches returns true if l matches the target

func (*Label) String Uses

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 Uses

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

UnmarshalJSON TODO create better explanation about unmarshall with examples

type LabelArray Uses

type LabelArray []Label

LabelArray is an array of labels forming a set

func NewLabelArrayFromSortedList Uses

func NewLabelArrayFromSortedList(list string) LabelArray

NewLabelArrayFromSortedList returns labels based on the output of SortedList() Trailing ';' will result in an empty key that must be filtered out.

func NewSelectLabelArrayFromModel Uses

func NewSelectLabelArrayFromModel(base []string) LabelArray

NewSelectLabelArrayFromModel parses a slice of strings and converts them into an array of selecting labels, sorted by the key.

func ParseLabelArray Uses

func ParseLabelArray(labels ...string) LabelArray

ParseLabelArray parses a list of labels and returns a LabelArray

func ParseLabelArrayFromArray Uses

func ParseLabelArrayFromArray(base []string) LabelArray

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

func ParseSelectLabelArray Uses

func ParseSelectLabelArray(labels ...string) LabelArray

ParseSelectLabelArray parses a list of select labels and returns a LabelArray

func ParseSelectLabelArrayFromArray Uses

func ParseSelectLabelArrayFromArray(base []string) LabelArray

ParseSelectLabelArrayFromArray converts an array of strings as select labels and returns a LabelArray

func (LabelArray) Contains Uses

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) DeepCopy Uses

func (ls LabelArray) DeepCopy() LabelArray

DeepCopy returns a deep copy of the labels.

func (LabelArray) Get Uses

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) GetModel Uses

func (ls LabelArray) GetModel() []string

GetModel returns the LabelArray as a string array with fully-qualified labels. The output is parseable by ParseLabelArrayFromArray

func (LabelArray) Has Uses

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

func (ls LabelArray) Labels() Labels

Labels returns the LabelArray as Labels

func (LabelArray) Lacks Uses

func (ls LabelArray) Lacks(needed LabelArray) LabelArray

Lacks is identical to Contains but returns all missing labels

func (LabelArray) Same Uses

func (ls LabelArray) Same(b LabelArray) bool

Same returns true if the label arrays are the same, i.e., have the same labels in the same order.

func (LabelArray) Sort Uses

func (ls LabelArray) Sort() LabelArray

Sort is an internal utility to return all LabelArrays in sorted order, when the source material may be unsorted. 'ls' is sorted in-place, but also returns the sorted array for convenience.

func (LabelArray) String Uses

func (ls LabelArray) String() string

func (LabelArray) StringMap Uses

func (ls LabelArray) StringMap() map[string]string

StringMap converts LabelArray into map[string]string Note: The source is included in the keys with a ':' separator. Note: LabelArray does not deduplicate entries, as it is an array. It is possible for the output to contain fewer entries when the source and key are repeated in a LabelArray, as that is the key of the output. This scenario is not expected.

type LabelArrayList Uses

type LabelArrayList []LabelArray

LabelArrayList is an array of LabelArrays. It is primarily intended as a simple collection

func (LabelArrayList) DeepCopy Uses

func (ls LabelArrayList) DeepCopy() LabelArrayList

DeepCopy returns a deep copy of the LabelArray, with each element also copied.

func (LabelArrayList) GetModel Uses

func (ls LabelArrayList) GetModel() [][]string

GetModel returns the LabelArrayList as a [][]string. Each member LabelArray becomes a []string.

type LabelPrefix Uses

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"`
    // contains filtered or unexported fields
}

LabelPrefix is the cilium's representation of a container label. +k8s:deepcopy-gen=false +k8s:openapi-gen=false

func (LabelPrefix) String Uses

func (p LabelPrefix) String() string

String returns a human readable representation of the LabelPrefix

type Labels Uses

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 FilterLabels Uses

func FilterLabels(lbls Labels) (identityLabels, informationLabels Labels)

FilterLabels returns Labels from the given labels that have the same source and the same prefix as one of lpc valid prefixes, as well as labels that do not match the aforementioned filtering criteria.

func Map2Labels Uses

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 Uses

func NewLabelsFromModel(base []string) Labels

NewLabelsFromModel creates labels from string array.

func NewLabelsFromSortedList Uses

func NewLabelsFromSortedList(list string) Labels

NewLabelsFromSortedList returns labels based on the output of SortedList()

func (Labels) AppendPrefixInKey Uses

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) Equals Uses

func (l Labels) Equals(other Labels) bool

Equals returns true if the two Labels contain the same set of labels.

func (Labels) FindReserved Uses

func (l Labels) FindReserved() Labels

FindReserved locates all labels with reserved source in the labels and returns a copy of them. If there are no reserved labels, returns nil. TODO: return LabelArray as it is likely faster

func (Labels) GetFromSource Uses

func (l Labels) GetFromSource(source string) Labels

GetFromSource returns all labels that are from the given source.

func (Labels) GetModel Uses

func (l Labels) GetModel() []string

GetModel returns model with all the values of the labels.

func (Labels) GetPrintableModel Uses

func (l Labels) GetPrintableModel() (res []string)

GetPrintableModel turns the Labels into a sorted list of strings representing the labels, with CIDRs deduplicated (ie, only provide the most specific CIDR).

func (Labels) IsReserved Uses

func (l Labels) IsReserved() bool

IsReserved returns true if any of the labels has a reserved source.

func (Labels) LabelArray Uses

func (l Labels) LabelArray() LabelArray

LabelArray returns the labels as label array, sorted by the key.

func (Labels) MergeLabels Uses

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 Uses

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) SortedList Uses

func (l Labels) SortedList() []byte

SortedList returns the labels as a sorted list, separated by semicolon

DO NOT BREAK THE FORMAT OF THIS. THE RETURNED STRING IS USED AS KEY IN THE KEY-VALUE STORE.

func (Labels) String Uses

func (l Labels) String() string

String returns the map of labels as human readable string

func (Labels) StringMap Uses

func (l Labels) StringMap() map[string]string

StringMap converts Labels into map[string]string

func (Labels) ToSlice Uses

func (l Labels) ToSlice() []Label

ToSlice returns a slice of label with the values of the given Labels' map, sorted by the key.

type OpLabels Uses

type OpLabels struct {
    // Active labels that are enabled and disabled but not deleted
    Custom Labels

    // Labels derived from orchestration system
    OrchestrationIdentity Labels

    // orchestrationIdentity labels which have been disabled
    Disabled Labels

    // orchestrationInfo - labels from orchestration which are not used in determining a security identity
    OrchestrationInfo Labels
}

OpLabels represents the the possible types.

func NewOpLabels Uses

func NewOpLabels() OpLabels

NewOpLabels creates new initialized OpLabels

func (*OpLabels) AllLabels Uses

func (o *OpLabels) AllLabels() Labels

AllLabels returns all Labels within the provided OpLabels.

func (*OpLabels) GetIdentityLabel Uses

func (o *OpLabels) GetIdentityLabel(key string) (l Label, found bool)

GetIdentityLabel returns the value of the given Key from all IdentityLabels.

func (*OpLabels) IdentityLabels Uses

func (o *OpLabels) IdentityLabels() Labels

IdentityLabels returns map of labels that are used when determining a security identity.

func (*OpLabels) ModifyIdentityLabels Uses

func (o *OpLabels) ModifyIdentityLabels(addLabels, delLabels Labels) (changed bool, err error)

func (*OpLabels) ReplaceIdentityLabels Uses

func (o *OpLabels) ReplaceIdentityLabels(l Labels, logger *logrus.Entry) bool

func (*OpLabels) ReplaceInformationLabels Uses

func (o *OpLabels) ReplaceInformationLabels(l Labels, logger *logrus.Entry) bool

func (*OpLabels) SplitUserLabelChanges Uses

func (o *OpLabels) SplitUserLabelChanges(lbls Labels) (add, del Labels)

SplitUserLabelChanges returns labels to 'add' and 'del'ete to make the custom labels match 'lbls' FIXME: Somewhere in the code we crash if the returned maps are non-nil but length 0. We retain this behaviour here because it's easier.

Directories

PathSynopsis
cidrPackage cidr provides helper methods for generating labels for CIDRs which are partially derived from node state.
model

Package labels imports 14 packages (graph) and is imported by 34 packages. Updated 2019-07-20. Refresh now. Tools for package owners.