podautoscaler

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 51 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package podautoscaler provides controllers for managing PodAutoscaler resources. The controller supports three scaling strategies: - HPA: Creates and manages Kubernetes HorizontalPodAutoscaler resources (KEDA-like wrapper) - KPA: Knative-style Pod Autoscaling with panic/stable windows - APA: Application-specific Pod Autoscaling with custom metrics

Architecture: - Stateless autoscaler management: AutoScalers are created on-demand for each reconciliation - HPA wrapper: For HPA strategy, we create and manage actual K8s HPA resources - Custom scaling: For KPA/APA, we directly compute and apply scaling decisions

Index

Constants

View Source
const (
	RayClusterFleet = "RayClusterFleet"
	StormService    = "StormService"
)
View Source
const (
	ConditionReady         = "Ready"
	ConditionValidSpec     = "ValidSpec"
	ConditionConflict      = "MultiPodAutoscalerConflict"
	ConditionScalingActive = "ScalingActive"
	ConditionAbleToScale   = "AbleToScale"

	ReasonAsExpected             = "AsExpected"
	ReasonReconcilingScaleDiff   = "ReconcilingScaleDiff"
	ReasonStable                 = "Stable"
	ReasonInvalidScalingStrategy = "InvalidScalingStrategy"
	ReasonInvalidBounds          = "InvalidBounds"
	ReasonMissingTargetRef       = "MissingScaleTargetRef"
	ReasonMetricsConfigError     = "MetricsConfigError"
	ReasonInvalidSpec            = "InvalidSpec"
	ReasonConfigured             = "Configured"
	ReasonPendingReplicas        = "PendingReplicas"
)
View Source
const AutoscalingStormServiceModeAnnotationKey = "autoscaling.aibrix.ai/storm-service-mode"

AutoscalingStormServiceModeAnnotationKey is the PodAutoscaler annotation that historically selected how role-level scaling applies to a StormService target: "replica" scales StormService.spec.replicas, anything else scales the targeted role's replicas.

Deprecated: declare StormService.spec.mode instead. The annotation is only honored as a compatibility fallback when the target StormService does not declare spec.mode, and may be removed once spec.mode is broadly adopted.

Variables

View Source
var (
	DefaultResyncInterval           = 10 * time.Second
	DefaultRequeueDuration          = 10 * time.Second
	DefaultReconcileTimeoutDuration = 10 * time.Second
)

Functions

func Add

func Add(mgr manager.Manager, runtimeConfig config.RuntimeConfig) error

Add creates a new PodAutoscaler Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller and Start it when the Manager is Started.

func GetReadyPodsCount added in v0.5.0

func GetReadyPodsCount(ctx context.Context, client client.Client, namespace string, selector labels.Selector) (int, error)

GetReadyPodsCount counts the number of ready pods matching the given selector

Types

type AutoScaler added in v0.5.0

type AutoScaler interface {
	// ComputeDesiredReplicas performs metric-based scaling calculation.
	// This is the primary method for scaling decisions and returns only the recommendation.
	// It does NOT perform any actual scaling operations.
	// All per-PA configuration is extracted from the PodAutoscaler spec on each call.
	ComputeDesiredReplicas(ctx context.Context, request ReplicaComputeRequest) (*ReplicaComputeResult, error)

	// ForgetPodAutoscaler releases the metric history kept for a PodAutoscaler
	// that no longer exists.
	ForgetPodAutoscaler(namespace, name string)
}

AutoScaler provides scaling decision capabilities based on metrics and algorithms. This interface focuses purely on scaling logic without actual resource manipulation. All implementations are stateless and thread-safe, supporting concurrent reconciliation.

type DefaultAutoScaler added in v0.5.0

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

DefaultAutoScaler implements the complete scaling pipeline All components are stateless or thread-safe, allowing concurrent reconciliation

func NewDefaultAutoScaler added in v0.5.0

func NewDefaultAutoScaler(
	factory metrics.MetricFetcherFactory,
	client client.Client,
) *DefaultAutoScaler

NewDefaultAutoScaler creates a new default autoscaler

func (*DefaultAutoScaler) ComputeDesiredReplicas added in v0.5.0

func (a *DefaultAutoScaler) ComputeDesiredReplicas(ctx context.Context, request ReplicaComputeRequest) (*ReplicaComputeResult, error)

ComputeDesiredReplicas computes desired replicas based on all metrics in MetricsSources. It returns the maximum recommended replicas across all valid metrics.

func (*DefaultAutoScaler) ForgetPodAutoscaler added in v0.8.0

