Skip to content

Commit f81826a

Browse files
committed
fix
1 parent e60cbd3 commit f81826a

2 files changed

Lines changed: 32 additions & 11 deletions

File tree

src/aks-preview/azext_aks_preview/agentpool_decorator.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,10 +1560,23 @@ def set_up_machines_mode(self, agentpool: AgentPool) -> AgentPool:
15601560
if mode == CONST_NODEPOOL_MODE_MACHINES:
15611561
agentpool.mode = CONST_NODEPOOL_MODE_MACHINES
15621562
# Make sure all other attributes are None
1563-
for attr in vars(agentpool):
1564-
if attr != 'name' and attr != 'mode' and not attr.startswith('_'):
1565-
if hasattr(agentpool, attr):
1563+
# Check properties sub-model first (AgentPool), then flat fields (ManagedClusterAgentPoolProfile)
1564+
props = getattr(agentpool, 'properties', None)
1565+
if props is not None and hasattr(props, '_attr_to_rest_field'):
1566+
target, fields = props, props._attr_to_rest_field
1567+
elif hasattr(agentpool, '_attr_to_rest_field') and 'mode' in agentpool._attr_to_rest_field:
1568+
target, fields = agentpool, agentpool._attr_to_rest_field
1569+
else:
1570+
target, fields = None, None
1571+
if target is not None:
1572+
for attr in list(fields.keys()):
1573+
if attr not in ('name', 'mode'):
15661574
setattr(agentpool, attr, None)
1575+
else:
1576+
for attr in vars(agentpool):
1577+
if attr != 'name' and attr != 'mode' and not attr.startswith('_'):
1578+
if hasattr(agentpool, attr):
1579+
setattr(agentpool, attr, None)
15671580

15681581
return agentpool
15691582

src/aks-preview/azext_aks_preview/managed_cluster_decorator.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5570,15 +5570,23 @@ def update_managed_system_pools(self, mc: ManagedCluster) -> ManagedCluster:
55705570
# Check if agentpool is in ManagedSystem mode and handle special case
55715571
if agentpool.mode == CONST_NODEPOOL_MODE_MANAGEDSYSTEM:
55725572
# Make sure all other attributes are None
5573-
# Use _attr_to_rest_field for new SDK models, fall back to vars() for old SDK
5574-
field_names = getattr(agentpool, '_attr_to_rest_field', None)
5575-
if field_names is not None:
5576-
attrs = list(field_names.keys())
5573+
# Check properties sub-model first (AgentPool), then flat fields (ManagedClusterAgentPoolProfile)
5574+
props = getattr(agentpool, 'properties', None)
5575+
if props is not None and hasattr(props, '_attr_to_rest_field'):
5576+
target, fields = props, props._attr_to_rest_field
5577+
elif hasattr(agentpool, '_attr_to_rest_field') and 'mode' in agentpool._attr_to_rest_field:
5578+
target, fields = agentpool, agentpool._attr_to_rest_field
55775579
else:
5578-
attrs = [a for a in vars(agentpool) if not a.startswith('_')]
5579-
for attr in attrs:
5580-
if attr not in ('name', 'mode'):
5581-
setattr(agentpool, attr, None)
5580+
target, fields = None, None
5581+
if target is not None:
5582+
for attr in list(fields.keys()):
5583+
if attr not in ('name', 'mode'):
5584+
setattr(agentpool, attr, None)
5585+
else:
5586+
for attr in vars(agentpool):
5587+
if attr != 'name' and attr != 'mode' and not attr.startswith('_'):
5588+
if hasattr(agentpool, attr):
5589+
setattr(agentpool, attr, None)
55825590
return mc
55835591

55845592
def init_models(self) -> None:

0 commit comments

Comments
 (0)