constraints

package
Version: v0.0.0-...-a69e935 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownConstraintType is the error when unknown Constraint.Type
	// enum is processed.
	ErrUnknownConstraintType = errors.New(
		"unknown enum value for Constraint.Type")

	// ErrUnknownLabelCondition is the error when unknown
	// LabelConstraint.Condition enum is processed.
	ErrUnknownLabelCondition = errors.New(
		"unknown enum value for LabelConstraint.Condition")
)

Functions

func HasExclusiveLabel

func HasExclusiveLabel(labels []*peloton.Label) bool

func IsNonExclusiveConstraint

func IsNonExclusiveConstraint(constraint *pod.Constraint) bool

IsNonExclusiveConstraint returns true if all components of the constraint specification do not use a host label constraint for exclusive attribute.

Types

type EvaluateResult

type EvaluateResult int

EvaluateResult is an enum indicating various possible result.

const (
	// EvaluateResultMatch indicates that given constraint fully matched
	// input labelValues.
	EvaluateResultMatch EvaluateResult = iota

	// EvaluateResultMismatch indicates that given constraint mismatched
	// input labelValues.
	EvaluateResultMismatch

	// EvaluateResultNotApplicable indicates that given constraint is not
	// applicable to input values.
	EvaluateResultNotApplicable
)

type Evaluator

type Evaluator interface {
	// Evaluate returns true if given constraint is satisfied on
	// these labelValues.
	Evaluate(
		constraint *pod.Constraint,
		labelValues LabelValues,
	) (EvaluateResult, error)
}

Evaluator is the interface to evaluate whether given LabelValueSet satisifies given constraint.

func NewEvaluator

func NewEvaluator(kind pod.LabelConstraint_Kind) Evaluator

NewEvaluator return a new instance of evaluator which filters out constraints of different kind.

type LabelValues

type LabelValues map[string]map[string]uint32

LabelValues tracks how many times a value presents for a given label key. First level key is label key, second level key is label value. This is the subject of constraint evaluation process.

func GetHostLabelValues

func GetHostLabelValues(
	hostname string,
	labels []*peloton.Label,
) LabelValues

GetHostLabelValues returns label counts for a host and its labels, which can be used to evaluate a constraint. NOTE: `hostname` is added unconditionally, to make sure hostname based constraints can be done regardless of label configuration.

Jump to

Keyboard shortcuts

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