func (a *DefaultAutoScaler) ForgetPodAutoscaler(namespace, name string)

ForgetPodAutoscaler drops the metric windows recorded for a deleted PodAutoscaler.

type PodAutoscalerReconciler

type PodAutoscalerReconciler struct {
	client.Client
	Scheme        *runtime.Scheme
	EventRecorder record.EventRecorder
	Mapper        apimeta.RESTMapper

	RuntimeConfig config.RuntimeConfig
	// contains filtered or unexported fields
}

PodAutoscalerReconciler reconciles a PodAutoscaler object. It uses stateless autoscaler management where AutoScalers are created on-demand for each reconciliation cycle, avoiding memory leaks and stale state issues.

func (*PodAutoscalerReconciler) Reconcile

func (r *PodAutoscalerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

func (*PodAutoscalerReconciler) Run

Run periodically enqueues all PodAutoscaler objects until ctx is cancelled. It is expected to be invoked by the controller-runtime manager via manager.RunnableFunc, so that ctx is tied to the manager lifecycle and the manager will wait for this function to return during shutdown.

type ReplicaComputeRequest added in v0.5.0

type ReplicaComputeRequest struct {
	PodAutoscaler   autoscalingv1alpha1.PodAutoscaler
	ScalingContext  scalingctx.ScalingContext // Single source of truth for PA-level configuration
	CurrentReplicas int32
	ReplicaState    ReplicaState
	Pods            []corev1.Pod
	Timestamp       time.Time
}

ReplicaComputeRequest represents a request for replica calculation. This type is used both for the public interface and internal pipeline processing.

type ReplicaComputeResult added in v0.5.0

type ReplicaComputeResult struct {
	DesiredReplicas           int32
	Algorithm                 string
	MetricName                string
	MetricSourceType          autoscalingv1alpha1.MetricSourceType
	MetricValue               float64
	Reason                    string
	Valid                     bool
	PendingReplicaGuardActive bool
}

ReplicaComputeResult represents the result of replica calculation

type ReplicaState added in v0.8.0

type ReplicaState struct {
	ReadyReplicas   int32
	PendingReplicas int32
}

ReplicaState captures scale target readiness state for pipeline-level guards.

type ScaleDecision added in v0.5.0

type ScaleDecision struct {
	DesiredReplicas           int32
	ShouldScale               bool
	Reason                    string
	Algorithm                 string
	PendingReplicaGuardActive bool
}

ScaleDecision represents a scaling decision made by the autoscaler

type ScalingTargetKey added in v0.5.0

type ScalingTargetKey struct {
	Namespace     string
	APIVersion    string
	Kind          string
	Name          string
	SubTargetRole string // from SubTargetSelector.RoleName
}

type ValidationResult added in v0.5.0

type ValidationResult struct {
	Valid   bool
	Reason  string
	Message string
}

type WorkloadScale added in v0.5.0

type WorkloadScale interface {
	// Validate checks if the target is valid and scalable
	Validate(ctx context.Context, pa *autoscalingv1alpha1.PodAutoscaler) error

	// GetCurrentReplicasFromScale extracts the current replica count from a scale object
	GetCurrentReplicasFromScale(ctx context.Context, pa *autoscalingv1alpha1.PodAutoscaler, scale *unstructured.Unstructured) (int32, error)

	// SetDesiredReplicas updates the replica count
	SetDesiredReplicas(ctx context.Context, pa *autoscalingv1alpha1.PodAutoscaler, replicas int32) error

	// GetPodSelectorFromScale extracts the label selector from an existing scale object
	// For role-level scaling, it adds the role label requirement
	// This avoids re-fetching the scale object when the controller already has it
	GetPodSelectorFromScale(ctx context.Context, pa *autoscalingv1alpha1.PodAutoscaler, scale *unstructured.Unstructured) (labels.Selector, error)
}

WorkloadScale provides scaling operations for different workload types. It provides the mechanism to get/set replica counts on workload resources, while AutoScaler provides the intelligence to compute desired replica counts. The interface is stateless - all methods take PodAutoscaler as a parameter.

func NewWorkloadScale added in v0.5.0

func NewWorkloadScale(
	client client.Client,
	restMapper meta.RESTMapper,
) WorkloadScale

NewWorkloadScale creates a stateless WorkloadScale implementation

Directories

Path Synopsis
Package algorithm provides scaling algorithms for different autoscaling strategies.
Package algorithm provides scaling algorithms for different autoscaling strategies.

Jump to

Keyboard shortcuts

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