kubernetesk8s.io/kubernetes/test/e2e/framework/autoscaling Index | Files

package autoscaling

import "k8s.io/kubernetes/test/e2e/framework/autoscaling"

Index

Variables

var (
	// KindDeployment is the GVK for Deployment
	KindDeployment = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}
	// KindReplicaSet is the GVK for ReplicaSet
	KindReplicaSet = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"}
	// KindCRD is the GVK for CRD for test purposes
	KindCRD = schema.GroupVersionKind{Group: crdGroup, Version: crdVersion, Kind: crdKind}
)

Functions

func CleanupExternalMetricsServer

func CleanupExternalMetricsServer(ctx context.Context, c clientset.Interface, ns, name string)

CleanupExternalMetricsServer removes the external metrics server resources

func CreateCPUHorizontalPodAutoscalerWithBehavior

func CreateCPUHorizontalPodAutoscalerWithBehavior(ctx context.Context, rc *ResourceConsumer, cpu int32, minReplicas int32, maxRepl int32, behavior *autoscalingv2.HorizontalPodAutoscalerBehavior) *autoscalingv2.HorizontalPodAutoscaler

func CreateCPUResourceHorizontalPodAutoscaler

func CreateCPUResourceHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, cpu, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler

func CreateContainerResourceHorizontalPodAutoscaler

func CreateContainerResourceHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, resourceType v1.ResourceName, metricTargetType autoscalingv2.MetricTargetType, metricTargetValue, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler

func CreateCustomResourceDefinition

func CreateCustomResourceDefinition(ctx context.Context, c crdclientset.Interface) *apiextensionsv1.CustomResourceDefinition

func CreateCustomSubresourceInstance

func CreateCustomSubresourceInstance(ctx context.Context, namespace, name string, client dynamic.ResourceInterface, definition *apiextensionsv1.CustomResourceDefinition) (*unstructured.Unstructured, error)

func CreateExternalHorizontalPodAutoscaler

func CreateExternalHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, metricName string, metricSelector map[string]string, targetType autoscalingv2.MetricTargetType, targetValue int64, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler

CreateExternalHorizontalPodAutoscaler creates an HPA with a single external metric

func CreateExternalHorizontalPodAutoscalerWithBehavior

func CreateExternalHorizontalPodAutoscalerWithBehavior(ctx context.Context, rc *ResourceConsumer, metricName string, metricSelector map[string]string, targetType autoscalingv2.MetricTargetType, targetValue int64, minReplicas, maxReplicas int32, behavior *autoscalingv2.HorizontalPodAutoscalerBehavior) *autoscalingv2.HorizontalPodAutoscaler

CreateExternalHorizontalPodAutoscalerWithBehavior creates an HPA with custom behavior

func CreateExternalMetricSpec

func CreateExternalMetricSpec(metricName string, metricSelector map[string]string, targetType autoscalingv2.MetricTargetType, targetValue int64) autoscalingv2.MetricSpec

CreateExternalMetricSpec creates a MetricSpec for external metrics

func CreateHorizontalPodAutoscaler

func CreateHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, targetRef autoscalingv2.CrossVersionObjectReference, namespace string, metrics []autoscalingv2.MetricSpec, resourceType v1.ResourceName, metricTargetType autoscalingv2.MetricTargetType, metricTargetValue, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler

func CreateMetricTargetWithType

func CreateMetricTargetWithType(resourceType v1.ResourceName, targetType autoscalingv2.MetricTargetType, targetValue int32) autoscalingv2.MetricTarget

func CreateMultiMetricHorizontalPodAutoscaler

func CreateMultiMetricHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, metrics []autoscalingv2.MetricSpec, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler

CreateMultiMetricHorizontalPodAutoscaler creates an HPA with multiple metrics

func CreateResourceHorizontalPodAutoscaler

func CreateResourceHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, resourceType v1.ResourceName, metricTargetType autoscalingv2.MetricTargetType, metricTargetValue, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler

func CreateResourceMetricSpec

func CreateResourceMetricSpec(resourceType v1.ResourceName, targetType autoscalingv2.MetricTargetType, targetValue int32) autoscalingv2.MetricSpec

CreateResourceMetricSpec creates a MetricSpec for resource metrics (CPU/Memory)

func DeleteContainerResourceHPA

func DeleteContainerResourceHPA(ctx context.Context, rc *ResourceConsumer, autoscalerName string)

