core

package
v3.10.0-alpha.0+incomp... Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2018 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxKubernetesEmptyNodeDeletionTime is the maximum time needed by Kubernetes to delete an empty node.
	MaxKubernetesEmptyNodeDeletionTime = 3 * time.Minute
	// MaxCloudProviderNodeDeletionTime is the maximum time needed by cloud provider to delete a node.
	MaxCloudProviderNodeDeletionTime = 5 * time.Minute
	// MaxPodEvictionTime is the maximum time CA tries to evict a pod before giving up.
	MaxPodEvictionTime = 2 * time.Minute
	// EvictionRetryTime is the time after CA retries failed pod eviction.
	EvictionRetryTime = 10 * time.Second
	// PodEvictionHeadroom is the extra time we wait to catch situations when the pod is ignoring SIGTERM and
	// is killed with SIGKILL after MaxGracefulTerminationTime
	PodEvictionHeadroom = 30 * time.Second
	// UnremovableNodeRecheckTimeout is the timeout before we check again a node that couldn't be removed before
	UnremovableNodeRecheckTimeout = 5 * time.Minute
)
View Source
const (
	// Megabyte is 2^20 bytes.
	Megabyte float64 = 1024 * 1024
)

Getting node cores/memory

View Source
const (
	// ReschedulerTaintKey is the name of the taint created by rescheduler.
	ReschedulerTaintKey = "CriticalAddonsOnly"
)

Variables

This section is empty.

Functions

func ConfigurePredicateCheckerForLoop

func ConfigurePredicateCheckerForLoop(unschedulablePods []*apiv1.Pod, schedulablePods []*apiv1.Pod, predicateChecker *simulator.PredicateChecker)

ConfigurePredicateCheckerForLoop can be run to update predicateChecker configuration based on current state of the cluster.

func FilterOutExpendableAndSplit

func FilterOutExpendableAndSplit(unschedulableCandidates []*apiv1.Pod, expendablePodsPriorityCutoff int) ([]*apiv1.Pod, []*apiv1.Pod)

FilterOutExpendableAndSplit filters out expendable pods and splits into:

  • waiting for lower priority pods preemption
  • other pods.

func FilterOutExpendablePods

func FilterOutExpendablePods(pods []*apiv1.Pod, expendablePodsPriorityCutoff int) []*apiv1.Pod

FilterOutExpendablePods filters out expendable pods.

func FilterOutSchedulable

func FilterOutSchedulable(unschedulableCandidates []*apiv1.Pod, nodes []*apiv1.Node, allScheduled []*apiv1.Pod, podsWaitingForLowerPriorityPreemption []*apiv1.Pod,
	predicateChecker *simulator.PredicateChecker, expendablePodsPriorityCutoff int) []*apiv1.Pod

FilterOutSchedulable checks whether pods from <unschedulableCandidates> marked as unschedulable by Scheduler actually can't be scheduled on any node and filter out the ones that can. It takes into account pods that are bound to node and will be scheduled after lower priority pod preemption.

func GetNodeInfosForGroups

func GetNodeInfosForGroups(nodes []*apiv1.Node, cloudProvider cloudprovider.CloudProvider, kubeClient kube_client.Interface,
	daemonsets []*extensionsv1.DaemonSet, predicateChecker *simulator.PredicateChecker) (map[string]*schedulercache.NodeInfo, errors.AutoscalerError)

GetNodeInfosForGroups finds NodeInfos for all node groups used to manage the given nodes. It also returns a node group to sample node mapping. TODO(mwielgus): This returns map keyed by url, while most code (including scheduler) uses node.Name for a key.

TODO(mwielgus): Review error policy - sometimes we may continue with partial errors.

func ScaleUp

func ScaleUp(context *AutoscalingContext, unschedulablePods []*apiv1.Pod, nodes []*apiv1.Node,
	daemonSets []*extensionsv1.DaemonSet) (bool, errors.AutoscalerError)

