Closed
Description
What happened (please include outputs or screenshots):
create_namespaced_horizontal_pod_autoscaler create exception 'Invalid value for `conditions`, must not be `None`'
What you expected to happen:
No exceptions.
How to reproduce it (as minimally and precisely as possible):
from flask import jsonify
from kubernetes import client, config
config.load_kube_config()
kube = client.AutoscalingV2beta1Api()
def create_hpa_object(name, owner, max_replicas, min_replicas, target_name,
target_cpu_utilization_percentage):
hpa_body = client.V1HorizontalPodAutoscaler(
metadata=client.V1ObjectMeta(
name=name,
labels={"app": name, "owner": owner},
),
spec=client.V1HorizontalPodAutoscalerSpec(
max_replicas=max_replicas,
min_replicas=min_replicas,
scale_target_ref=client.V1CrossVersionObjectReference(
kind="Deployment",
name=target_name,
),
target_cpu_utilization_percentage=target_cpu_utilization_percentage
)
)
return hpa_body
def create_hpa(namespace, body):
resp = kube.create_namespaced_horizontal_pod_autoscaler(namespace=namespace, body=body)
return jsonify(str(resp.metadata.name))
@app.route('/hpa', methods=['POST'])
def create_hpa():
hpa_data = request.get_json()
# Read data from body and used them as Local variables
name = hpa_data['name']
namespace = hpa_data['namespace']
owner = hpa_data['owner']
max_replicas = hpa_data['max_replicas']
min_replicas = hpa_data['min_replicas']
target_name = hpa_data['target_name']
target_cpu_utilization_percentage = hpa_data['target_cpu_utilization_percentage']
# Check if the method is POST
if request.method == 'POST':
try:
# Create hpa
hpa_body = AutoscalingV1Api.create_hpa_object(name=name,
owner=owner,
max_replicas=max_replicas,
min_replicas=min_replicas,
target_name=target_name,
target_cpu_utilization_percentage=
target_cpu_utilization_percentage)
return AutoscalingV1Api.create_hpa(namespace=namespace, body=hpa_body)
except Exception as e:
# Bypass the exception to avoid misleading info
# if str(e) == 'Invalid value for `conditions`, must not be `None`':
# return "Here you need a return status function to bypass the bug of AutoscalingV1Api"
# else:
return str(e)
else:
return Exception
Anything else we need to know?:
Environment:
- Kubernetes version (v1.20.10):
- OS (Windows 10):
- Python version (3.8)
- Python client version (18.20.0)