core

package
v0.0.0-...-e6acfc1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: Apache-2.0 Imports: 33 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 = 20 * time.Second
)

Variables

This section is empty.

Functions

func FilterOutSchedulable

func FilterOutSchedulable(unschedulableCandidates []*apiv1.Pod, nodes []*apiv1.Node, allPods []*apiv1.Pod, predicateChecker *simulator.PredicateChecker) []*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.

func GetAllNodesAvailableTime

func GetAllNodesAvailableTime(nodes []*apiv1.Node) time.Time

GetAllNodesAvailableTime returns time when the newest node became available for scheduler. TODO: This function should use LastTransitionTime from NodeReady condition.

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 ResetPodScheduledCondition

func ResetPodScheduledCondition(kubeClient kube_client.Interface, pods []*apiv1.Pod)

ResetPodScheduledCondition resets pod condition PodScheduled to "unknown" for all the pods with LastTransitionTime not after the threshold time.

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 occured. Assumes that all nodes in the cluster are ready and in sync with instance groups.

func SlicePodsByPodScheduledTime

func SlicePodsByPodScheduledTime(pods []*apiv1.Pod, threshold time.Time) (oldPods []*apiv1.Pod, newPods []*apiv1.Pod)

SlicePodsByPodScheduledTime slices given pod array into those where PodScheduled condition have been updated after the thresold and others. Each pod must be in condition "Scheduled: False; Reason: Unschedulable"

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()
	// 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
	// CloudProviderBuilder is used to new CloudProvider
	CloudProviderBuilder builder.CloudProviderBuilder
	// ClientSet interface.
	ClientSet kube_client.Interface
	// ClusterState for maintaining the state of custer 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 threshould for nodes to be considered for scale down.
	// Well-utilized nodes are not touched.
	ScaleDownUtilizationThreshold float64
	// ScaleDownUnneededTime sets the duriation CA exepects a node to be unneded/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
	// NodeGroupAutoDiscovery represents one or more definition(s) of node group auto-discovery
	NodeGroupAutoDiscovery string
	// UnregisteredNodeRemovalTime represents how long CA waits before removing nodes that are not registered in Kubernetes")
	UnregisteredNodeRemovalTime time.Duration
	// 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 terminante 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
	// VerifyUnschedulable is used to enable verification to ensure that each pod marked by Scheduler as unschedulable actually can't be scheduled on any node.
	// This prevents from adding unnecessary nodes in situation when CA and Scheduler have different configuration.
	VerifyUnschedulablePods bool
	// ScaleDownEnabled is used to allow CA to scale down the cluster
	ScaleDownEnabled bool
	// ScaleDownDelay sets the duration from the last scale up to the time when CA starts to check scale down options
	ScaleDownDelay time.Duration
	// ScaleDownTrialInterval sets how often scale down possibility is check
	ScaleDownTrialInterval time.Duration
	// 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 namesapce cluster-autoscaler is running in and all related configmaps live in
	ConfigNamespace string
}

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) 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 PollingAutoscaler

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

PollingAutoscaler is a variant of autoscaler which polls the source-of-truth every time RunOnce is invoked

func NewPollingAutoscaler

func NewPollingAutoscaler(autoscalerBuilder AutoscalerBuilder) (*PollingAutoscaler, errors.AutoscalerError)

NewPollingAutoscaler builds a PollingAutoscaler from required parameters

func (*PollingAutoscaler) CleanUp

func (a *PollingAutoscaler) CleanUp()

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

func (*PollingAutoscaler) ExitCleanUp

func (a *PollingAutoscaler) ExitCleanUp()

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

func (*PollingAutoscaler) Poll

func (a *PollingAutoscaler) Poll() error

Poll latest data from cloud provider to recreate this autoscaler

func (*PollingAutoscaler) RunOnce

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

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

type ScaleDown

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

ScaleDown is responsible for maintaining the state needed to perform unneded 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(nodes []*apiv1.Node, pods []*apiv1.Pod, pdbs []*policyv1.PodDisruptionBudget) (ScaleDownResult, errors.AutoscalerError)

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

func (*ScaleDown) UpdateUnneededNodes

func (sd *ScaleDown) UpdateUnneededNodes(
	nodes []*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.

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
)

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) 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