ScaleUp tries to scale the cluster up. Return true if it found a way to increase the size, false if it didn't and error if an error occurred. Assumes that all nodes in the cluster are ready and in sync with instance groups.

func UpdateClusterStateMetrics

func UpdateClusterStateMetrics(csr *clusterstate.ClusterStateRegistry)

UpdateClusterStateMetrics updates metrics related to cluster state

func UpdateEmptyClusterStateMetrics

func UpdateEmptyClusterStateMetrics()

UpdateEmptyClusterStateMetrics updates metrics related to empty cluster's state. TODO(aleksandra-malinowska): use long unregistered value from ClusterStateRegistry.

Types

type Autoscaler

type Autoscaler interface {
	// RunOnce represents an iteration in the control-loop of CA
	RunOnce(currentTime time.Time) errors.AutoscalerError
	// CleanUp represents a clean-up required before the first invocation of RunOnce
	CleanUp()
	// CloudProvider returns the cloud provider associated to this autoscaler
	CloudProvider() cloudprovider.CloudProvider
	// ExitCleanUp is a clean-up performed just before process termination.
	ExitCleanUp()
}

Autoscaler is the main component of CA which scales up/down node groups according to its configuration The configuration can be injected at the creation of an autoscaler

func NewAutoscaler

func NewAutoscaler(opts AutoscalerOptions, predicateChecker *simulator.PredicateChecker, kubeClient kube_client.Interface,
	kubeEventRecorder kube_record.EventRecorder, listerRegistry kube_util.ListerRegistry) (Autoscaler, errors.AutoscalerError)

NewAutoscaler creates an autoscaler of an appropriate type according to the parameters

type AutoscalerBuilder

type AutoscalerBuilder interface {
	SetDynamicConfig(config dynamic.Config) AutoscalerBuilder
	Build() (Autoscaler, errors.AutoscalerError)
}

AutoscalerBuilder builds an instance of Autoscaler which is the core of CA

type AutoscalerBuilderImpl

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

AutoscalerBuilderImpl builds new autoscalers from its state including initial `AutoscalingOptions` given at startup and `dynamic.Config` read on demand from the configmap

func NewAutoscalerBuilder

func NewAutoscalerBuilder(autoscalingOptions AutoscalingOptions, predicateChecker *simulator.PredicateChecker,
	kubeClient kube_client.Interface, kubeEventRecorder kube_record.EventRecorder, listerRegistry kube_util.ListerRegistry) *AutoscalerBuilderImpl

NewAutoscalerBuilder builds an AutoscalerBuilder from required parameters

func (*AutoscalerBuilderImpl) Build

Build an autoscaler according to the builder's state

func (*AutoscalerBuilderImpl) SetDynamicConfig

func (b *AutoscalerBuilderImpl) SetDynamicConfig(config dynamic.Config) AutoscalerBuilder

SetDynamicConfig sets an instance of dynamic.Config read from a configmap so that the new autoscaler built afterwards reflect the latest configuration contained in the configmap

type AutoscalerOptions

type AutoscalerOptions struct {
	AutoscalingOptions
	dynamic.ConfigFetcherOptions
}

AutoscalerOptions is the whole set of options for configuring an autoscaler

type AutoscalingContext

type AutoscalingContext struct {
	// Options to customize how autoscaling works
	AutoscalingOptions
	// CloudProvider used in CA.
	CloudProvider cloudprovider.CloudProvider
	// ClientSet interface.
	ClientSet kube_client.Interface
	// ClusterState for maintaining the state of cluster nodes.
	ClusterStateRegistry *clusterstate.ClusterStateRegistry
	// Recorder for recording events.
	Recorder kube_record.EventRecorder
	// PredicateChecker to check if a pod can fit into a node.
	PredicateChecker *simulator.PredicateChecker
	// ExpanderStrategy is the strategy used to choose which node group to expand when scaling up
	ExpanderStrategy expander.Strategy
	// LogRecorder can be used to collect log messages to expose via Events on some central object.
	LogRecorder *utils.LogEventRecorder
}

