I have an AKS cluster application with knative installed and I'm trying to make a request to update its autoscale settings. I currently am working with this:
def update_service_autoscaling(self, service_name: str, namespace: str, min_scale: int, max_scale: int):
uri = f"https://{self.api_server_url}/apis/serving.knative.dev/v1/namespaces/{namespace}/services/{service_name}"
headers = {
"Authorization": f"Bearer {self.api_server_token}",
"content-type": "application/json-patch+json",
}
patch_data = [
{
"op": "add",
"path": "/spec/template/metadata/annotations/autoscaling.knative.dev~1min-scale",
"value": str(min_scale),
},
{
"op": "add",
"path": "/spec/template/metadata/annotations/autoscaling.knative.dev~1max-scale",
"value": str(max_scale),
}
]
response = requests.patch(
uri,
headers=headers,
verify=False,
json=patch_data,
)
if response.status_code != 200:
exception_message = f"HTTP {response.status_code}: {response.json()['message']}"
raise Exception(exception_message)
return response.json()
In theory it should work and all the parameters are being reached correctly, but when I make the request I get "HTTP 422: the server rejected our request due to an error in our request". I've debugged through VSCode but couldn't find what is wrong with it.
Knative service autoscale settings by sending a PATCH request to the Knative service's API. It's independent of Azure services and works with any Kubernetes cluster with Knative installed. The HTTP 422 error code indicates that the server understands the request but cannot process it due to a client-side error. Check the
URI,Authorizationheader, andpatch_data.For Error Handling:
I have also cross-checked with managing an Azure AKS cluster using the Azure SDK. It enables autoscaling for the agent pool of an AKS cluster and sets the minimum and maximum counts for the nodes in the pool. This code is specific to Azure AKS and is used to update AKS cluster settings both leads to the same response.