Package kta_python_sdk.algorithm
algorithm package.
Provides ready-to-use autoscaling algorithms.
ALGORITHMS = (KTADummyAutoscaler, KTADummyAutoscalerMonitor, KTADummyAutoscalerAnalyzePlan)
module-attribute
dummy
KTA Dummy Autoscaler (KTADummyAutoscaler).
The KTADummyAutoscaler is an autoscaler for demonstration and testing purposes. It is deliberately kept simple to
showcase the functionality of KTA.
It toggles between 2 states (off/on encoded as 0/1) where each state corresponds to a configurable number of replicas. The state is changed based on the toggle threshold n, which corresponds to the number of MAPE-K loop iterations incl. the one that is in progress.
Algorithm details:
- The monitor UDF tracks the number of MAPE-K loop iterations.
- The analyze UDF determines the state (0/1).
- The plan UDF determines the number of replicas based on the toggle state of the analyze UDF result.
Note that the wall clock time between state changes depends on the toggle threshold n AND the reconciliation time interval of the Kubernetes Operator that is configured in the KTAPolicy. For example, a toggle threshold of 5 and a reconciliation interval of 5s will toggle the state approximately every 5 * 5s = 25s.
To demonstrate how the Python SDK can be used, we provide the KTADummyAutoscaler in 2 different versions:
- Combined version where all UDFs are implemented in a single class.
- Separate classes for (1) the monitor (2) the analyze and plan UDF.
KTADummyAutoscaler
Bases: AutoscalingAlgorithmUDFs[_KTADummyAutoscalerMonitorResult, _KTADummyAutoscalerAnalyzeResult, Dict[TopologyNode, PlanUdfResult]]
Implements all UDFs.
num_replicas_by_state = num_replicas_by_state
instance-attribute
toggle_threshold = toggle_threshold
instance-attribute
__init__(toggle_threshold, num_replicas_by_state, *args, **kwargs)
Initializes the autoscaler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
toggle_threshold
|
int
|
Toggle threshold. |
required |
num_replicas_by_state
|
Union[List[int], tuple[int, ...]]
|
Number of replicas for each state. Must be of length 2. |
required |
*args
|
Any
|
Params for super types. |
()
|
**kwargs
|
Any
|
Params for super types. |
{}
|
analyze(ctx)
monitor(ctx)
plan(ctx)
KTADummyAutoscalerAnalyzePlan
Bases: AutoscalingAlgorithmAnalyzeUDF[_KTADummyAutoscalerMonitorResult, _KTADummyAutoscalerAnalyzeResult, Dict[TopologyNode, PlanUdfResult]], AutoscalingAlgorithmPlanUDF[_KTADummyAutoscalerMonitorResult, _KTADummyAutoscalerAnalyzeResult, Dict[TopologyNode, PlanUdfResult]]
Only implements the analyze and plan UDF.
num_replicas_by_state = num_replicas_by_state
instance-attribute
toggle_threshold = toggle_threshold
instance-attribute
__init__(toggle_threshold, num_replicas_by_state, *args, **kwargs)
Initializes the autoscaler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
toggle_threshold
|
int
|
Toggle threshold. |
required |
num_replicas_by_state
|
Union[List[int], Tuple[int]]
|
Number of replicas for each state. Must be of length 2. |
required |
*args
|
Any
|
Params for super types. |
()
|
**kwargs
|
Any
|
Params for super types. |
{}
|
analyze(ctx)
plan(ctx)
KTADummyAutoscalerMonitor
Bases: AutoscalingAlgorithmMonitorUDF[_KTADummyAutoscalerMonitorResult, _KTADummyAutoscalerAnalyzeResult, Dict[TopologyNode, PlanUdfResult]]
Only implements the monitor UDF.