AutoscalingContext contains user-configurable constant and configuration-related objects passed to scale up/scale down functions.

func NewAutoscalingContext

func NewAutoscalingContext(options AutoscalingOptions, predicateChecker *simulator.PredicateChecker,
	kubeClient kube_client.Interface, kubeEventRecorder kube_record.EventRecorder,
	logEventRecorder *utils.LogEventRecorder, listerRegistry kube_util.ListerRegistry) (*AutoscalingContext, errors.AutoscalerError)

NewAutoscalingContext returns an autoscaling context from all the necessary parameters passed via arguments

type AutoscalingOptions

type AutoscalingOptions struct {
	// MaxEmptyBulkDelete is a number of empty nodes that can be removed at the same time.
	MaxEmptyBulkDelete int
	// ScaleDownUtilizationThreshold sets threshold for nodes to be considered for scale down.
	// Well-utilized nodes are not touched.
	ScaleDownUtilizationThreshold float64
	// ScaleDownUnneededTime sets the duration CA expects a node to be unneeded/eligible for removal
	// before scaling down the node.
	ScaleDownUnneededTime time.Duration
	// ScaleDownUnreadyTime represents how long an unready node should be unneeded before it is eligible for scale down
	ScaleDownUnreadyTime time.Duration
	// MaxNodesTotal sets the maximum number of nodes in the whole cluster
	MaxNodesTotal int
	// MaxCoresTotal sets the maximum number of cores in the whole cluster
	MaxCoresTotal int64
	// MinCoresTotal sets the minimum number of cores in the whole cluster
	MinCoresTotal int64
	// MaxMemoryTotal sets the maximum memory (in megabytes) in the whole cluster
	MaxMemoryTotal int64
	// MinMemoryTotal sets the maximum memory (in megabytes) in the whole cluster
	MinMemoryTotal int64
	// NodeGroupAutoDiscovery represents one or more definition(s) of node group auto-discovery
	NodeGroupAutoDiscovery []string
	// EstimatorName is the estimator used to estimate the number of needed nodes in scale up.
	EstimatorName string
	// ExpanderName sets the type of node group expander to be used in scale up
	ExpanderName string
	// MaxGracefulTerminationSec is maximum number of seconds scale down waits for pods to terminate before
	// removing the node from cloud provider.
	MaxGracefulTerminationSec int
	//  Maximum time CA waits for node to be provisioned
	MaxNodeProvisionTime time.Duration
	// MaxTotalUnreadyPercentage is the maximum percentage of unready nodes after which CA halts operations
	MaxTotalUnreadyPercentage float64
	// OkTotalUnreadyCount is the number of allowed unready nodes, irrespective of max-total-unready-percentage
	OkTotalUnreadyCount int
	// CloudConfig is the path to the cloud provider configuration file. Empty string for no configuration file.
	CloudConfig string
	// CloudProviderName sets the type of the cloud provider CA is about to run in. Allowed values: gce, aws
	CloudProviderName string
	// NodeGroups is the list of node groups a.k.a autoscaling targets
	NodeGroups []string
	// ScaleDownEnabled is used to allow CA to scale down the cluster
	ScaleDownEnabled bool
	// ScaleDownDelayAfterAdd sets the duration from the last scale up to the time when CA starts to check scale down options
	ScaleDownDelayAfterAdd time.Duration
	// ScaleDownDelayAfterDelete sets the duration between scale down attempts if scale down removes one or more nodes
	ScaleDownDelayAfterDelete time.Duration
	// ScaleDownDelayAfterFailure sets the duration before the next scale down attempt if scale down results in an error
	ScaleDownDelayAfterFailure time.Duration
	// ScaleDownNonEmptyCandidatesCount is the maximum number of non empty nodes
	// considered at once as candidates for scale down.
	ScaleDownNonEmptyCandidatesCount int
	// ScaleDownCandidatesPoolRatio is a ratio of nodes that are considered
	// as additional non empty candidates for scale down when some candidates from
	// previous iteration are no longer valid.
	ScaleDownCandidatesPoolRatio float64
	// ScaleDownCandidatesPoolMinCount is the minimum number of nodes that are
	// considered as additional non empty candidates for scale down when some
	// candidates from previous iteration are no longer valid.
	// The formula to calculate additional candidates number is following:
	// max(#nodes * ScaleDownCandidatesPoolRatio, ScaleDownCandidatesPoolMinCount)
	ScaleDownCandidatesPoolMinCount int
	// WriteStatusConfigMap tells if the status information should be written to a ConfigMap
	WriteStatusConfigMap bool
	// BalanceSimilarNodeGroups enables logic that identifies node groups with similar machines and tries to balance node count between them.
	BalanceSimilarNodeGroups bool
	// ConfigNamespace is the namespace cluster-autoscaler is running in and all related configmaps live in
	ConfigNamespace string
	// ClusterName if available
	ClusterName string
	// NodeAutoprovisioningEnabled tells whether the node auto-provisioning is enabled for this cluster.
	NodeAutoprovisioningEnabled bool
	// MaxAutoprovisionedNodeGroupCount is the maximum number of autoprovisioned groups in the cluster.
	MaxAutoprovisionedNodeGroupCount int
	// Pods with priority below cutoff are expendable. They can be killed without any consideration during scale down and they don't cause scale-up.
	// Pods with null priority (PodPriority disabled) are non-expendable.
	ExpendablePodsPriorityCutoff int
	// Regional tells whether the cluster is regional.
	Regional bool
}