DeleteContainerResourceHPA delete the horizontalPodAutoscaler for consuming resources.

func DeleteHPAWithBehavior

func DeleteHPAWithBehavior(ctx context.Context, rc *ResourceConsumer, autoscalerName string)

func DeleteHorizontalPodAutoscaler

func DeleteHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, autoscalerName string)

DeleteHorizontalPodAutoscaler delete the horizontalPodAutoscaler for consuming resources.

func HPABehaviorWithScaleDisabled

func HPABehaviorWithScaleDisabled(scalingDirection ScalingDirection) *autoscalingv2.HorizontalPodAutoscalerBehavior

func HPABehaviorWithScaleLimitedByNumberOfPods

func HPABehaviorWithScaleLimitedByNumberOfPods(scalingDirection ScalingDirection, numberOfPods, periodSeconds int32) *autoscalingv2.HorizontalPodAutoscalerBehavior

func HPABehaviorWithScaleLimitedByPercentage

func HPABehaviorWithScaleLimitedByPercentage(scalingDirection ScalingDirection, percentage, periodSeconds int32) *autoscalingv2.HorizontalPodAutoscalerBehavior

func HPABehaviorWithScaleUpAndDownRules

func HPABehaviorWithScaleUpAndDownRules(scaleUpRule, scaleDownRule *autoscalingv2.HPAScalingRules) *autoscalingv2.HorizontalPodAutoscalerBehavior

func HPABehaviorWithScalingRuleInDirection

func HPABehaviorWithScalingRuleInDirection(scalingDirection ScalingDirection, rule *autoscalingv2.HPAScalingRules) *autoscalingv2.HorizontalPodAutoscalerBehavior

func HPABehaviorWithStabilizationWindows

func HPABehaviorWithStabilizationWindows(upscaleStabilization, downscaleStabilization time.Duration) *autoscalingv2.HorizontalPodAutoscalerBehavior

func HPAScalingRuleWithPolicyDisabled

func HPAScalingRuleWithPolicyDisabled() *autoscalingv2.HPAScalingRules

func HPAScalingRuleWithScalingPolicy

func HPAScalingRuleWithScalingPolicy(policyType autoscalingv2.HPAScalingPolicyType, value, periodSeconds int32) *autoscalingv2.HPAScalingRules

func HPAScalingRuleWithStabilizationWindow

func HPAScalingRuleWithStabilizationWindow(stabilizationDuration int32) *autoscalingv2.HPAScalingRules

func HPAScalingRuleWithToleranceMilli

func HPAScalingRuleWithToleranceMilli(toleranceMilli int64) *autoscalingv2.HPAScalingRules

Types

type ExternalMetricsController

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

ExternalMetricsController provides methods to control the external metrics server at runtime

func NewExternalMetricsController

func NewExternalMetricsController(clientSet clientset.Interface, serviceName, namespace string) *ExternalMetricsController

NewExternalMetricsController creates a new controller for the external metrics server

func RunExternalMetricsServer

func RunExternalMetricsServer(ctx context.Context, c clientset.Interface, ns, name string, serviceAnnotations map[string]string) *ExternalMetricsController

RunExternalMetricsServer creates and returns an ExternalMetricsController for controlling the server

func (*ExternalMetricsController) CreateMetric

func (emc *ExternalMetricsController) CreateMetric(ctx context.Context, metricName string, value int64, labels map[string]string, shouldFail bool) error

CreateMetric creates a new metric on the external metrics server

func (*ExternalMetricsController) SetMetricFail

func (emc *ExternalMetricsController) SetMetricFail(ctx context.Context, metricName string, shouldFail bool, labels map[string]string) error

SetMetricFail configures whether a metric should return errors

func (*ExternalMetricsController) SetMetricValue

func (emc *ExternalMetricsController) SetMetricValue(ctx context.Context, metricName string, value int64, labels map[string]string) error

SetMetricValue updates the value of an existing metric

type ResourceConsumer

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

ResourceConsumer is a tool for testing. It helps to create a specified usage of CPU or memory. Typical use case: rc.ConsumeCPU(600) // ... check your assumption here rc.ConsumeCPU(300) // ... check your assumption here

func NewDynamicResourceConsumer

func NewDynamicResourceConsumer(ctx context.Context, name, nsName string, kind schema.GroupVersionKind, replicas, initCPUTotal, initMemoryTotal, initCustomMetric int, cpuLimit, memLimit int64, clientset clientset.Interface, scaleClient scaleclient.ScalesGetter, enableSidecar SidecarStatusType, sidecarType SidecarWorkloadType, podResources *v1.ResourceRequirements) *ResourceConsumer

