Documentation ¶
Index ¶
- Constants
- Variables
- func BuildConfigFromFlags(apiserver, kubecfg string) (*rest.Config, error)
- func ConvertLabelsToFilterExpr(labelsSlice []string) (*string, error)
- func HasDrainRetryAnnotation(n *core.Node) bool
- func IsAlreadyScheduledError(err error) bool
- func IsMarkedForDrain(n *core.Node) bool
- func IsTimeout(err error) bool
- func LocalStoragePodFilter(p core.Pod) (bool, error)
- func MirrorPodFilter(p core.Pod) (bool, error)
- func NewAlreadyScheduledError() error
- func NewEventRecorder(c kubernetes.Interface) record.EventRecorder
- func NewNodeLabelFilter(expressionStr *string, log *zap.Logger) (func(o interface{}) bool, error)
- func RetryWithTimeout(f func() error, retryPeriod, timeout time.Duration) error
- func UnreplicatedPodFilter(p core.Pod) (bool, error)
- type APICordonDrainer
- func (d *APICordonDrainer) Cordon(n *core.Node, mutators ...nodeMutatorFn) error
- func (d *APICordonDrainer) Drain(n *core.Node) error
- func (d *APICordonDrainer) MarkDrain(n *core.Node, when, finish time.Time, failed bool) error
- func (d *APICordonDrainer) Uncordon(n *core.Node, mutators ...nodeMutatorFn) error
- type APICordonDrainerOption
- func EvictionHeadroom(h time.Duration) APICordonDrainerOption
- func MaxGracePeriod(m time.Duration) APICordonDrainerOption
- func WithAPICordonDrainerLogger(l *zap.Logger) APICordonDrainerOption
- func WithPodFilter(f PodFilterFunc) APICordonDrainerOption
- func WithSkipDrain(b bool) APICordonDrainerOption
- type AlreadyScheduledError
- type CordonDrainer
- type Cordoner
- type DrainScheduler
- type DrainSchedules
- type Drainer
- type DrainingResourceEventHandler
- type DrainingResourceEventHandlerOption
- type NodeProcessed
- type NodeStore
- type NodeWatch
- type NoopCordonDrainer
- func (d *NoopCordonDrainer) Cordon(n *core.Node, mutators ...nodeMutatorFn) error
- func (d *NoopCordonDrainer) Drain(n *core.Node) error
- func (d *NoopCordonDrainer) MarkDrain(n *core.Node, when, finish time.Time, failed bool) error
- func (d *NoopCordonDrainer) Uncordon(n *core.Node, mutators ...nodeMutatorFn) error
- type PodFilterFunc
- type SuppliedCondition
Constants ¶
const ( SetConditionTimeout = 10 * time.Second SetConditionRetryPeriod = 50 * time.Millisecond )
const ( DefaultMaxGracePeriod time.Duration = 8 * time.Minute DefaultEvictionOverhead time.Duration = 30 * time.Second ConditionDrainedScheduled = "DrainScheduled" DefaultSkipDrain = false )
Default pod eviction settings.
const Component = "draino"
Component is the name of this application.
const ( // DefaultDrainBuffer is the default minimum time between node drains. DefaultDrainBuffer = 10 * time.Minute )
Variables ¶
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 ¶
BuildConfigFromFlags is clientcmd.BuildConfigFromFlags with no annoying dependencies on glog. https://godoc.org/k8s.io/client-go/tools/clientcmd#BuildConfigFromFlags
func ConvertLabelsToFilterExpr ¶
ConvertLabelsToFilterExpr Convert old list labels into new expression syntax
func HasDrainRetryAnnotation ¶
func IsAlreadyScheduledError ¶
func IsMarkedForDrain ¶
func LocalStoragePodFilter ¶
LocalStoragePodFilter returns true if the supplied pod does not have local storage, i.e. does not use any 'empty dir' volumes.
func MirrorPodFilter ¶
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 ¶
NewNodeLabelFilter returns a filter that returns true if the supplied node satisfies the boolean expression
func RetryWithTimeout ¶
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.
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 ¶
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 ¶
func (*DrainSchedules) DeleteSchedule ¶
func (d *DrainSchedules) DeleteSchedule(name string)
func (*DrainSchedules) HasSchedule ¶
func (d *DrainSchedules) HasSchedule(name string) (has, failed bool)
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 ¶
func NewDrainingResourceEventHandler(d CordonDrainer, e record.EventRecorder, ho ...DrainingResourceEventHandlerOption) *DrainingResourceEventHandler
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 ¶
func WithDrainBuffer(d time.Duration) DrainingResourceEventHandlerOption
WithDrainBuffer configures the minimum time between scheduled drains.
func WithLogger ¶
func WithLogger(l *zap.Logger) DrainingResourceEventHandlerOption
WithLogger configures a DrainingResourceEventHandler to use the supplied logger.
type NodeProcessed ¶
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 {
}An NodeWatch is a cache of node resources that notifies registered handlers when its contents change.
func NewNodeWatch ¶
func NewNodeWatch(c kubernetes.Interface, rs ...cache.ResourceEventHandler) *NodeWatch
NewNodeWatch creates a watch on node resources. Nodes are cached and the provided ResourceEventHandlers are called when the cache changes.
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.
type PodFilterFunc ¶
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.