AutoscalingOptions contain various options to customize how autoscaling works

type DynamicAutoscaler

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

DynamicAutoscaler is a variant of autoscaler which supports dynamic reconfiguration at runtime

func NewDynamicAutoscaler

func NewDynamicAutoscaler(autoscalerBuilder AutoscalerBuilder, configFetcher dynamic.ConfigFetcher) (*DynamicAutoscaler, errors.AutoscalerError)

NewDynamicAutoscaler builds a DynamicAutoscaler from required parameters

func (*DynamicAutoscaler) CleanUp

func (a *DynamicAutoscaler) CleanUp()

CleanUp does the work required before all the iterations of a dynamic autoscaler run

func (*DynamicAutoscaler) CloudProvider

func (a *DynamicAutoscaler) CloudProvider() cloudprovider.CloudProvider

CloudProvider returns the cloud provider associated to this autoscaler

func (*DynamicAutoscaler) ExitCleanUp

func (a *DynamicAutoscaler) ExitCleanUp()

ExitCleanUp cleans-up after autoscaler, so no mess remains after process termination.

func (*DynamicAutoscaler) Reconfigure

func (a *DynamicAutoscaler) Reconfigure() error

Reconfigure this dynamic autoscaler if the configmap is updated

func (*DynamicAutoscaler) RunOnce

