core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvaluateRule

func EvaluateRule(value resource.Quantity, rule telempol.TASPolicyRule) bool

EvaluateRule returns a boolean after implementing the function described in the TASPolicyRule. The rule is transformed into a function inside of the method.

Types

type AddStrategyInvocation added in v0.3.0

type AddStrategyInvocation struct {
	I interface{}
	// contains filtered or unexported fields
}

AddStrategyInvocation is used to test the times that AddStrategy is called.

type Enforceable

type Enforceable interface {
	Enforce(enforcer *MetricEnforcer, cache cache.Reader) (int, error)
	Cleanup(enforcer *MetricEnforcer, policyName string) error
}

Enforceable enforce strategies and clean up after strategies are removed.

type Enforcer

type Enforcer interface {
	RegisterStrategyType(strategy Interface)
	UnregisterStrategyType(strategy Interface)
	IsRegistered(string) bool
	AddStrategy(Interface, string)
	RemoveStrategy(Interface, string)
	EnforceRegisteredStrategies(cache.Reader, time.Ticker)
}

Enforcer registers strategies by type, adds specific strategies to a registry, and Enforces those strategies.

type Interface

type Interface interface {
	Violated(cache cache.Reader) map[string]interface{}
	StrategyType() string
	Equals(Interface) bool
	GetPolicyName() string
	SetPolicyName(string)
}

Interface describes expected behavior of a specific strategy.

type MetricEnforcer

type MetricEnforcer struct {
	RegisteredStrategies map[string]map[Interface]interface{}
	KubeClient           kubernetes.Interface
	sync.RWMutex
}

MetricEnforcer instruments behavior to register strategies and trigger their enforcement actions.

func NewEnforcer

func NewEnforcer(kubeClient kubernetes.Interface) *MetricEnforcer

NewEnforcer returns an enforcer with the passed arguments and an empty strategy store.

func (*MetricEnforcer) AddStrategy

func (e *MetricEnforcer) AddStrategy(str Interface, strategyType string)

AddStrategy includes the specific strategy under its type in the strategy registry.

func (*MetricEnforcer) EnforceRegisteredStrategies

func (e *MetricEnforcer) EnforceRegisteredStrategies(cache cache.Reader, timer time.Ticker)

EnforceRegisteredStrategies runs periodically, enforcing each of the registered strategy types in the registry.

func (*MetricEnforcer) IsRegistered

func (e *MetricEnforcer) IsRegistered(str string) bool

IsRegistered checks to see if a passed strategy is already being enforced.

func (*MetricEnforcer) RegisterStrategyType

func (e *MetricEnforcer) RegisterStrategyType(str Interface)

RegisterStrategyType adds the type of strategy as top level entry in the registry.

func (*MetricEnforcer) RegisteredStrategyTypes

func (e *MetricEnforcer) RegisteredStrategyTypes() []string

RegisteredStrategyTypes returns a slice of the names of strategy types currently registered with the enforcer.

func (*MetricEnforcer) RemoveStrategy

func (e *MetricEnforcer) RemoveStrategy(str Interface, strategyType string)

RemoveStrategy will take a strategy out of the enforcer if it's currently registered.

func (*MetricEnforcer) UnregisterStrategyType

func (e *MetricEnforcer) UnregisterStrategyType(str Interface)

UnregisterStrategyType removes the passed strategy from the registry if it exists there. If it doesn't exist it fails silently.

type MockStrategy

type MockStrategy struct {
	StrategyTypeMock     string
	RegisteredStrategies map[string]map[Interface]interface{}
	AddedStrategies      AddStrategyInvocation
	RemovedStrategies    interface{}
}

MockStrategy is used in the tests for the core and other packages.

func (*MockStrategy) AddStrategy added in v0.3.0

func (v *MockStrategy) AddStrategy(i Interface, s string)

AddStrategy is a method in Mock strategy.

func (*MockStrategy) Clean added in v0.3.0

Clean returns nil error.

func (*MockStrategy) Enforce

func (v *MockStrategy) Enforce(enforcer *MetricEnforcer, cache cache.Reader) (int, error)

Enforce returns 0 value and nil error.

func (*MockStrategy) EnforceRegisteredStrategies added in v0.3.0

func (v *MockStrategy) EnforceRegisteredStrategies(cache.Reader, time.Ticker)

EnforceRegisteredStrategies is a method in Mock strategy.

func (*MockStrategy) Equals

func (v *MockStrategy) Equals(o Interface) bool

Equals returns the value of checking if the strategy types are the same.

func (*MockStrategy) GetPolicyName

func (v *MockStrategy) GetPolicyName() string

GetPolicyName gets the mock strategy policy name.

func (*MockStrategy) IsRegistered added in v0.3.0

func (v *MockStrategy) IsRegistered(strategy string) bool

IsRegistered is a method in Mock strategy.

func (*MockStrategy) RegisterStrategyType added in v0.3.0

func (v *MockStrategy) RegisterStrategyType(strategy Interface)

RegisterStrategyType is a method in Mock strategy.

func (*MockStrategy) RemoveStrategy added in v0.3.0

func (v *MockStrategy) RemoveStrategy(i Interface, s string)

RemoveStrategy is a method in Mock strategy.

func (*MockStrategy) SetPolicyName

func (v *MockStrategy) SetPolicyName(string)

SetPolicyName sets the policy name of the mock strategy.

func (*MockStrategy) StrategyType

func (v *MockStrategy) StrategyType() string

StrategyType returns the Strategy type of the mock.

func (*MockStrategy) UnregisterStrategyType added in v0.3.0

func (v *MockStrategy) UnregisterStrategyType(Interface)

UnregisterStrategyType is a method in Mock strategy.

func (*MockStrategy) Violated

func (v *MockStrategy) Violated(cache cache.Reader) map[string]interface{}

Violated gets the cache values from MockStrategy and returns the map interface.

type NodeSortableMetric

type NodeSortableMetric struct {
	NodeName    string
	MetricValue resource.Quantity
}

NodeSortableMetric type is necessary in order to call the sort.Slice method. Note lack of usage of time windows or stamps.

func OrderedList

func OrderedList(metricsInfo metrics.NodeMetricsInfo, operator string) []NodeSortableMetric

OrderedList will return a list of nodes ordered by their linked metric and operator. TODO: Make this method more generic so it can use objects other than nodes.

Jump to

Keyboard shortcuts

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