in cost-optimization/hpa-config-recommender/src/hpaconfigrecommender/run_workload_simulation.py [0:0]
def _is_plan_valid(
config: Config, plan: WorkloadPlan
) -> Tuple[bool, Optional[str]]:
'''
Validate an recommendations workload plan based on defined criteria.
Args:
plan (WorkloadPlan): The recommendations workload plan to validate.
config (Config): Run configurations
Returns:
bool: Returns True if the recommendations plan is valid, otherwise False.
Validation criteria:
- The `max_usage_slope_up_ratio` should not exceed the defined
`config.HPA_SCALE_LIMIT`.
- The `recommended_min_replicas` must be less than the
`recommended_max_replicas`.
- The recommendations Target CPU must be greater than the config.MIN_HPA_TARGET_CPU
'''
HPA_SCALE_LIMIT = config.HPA_SCALE_LIMIT
MIN_HPA_TARGET_CPU = config.MIN_HPA_TARGET_CPU
if plan.max_usage_slope_up_ratio > HPA_SCALE_LIMIT:
msg = 'max_usage_slope_up_ratio: {} exceeds HPA_SCALE_LIMIT {}'.format(
plan.max_usage_slope_up_ratio, HPA_SCALE_LIMIT
)
return False, msg
if (
plan.recommended_min_replicas
> plan.recommended_max_replicas
):
msg = 'min replicas {} greater than max replicas {}'.format(
plan.recommended_min_replicas,
plan.recommended_max_replicas,
)
return False, msg
if plan.recommended_hpa_target_cpu < MIN_HPA_TARGET_CPU:
msg =(
'recommended_hpa_target_cpu {} is less than MIN_HPA_TARGET_CPU {}'
.format(plan.recommended_hpa_target_cpu, MIN_HPA_TARGET_CPU)
)
return False, msg
return True, None