func (a *DynamicAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError

RunOnce represents a single iteration of a dynamic autoscaler inside the CA's control-loop

type NodeDeleteStatus

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

NodeDeleteStatus tells whether a node is being deleted right now.

func (*NodeDeleteStatus) IsDeleteInProgress

func (n *NodeDeleteStatus) IsDeleteInProgress() bool

IsDeleteInProgress returns true if a node is being deleted.

func (*NodeDeleteStatus) SetDeleteInProgress

func (n *NodeDeleteStatus) SetDeleteInProgress(status bool)

SetDeleteInProgress sets deletion process status

type ScaleDown

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

ScaleDown is responsible for maintaining the state needed to perform unneeded node removals.

func NewScaleDown

func NewScaleDown(context *AutoscalingContext) *ScaleDown

NewScaleDown builds new ScaleDown object.

func (*ScaleDown) CleanUp

func (sd *ScaleDown) CleanUp(timestamp time.Time)

CleanUp cleans up the internal ScaleDown state.

func (*ScaleDown) CleanUpUnneededNodes

func (sd *ScaleDown) CleanUpUnneededNodes()

CleanUpUnneededNodes clears the list of unneeded nodes.

func (*ScaleDown) GetCandidatesForScaleDown

func (sd *ScaleDown) GetCandidatesForScaleDown() []*apiv1.Node

GetCandidatesForScaleDown gets candidates for scale down.

func (*ScaleDown) TryToScaleDown

func (sd *ScaleDown) TryToScaleDown(allNodes []*apiv1.Node, pods []*apiv1.Pod, pdbs []*policyv1.PodDisruptionBudget, currentTime time.Time) (ScaleDownResult, errors.AutoscalerError)

TryToScaleDown tries to scale down the cluster. It returns ScaleDownResult indicating if any node was removed and error if such occurred.

func (*ScaleDown) UpdateUnneededNodes

func (sd *ScaleDown) UpdateUnneededNodes(
	nodes []*apiv1.Node,
	nodesToCheck []*apiv1.Node,
	pods []*apiv1.Pod,
	timestamp time.Time,
	pdbs []*policyv1.PodDisruptionBudget) errors.AutoscalerError

UpdateUnneededNodes calculates which nodes are not needed, i.e. all pods can be scheduled somewhere else, and updates unneededNodes map accordingly. It also computes information where pods can be rescheduled and node utilization level. Timestamp is the current timestamp. The computations are made only for the nodes managed by CA.

type ScaleDownResult

type ScaleDownResult int

ScaleDownResult represents the state of scale down.

const (
	// ScaleDownError - scale down finished with error.
	ScaleDownError ScaleDownResult = iota
	// ScaleDownNoUnneeded - no unneeded nodes and no errors.
	ScaleDownNoUnneeded ScaleDownResult = iota
	// ScaleDownNoNodeDeleted - unneeded nodes present but not available for deletion.
	ScaleDownNoNodeDeleted ScaleDownResult = iota
	// ScaleDownNodeDeleted - a node was deleted.
	ScaleDownNodeDeleted ScaleDownResult = iota
	// ScaleDownNodeDeleteStarted - a node deletion process was started.
	ScaleDownNodeDeleteStarted ScaleDownResult = iota
	// ScaleDownDisabledKey is the name of annotation marking node as not eligible for scale down.
	ScaleDownDisabledKey = "cluster-autoscaler.kubernetes.io/scale-down-disabled"
)

type StaticAutoscaler

type StaticAutoscaler struct {
	// AutoscalingContext consists of validated settings and options for this autoscaler
	*AutoscalingContext
	kube_util.ListerRegistry
	// contains filtered or unexported fields
}

StaticAutoscaler is an autoscaler which has all the core functionality of a CA but without the reconfiguration feature

func NewStaticAutoscaler

func NewStaticAutoscaler(opts AutoscalingOptions, predicateChecker *simulator.PredicateChecker,
	kubeClient kube_client.Interface, kubeEventRecorder kube_record.EventRecorder, listerRegistry kube_util.ListerRegistry) (*StaticAutoscaler, errors.AutoscalerError)

NewStaticAutoscaler creates an instance of Autoscaler filled with provided parameters

func (*StaticAutoscaler) CleanUp

func (a *StaticAutoscaler) CleanUp()

CleanUp cleans up ToBeDeleted taints added by the previously run and then failed CA

func (*StaticAutoscaler) CloudProvider

func (a *StaticAutoscaler) CloudProvider() cloudprovider.CloudProvider

CloudProvider returns the cloud provider associated to this autoscaler

func (*StaticAutoscaler) ExitCleanUp

func (a *StaticAutoscaler) ExitCleanUp()

ExitCleanUp removes status configmap.

func (*StaticAutoscaler) RunOnce

func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError

RunOnce iterates over node groups and scales them up/down if necessary

Jump to

Keyboard shortcuts

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