kubernetes

package
v0.0.0-...-9d39b53 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SetConditionTimeout     = 10 * time.Second
	SetConditionRetryPeriod = 50 * time.Millisecond
)
View Source
const (
	DefaultMaxGracePeriod   time.Duration = 8 * time.Minute
	DefaultEvictionOverhead time.Duration = 30 * time.Second

	ConditionDrainedScheduled = "DrainScheduled"
	DefaultSkipDrain          = false
)

Default pod eviction settings.

View Source
const Component = "draino"

Component is the name of this application.

View Source
const (
	// DefaultDrainBuffer is the default minimum time between node drains.
	DefaultDrainBuffer = 10 * time.Minute
)

Variables

View Source
var (
	MeasureNodesCordoned       = stats.Int64("draino/nodes_cordoned", "Number of nodes cordoned.", stats.UnitDimensionless)
	MeasureNodesUncordoned     = stats.Int64("draino/nodes_uncordoned", "Number of nodes uncordoned.", stats.UnitDimensionless)
	MeasureNodesDrained        = stats.Int64("draino/nodes_drained", "Number of nodes drained.", stats.UnitDimensionless)
	MeasureNodesDrainScheduled = stats.Int64("draino/nodes_drainScheduled", "Number of nodes drain scheduled.", stats.UnitDimensionless)

	TagNodeName, _ = tag.NewKey("node_name")
	TagResult, _   = tag.NewKey("result")
)

Opencensus measurements.

Functions

func BuildConfigFromFlags

func BuildConfigFromFlags(apiserver, kubecfg string) (*rest.Config, error)

BuildConfigFromFlags is clientcmd.BuildConfigFromFlags with no annoying dependencies on glog. https://godoc.org/k8s.io/client-go/tools/clientcmd#BuildConfigFromFlags

func ConvertLabelsToFilterExpr

func ConvertLabelsToFilterExpr(labelsSlice []string) (*string, error)

ConvertLabelsToFilterExpr Convert old list labels into new expression syntax

func HasDrainRetryAnnotation

func HasDrainRetryAnnotation(n *core.Node) bool

func IsAlreadyScheduledError

func IsAlreadyScheduledError(err error) bool

func IsMarkedForDrain

func IsMarkedForDrain(n *core.Node) bool

func IsTimeout

func IsTimeout(err error) bool

IsTimeout returns true if the supplied error was caused by a timeout.

func LocalStoragePodFilter

func LocalStoragePodFilter(p core.Pod) (bool, error)

LocalStoragePodFilter returns true if the supplied pod does not have local storage, i.e. does not use any 'empty dir' volumes.

func MirrorPodFilter

func MirrorPodFilter(p core.Pod) (bool, error)

MirrorPodFilter returns true if the supplied pod is not a mirror pod, i.e. a pod created by a manifest on the node rather than the API server.

func NewAlreadyScheduledError

func NewAlreadyScheduledError() error

func NewEventRecorder

func NewEventRecorder(c kubernetes.Interface) record.EventRecorder

NewEventRecorder returns a new record.EventRecorder for the given client.

func NewNodeLabelFilter

func NewNodeLabelFilter(expressionStr *string, log *zap.Logger) (func(o interface{}) bool, error)

NewNodeLabelFilter returns a filter that returns true if the supplied node satisfies the boolean expression

func RetryWithTimeout

func RetryWithTimeout(f func() error, retryPeriod, timeout time.Duration) error

func UnreplicatedPodFilter

func UnreplicatedPodFilter(p core.Pod) (bool, error)

UnreplicatedPodFilter returns true if the pod is replicated, i.e. is managed by a controller (deployment, daemonset, statefulset, etc) of some sort.

Types

type APICordonDrainer

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

APICordonDrainer drains Kubernetes nodes via the Kubernetes API.

func NewAPICordonDrainer

func NewAPICordonDrainer(c kubernetes.Interface, ao ...APICordonDrainerOption) *APICordonDrainer

NewAPICordonDrainer returns a CordonDrainer that cordons and drains nodes via the Kubernetes API.

func (*APICordonDrainer) Cordon

func (d *APICordonDrainer) Cordon(n *core.Node, mutators ...nodeMutatorFn) error

