var ( // KindRC is the GVK for ReplicationController KindRC = schema.GroupVersionKind{Version: "v1", Kind: "ReplicationController"} // KindDeployment is the GVK for Deployment KindDeployment = schema.GroupVersionKind{Group: "apps", Version: "v1beta2", Kind: "Deployment"} // KindReplicaSet is the GVK for ReplicaSet KindReplicaSet = schema.GroupVersionKind{Group: "apps", Version: "v1beta2", Kind: "ReplicaSet"} // KindCRD is the GVK for CRD for test purposes KindCRD = schema.GroupVersionKind{Group: crdGroup, Version: crdVersion, Kind: crdKind} )
func CreateCPUHorizontalPodAutoscalerWithBehavior(ctx context.Context, rc *ResourceConsumer, cpu int32, minReplicas int32, maxRepl int32, behavior *autoscalingv2.HorizontalPodAutoscalerBehavior) *autoscalingv2.HorizontalPodAutoscaler
func CreateCPUResourceHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, cpu, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler
func CreateContainerResourceHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, resourceType v1.ResourceName, metricTargetType autoscalingv2.MetricTargetType, metricTargetValue, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler
func CreateCustomResourceDefinition(ctx context.Context, c crdclientset.Interface) *apiextensionsv1.CustomResourceDefinition
func CreateCustomSubresourceInstance(ctx context.Context, namespace, name string, client dynamic.ResourceInterface, definition *apiextensionsv1.CustomResourceDefinition) (*unstructured.Unstructured, error)
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(resourceType v1.ResourceName, targetType autoscalingv2.MetricTargetType, targetValue int32) autoscalingv2.MetricTarget
func CreateResourceHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, resourceType v1.ResourceName, metricTargetType autoscalingv2.MetricTargetType, metricTargetValue, minReplicas, maxReplicas int32) *autoscalingv2.HorizontalPodAutoscaler
func DeleteContainerResourceHPA(ctx context.Context, rc *ResourceConsumer, autoscalerName string)
DeleteContainerResourceHPA delete the horizontalPodAutoscaler for consuming resources.
func DeleteHPAWithBehavior(ctx context.Context, rc *ResourceConsumer, autoscalerName string)
func DeleteHorizontalPodAutoscaler(ctx context.Context, rc *ResourceConsumer, autoscalerName string)
DeleteHorizontalPodAutoscaler delete the horizontalPodAutoscaler for consuming resources.
func HPABehaviorWithScaleDisabled(scalingDirection ScalingDirection) *autoscalingv2.HorizontalPodAutoscalerBehavior
func HPABehaviorWithScaleLimitedByNumberOfPods(scalingDirection ScalingDirection, numberOfPods, periodSeconds int32) *autoscalingv2.HorizontalPodAutoscalerBehavior
func HPABehaviorWithScaleLimitedByPercentage(scalingDirection ScalingDirection, percentage, periodSeconds int32) *autoscalingv2.HorizontalPodAutoscalerBehavior
func HPABehaviorWithScaleUpAndDownRules(scaleUpRule, scaleDownRule *autoscalingv2.HPAScalingRules) *autoscalingv2.HorizontalPodAutoscalerBehavior
func HPABehaviorWithScalingRuleInDirection(scalingDirection ScalingDirection, rule *autoscalingv2.HPAScalingRules) *autoscalingv2.HorizontalPodAutoscalerBehavior
func HPABehaviorWithStabilizationWindows(upscaleStabilization, downscaleStabilization time.Duration) *autoscalingv2.HorizontalPodAutoscalerBehavior
func HPAScalingRuleWithPolicyDisabled() *autoscalingv2.HPAScalingRules
func HPAScalingRuleWithScalingPolicy(policyType autoscalingv2.HPAScalingPolicyType, value, periodSeconds int32) *autoscalingv2.HPAScalingRules
func HPAScalingRuleWithStabilizationWindow(stabilizationDuration int32) *autoscalingv2.HPAScalingRules
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
type ResourceConsumer struct {
// contains filtered or unexported fields
}
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) *ResourceConsumer
NewDynamicResourceConsumer is a wrapper to create a new dynamic ResourceConsumer
func (rc *ResourceConsumer) CleanUp(ctx context.Context)
CleanUp clean up the background goroutines responsible for consuming resources.
func (rc *ResourceConsumer) ConsumeCPU(millicores int)
ConsumeCPU consumes given number of CPU
func (rc *ResourceConsumer) ConsumeCustomMetric(amount int)
ConsumeCustomMetric consumes given number of custom metric
func (rc *ResourceConsumer) ConsumeMem(megabytes int)
ConsumeMem consumes given number of Mem
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 (rc *ResourceConsumer) GetHpa(ctx context.Context, name string) (*autoscalingv1.HorizontalPodAutoscaler, error)
GetHpa get the corresponding horizontalPodAutoscaler object
func (rc *ResourceConsumer) GetReplicas(ctx context.Context) (int, error)
GetReplicas get the replicas
func (rc *ResourceConsumer) Pause()
Pause stops background goroutines responsible for consuming resources.
func (rc *ResourceConsumer) Resume(ctx context.Context)
Resume starts background goroutines responsible for consuming resources.
func (rc *ResourceConsumer) WaitForReplicas(ctx context.Context, desiredReplicas int, duration time.Duration)
WaitForReplicas wait for the desired replicas
ScalingDirection identifies the scale direction for HPA Behavior.
type ScalingDirection int
const ( DirectionUnknown ScalingDirection = iota ScaleUpDirection ScaleDownDirection )
SidecarStatusType type for sidecar status
type SidecarStatusType bool
const ( Enable SidecarStatusType = true Disable SidecarStatusType = false )
SidecarWorkloadType type of the sidecar
type SidecarWorkloadType string
const ( Busy SidecarWorkloadType = "Busy" Idle SidecarWorkloadType = "Idle" )