enable_auto_scaling misbehavior
-
Package Name: azure.mgmt.containerservice
-
Package Version: 23.0.0
-
Operating System: Windows 11
-
Python Version: 3.10
Describe the bug While using underscore parameters/properties for the autoscaler ("enable_auto_scaling", "max_count", "min_count") the AKS cluster node pool changes from Autoscale to Manual.
To Reproduce Steps to reproduce the behavior:
- Create an AKS cluster and set the Autoscaler (1 - 10) for the node pool
- Use underscores for the parameters/properties and Run the code:
from azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClient
def main():
client = ContainerServiceClient(
credential=DefaultAzureCredential(exclude_interactive_browser_credential=False),
subscription_id="PLACEHOLDER"
)
response = client.agent_pools.begin_create_or_update(
resource_group_name="PLACEHOLDER",
resource_name="PLACEHOLDER",
agent_pool_name="PLACEHOLDER",
parameters={
"properties": {
"type": "VirtualMachineScaleSets",
"enable_auto_scaling": True,
"max_count": 10,
"min_count": 1,
"osType": "Linux"
#"mode": "System"
}
},
).result()
print(response)
if __name__ == "__main__":
main()
3 The output reports "...'max_count': None, 'min_count': None, 'enable_auto_scaling': None..." (Process finished with exit code 0)
Expected behavior It should throw out an error at validation or it should not change the AKS autoscaler to manual/"None" (keep the Autoscaler enabled as it was set at AKS cluster creation time).
Screenshots NA
Additional context NA
Thank you for the feedback @NitroAMD . We will investigate and get back to you asap.
Hi @NitroAMD When you input dict into model, the key name shall be camel-case instead of snake-case:
...
"enableAutoScaling": True,
"maxCount": 10,
"minCount": 1,
...
Here is the sample reference: https://github.com/Azure/azure-sdk-for-python/blob/b0e9822238b878140ba07328e8e7d30b13364776/sdk/containerservice/azure-mgmt-containerservice/generated_samples/agent_pools_update.py#L39-L41
Hi @NitroAMD. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
Thanks and yes enableAutoScaling, maxCount, minCount works as expected, but my reported issue is related to properties with an underscore (snake case):
"enable_auto_scaling", "max_count", "min_count"
Why I get no error at validation and/or why it is removing the Autoscaler and putting it to "Manual" (it was on "Autoscale" before) with these Properties? 3 The output reports "...'max_count': None, 'min_count': None, 'enable_auto_scaling': None..." (Process finished with exit code 0)
Let me introduce more about operation https://github.com/Azure/azure-sdk-for-python/blob/97511f2358a8fcbedfdb0de9962a21534368e613/sdk/containerservice/azure-mgmt-containerservice/azure/mgmt/containerservice/v2023_04_01/operations/_agent_pools_operations.py#L762-L771.
For convenient usage, Python SDK accept two kinds of type for parameters.
(1) model
from azure.mgmt.containerservice.models import AgentPool
client.agent_pools.begin_create_or_update(..., parameters=AgentPool(
max_count=10, min_count=1, enable_auto_scaling=True
))
(2) json-like object
client.agent_pools.begin_create_or_update(...,
parameters={
"properties": {
"enableAutoScaling": True,
"maxCount": 10,
"minCount": 1,
}})
We can see: with model, the attribute is snake-case which follows python naming pattern; with json-like object, the name pattern becomes camel-case which is same with swagger definion. Users can choose the way they like to input.
And yes, the model vs. json-like object confused me a bit as some documentations referenced to a camel style some to snake one. But can you think of any type of a latest behavior change in that direction? Seems like snake case worked fine until May 11, 2023 (got that details from another contact) and now the autoscaler gets onto manual instead of leaving the autoscaler on automatic. I mean, it is on autoscaler "automatic" and we send the correct properties in snake case, but that triggers an odd "manual" ("None") action.
Here is my sample file: https://github.com/Azure-Samples/azure-samples-python-management/blob/main/samples/containerservice/manage_agent_pool.py. After running it, Autoscaling is still enabled:
So I guess maybe customer change it configuration in other way with negligence?
1 But why the JSON approach is not throwing out an validation error as the model approach is doing? model error
enableautoscaling is not a known attribute of class <class 'azure.mgmt.containerservice.v2023_04_01.models._models_py3.AgentPool'> and will be ignored
maxcount is not a known attribute of class <class 'azure.mgmt.containerservice.v2023_04_01.models._models_py3.AgentPool'> and will be ignored
mincount is not a known attribute of class <class 'azure.mgmt.containerservice.v2023_04_01.models._models_py3.AgentPool'> and will be ignored
2 Again, while running the model approach with camel case (see 1 above - the wrong way) this time it again changes to "Manual" from Auto So does this means, that Python SDK is sending stuff (while with wrong parameters) to the Azure API which the Azure API cannot parse correctly in some way, so that it sets a default value setting for "Scale node pool" to Manual? I thought that nothing will change or it should stay "as is" if no correct parameters are used.
- It is by design
Again, while running the model approach with camel case (see 1 above - the wrong way) this time->I want to emphasize again about the right way to use model. And here is the sample: https://github.com/Azure-Samples/azure-samples-python-management/blob/main/samples/containerservice/manage_agent_pool.py
Also, if you still think Python SDK send wrong params, you can:
(1) set logging_enable in client:
client = ContainerServiceClient(..., logging_enable=True)
(2) then follow https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/debug_guide.md. With the up configuration, you can see all the process including raw request body and response between SDK client and service server
Hi @NitroAMD, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.
/unresolve
Hi $welersonlisboa1970, only the original author of the issue can ask that it be unresolved. Please open a new issue with your scenario and details if you would like to discuss this topic with the team.
Hi, for this issue, AKS has an internal meeting and decided to change the current agent pool update behavior for cluster autoscaler setting. If users do not provide any cluster autoscaler related setting, AKS resource provider would keep the old cluster autoscaler setting instead of disable it. This PR will go with July 16, 2023 release. So, please allow 2-3 weeks for the code to release to global.