Cordon the supplied node. Marks it unschedulable for new pods.

func (*APICordonDrainer) Drain

func (d *APICordonDrainer) Drain(n *core.Node) error

Drain the supplied node. Evicts the node of all but mirror and DaemonSet pods.

func (*APICordonDrainer) MarkDrain

func (d *APICordonDrainer) MarkDrain(n *core.Node, when, finish time.Time, failed bool) error

MarkDrain set a condition on the node to mark that that drain is scheduled.

func (*APICordonDrainer) Uncordon

func (d *APICordonDrainer) Uncordon(n *core.Node, mutators ...nodeMutatorFn) error

Uncordon the supplied node. Marks it schedulable for new pods.

type APICordonDrainerOption

type APICordonDrainerOption func(d *APICordonDrainer)

APICordonDrainerOption configures an APICordonDrainer.

func EvictionHeadroom

func EvictionHeadroom(h time.Duration) APICordonDrainerOption

EvictionHeadroom configures an amount of time to wait in addition to the MaxGracePeriod for the API server to report a pod deleted.

func MaxGracePeriod

func MaxGracePeriod(m time.Duration) APICordonDrainerOption

MaxGracePeriod configures the maximum time to wait for a pod eviction. Pod containers will be allowed this much time to shutdown once they receive a SIGTERM before they are sent a SIGKILL.

func WithAPICordonDrainerLogger

func WithAPICordonDrainerLogger(l *zap.Logger) APICordonDrainerOption

WithAPICordonDrainerLogger configures a APICordonDrainer to use the supplied logger.

func WithPodFilter

func WithPodFilter(f PodFilterFunc) APICordonDrainerOption

WithPodFilter configures a filter that may be used to exclude certain pods from eviction when draining.

func WithSkipDrain

func WithSkipDrain(b bool) APICordonDrainerOption

WithDrain determines if we're actually going to drain nodes

type AlreadyScheduledError

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

type CordonDrainer

type CordonDrainer interface {
	Cordoner
	Drainer
}

A CordonDrainer both cordons and drains nodes!

type Cordoner

type Cordoner interface {
	// Cordon the supplied node. Marks it unschedulable for new pods.
	Cordon(n *core.Node, mutators ...nodeMutatorFn) error

	// Uncordon the supplied node. Marks it schedulable for new pods.
	Uncordon(n *core.Node, mutators ...nodeMutatorFn) error
}

A Cordoner cordons nodes.

type DrainScheduler

type DrainScheduler interface {
	HasSchedule(name string) (has, failed bool)
	Schedule(node *v1.Node) (time.Time, error)
	DeleteSchedule(name string)
}

func NewDrainSchedules

func NewDrainSchedules(drainer Drainer, eventRecorder record.EventRecorder, period time.Duration, logger *zap.Logger) DrainScheduler

type DrainSchedules

type DrainSchedules struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*DrainSchedules) DeleteSchedule

func (d *DrainSchedules) DeleteSchedule(name string)

func (*DrainSchedules) HasSchedule

func (d *DrainSchedules) HasSchedule(name string) (has, failed bool)

func (*DrainSchedules) Schedule

func (d *DrainSchedules) Schedule(node *v1.Node) (time.Time, error)

func (*DrainSchedules) WhenNextSchedule

func (d *DrainSchedules) WhenNextSchedule() time.Time

type Drainer

type Drainer interface {
	// Drain the supplied node. Evicts the node of all but mirror and DaemonSet pods.
	Drain(n *core.Node) error
	MarkDrain(n *core.Node, when, finish time.Time, failed bool) error
}

A Drainer drains nodes.

type DrainingResourceEventHandler

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

A DrainingResourceEventHandler cordons and drains any added or updated nodes.

func NewDrainingResourceEventHandler

NewDrainingResourceEventHandler returns a new DrainingResourceEventHandler.

func (*DrainingResourceEventHandler) HandleNode

func (h *DrainingResourceEventHandler) HandleNode(n *core.Node)

func (*DrainingResourceEventHandler) OnAdd

func (h *DrainingResourceEventHandler) OnAdd(obj interface{})

OnAdd cordons and drains the added node.

func (*DrainingResourceEventHandler) OnDelete

func (h *DrainingResourceEventHandler) OnDelete(obj interface{})