NewDynamicResourceConsumer is a wrapper to create a new dynamic ResourceConsumer

func NewResourceConsumer

func NewResourceConsumer(ctx context.Context, name, nsName string, kind schema.GroupVersionKind, replicas int, customMetricName string, initCPUTotal, initMemoryTotal, initCustomMetric, consumptionTimeInSeconds, requestSizeInMillicores,
	requestSizeInMegabytes int, requestSizeCustomMetric int, cpuLimit, memLimit int64, clientset clientset.Interface, scaleClient scaleclient.ScalesGetter, podAnnotations, serviceAnnotations map[string]string, sidecarStatus SidecarStatusType, sidecarType SidecarWorkloadType, podResources *v1.ResourceRequirements) *ResourceConsumer

NewResourceConsumer creates new ResourceConsumer initCPUTotal argument is in millicores initMemoryTotal argument is in megabytes memLimit argument is in megabytes, memLimit is a maximum amount of memory that can be consumed by a single pod cpuLimit argument is in millicores, cpuLimit is a maximum amount of cpu that can be consumed by a single pod

func (*ResourceConsumer) CleanUp

func (rc *ResourceConsumer) CleanUp(ctx context.Context)

CleanUp clean up the background goroutines responsible for consuming resources.

func (*ResourceConsumer) ConsumeCPU

func (rc *ResourceConsumer) ConsumeCPU(millicores int)

ConsumeCPU consumes given number of CPU

func (*ResourceConsumer) ConsumeCPUPerPod

func (rc *ResourceConsumer) ConsumeCPUPerPod(millicoresTotal int)

ConsumeCPUPerPod sends CPU load directly to each consumer pod via the Kubernetes pod proxy API, bypassing kube-proxy's non-deterministic load balancing. millicoresTotal is divided evenly across all running pods, guaranteeing each pod receives an equal share regardless of cluster network config.

func (*ResourceConsumer) ConsumeCustomMetric

func (rc *ResourceConsumer) ConsumeCustomMetric(amount int)

ConsumeCustomMetric consumes given number of custom metric

func (*ResourceConsumer) ConsumeMem

func (rc *ResourceConsumer) ConsumeMem(megabytes int)

ConsumeMem consumes given number of Mem

func (*ResourceConsumer) EnsureDesiredReplicasInRange

func (rc *ResourceConsumer) EnsureDesiredReplicasInRange(ctx context.Context, minDesiredReplicas, maxDesiredReplicas int, duration time.Duration, hpaName string)

EnsureDesiredReplicasInRange ensure the replicas is in a desired range

func (*ResourceConsumer) GetHpa

GetHpa get the corresponding horizontalPodAutoscaler object

func (*ResourceConsumer) GetReplicas

func (rc *ResourceConsumer) GetReplicas(ctx context.Context) (int, error)

GetReplicas get the replicas

func (*ResourceConsumer) Pause

func (rc *ResourceConsumer) Pause()

Pause stops background goroutines responsible for consuming resources.

func (*ResourceConsumer) Resume

func (rc *ResourceConsumer) Resume(ctx context.Context)

Resume starts background goroutines responsible for consuming resources.

func (*ResourceConsumer) WaitForReplicas

func (rc *ResourceConsumer) WaitForReplicas(ctx context.Context, desiredReplicas int, duration time.Duration)

WaitForReplicas wait for the desired replicas

type ScalingDirection

type ScalingDirection int

ScalingDirection identifies the scale direction for HPA Behavior.

const (
	DirectionUnknown ScalingDirection = iota
	ScaleUpDirection
	ScaleDownDirection
)

type SidecarStatusType

type SidecarStatusType bool

SidecarStatusType type for sidecar status

const (
	Enable  SidecarStatusType = true
	Disable SidecarStatusType = false
)

type SidecarWorkloadType

type SidecarWorkloadType string

SidecarWorkloadType type of the sidecar

const (
	Busy SidecarWorkloadType = "Busy"
	Idle SidecarWorkloadType = "Idle"
)

Source Files

autoscaling_utils.go

Version
v1.36.0 (latest)
Published
Apr 22, 2026
Platform
linux/amd64
Imports
38 packages
Last checked
2 seconds ago

Tools for package owners.