func (*DrainingResourceEventHandler) OnUpdate

func (h *DrainingResourceEventHandler) OnUpdate(_, newObj interface{})

OnUpdate cordons and drains the updated node.

type DrainingResourceEventHandlerOption

type DrainingResourceEventHandlerOption func(d *DrainingResourceEventHandler)

DrainingResourceEventHandlerOption configures an DrainingResourceEventHandler.

func WithConditionsFilter

func WithConditionsFilter(conditions []string) DrainingResourceEventHandlerOption

WithConditionsFilter configures which conditions should be handled.

func WithDrainBuffer

WithDrainBuffer configures the minimum time between scheduled drains.

func WithLogger

WithLogger configures a DrainingResourceEventHandler to use the supplied logger.

type NodeProcessed

type NodeProcessed map[types.UID]bool

NodeProcessed tracks whether nodes have been processed before using a map.

func NewNodeProcessed

func NewNodeProcessed() NodeProcessed

NewNodeProcessed returns a new node processed filter.

func (NodeProcessed) Filter

func (processed NodeProcessed) Filter(o interface{}) bool

Filter returns true if the supplied object is a node that this filter has not seen before. It is not threadsafe and should always be the last filter applied.

type NodeStore

type NodeStore interface {
	// Get an node by name. Returns an error if the node does not exist.
	Get(name string) (*core.Node, error)
}

An NodeStore is a cache of node resources.

type NodeWatch

type NodeWatch struct {
	cache.SharedInformer
}

An NodeWatch is a cache of node resources that notifies registered handlers when its contents change.

func NewNodeWatch

NewNodeWatch creates a watch on node resources. Nodes are cached and the provided ResourceEventHandlers are called when the cache changes.

func (*NodeWatch) Get

func (w *NodeWatch) Get(name string) (*core.Node, error)

Get an node by name. Returns an error if the node does not exist.

type NoopCordonDrainer

type NoopCordonDrainer struct{}

A NoopCordonDrainer does nothing.

func (*NoopCordonDrainer) Cordon

func (d *NoopCordonDrainer) Cordon(n *core.Node, mutators ...nodeMutatorFn) error

Cordon does nothing.

func (*NoopCordonDrainer) Drain

func (d *NoopCordonDrainer) Drain(n *core.Node) error

Drain does nothing.

func (*NoopCordonDrainer) MarkDrain

func (d *NoopCordonDrainer) MarkDrain(n *core.Node, when, finish time.Time, failed bool) error

MarkDrain does nothing.

func (*NoopCordonDrainer) Uncordon

func (d *NoopCordonDrainer) Uncordon(n *core.Node, mutators ...nodeMutatorFn) error

Uncordon does nothing.

type PodFilterFunc

type PodFilterFunc func(p core.Pod) (bool, error)

A PodFilterFunc returns true if the supplied pod passes the filter.

func NewDaemonSetPodFilter

func NewDaemonSetPodFilter(client kubernetes.Interface) PodFilterFunc

NewDaemonSetPodFilter returns a FilterFunc that returns true if the supplied pod is not managed by an extant DaemonSet.

func NewPodFilters

func NewPodFilters(filters ...PodFilterFunc) PodFilterFunc

NewPodFilters returns a FilterFunc that returns true if all of the supplied FilterFuncs return true.

func NewStatefulSetPodFilter

func NewStatefulSetPodFilter(client kubernetes.Interface) PodFilterFunc

NewStatefulSetPodFilter returns a FilterFunc that returns true if the supplied pod is not managed by an extant StatefulSet.

func UnprotectedPodFilter

func UnprotectedPodFilter(annotations ...string) PodFilterFunc

UnprotectedPodFilter returns a FilterFunc that returns true if the supplied pod does not have any of the user-specified annotations for protection from eviction

type SuppliedCondition

type SuppliedCondition struct {
	Type            core.NodeConditionType
	Status          core.ConditionStatus
	MinimumDuration time.Duration
}

SuppliedCondition defines the condition will be watched.

func ParseConditions

func ParseConditions(conditions []string) []SuppliedCondition

ParseConditions can parse the string array of conditions to a list of SuppliedContion to support particular status value and duration.

Jump to

Keyboard shortcuts

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