@@ -903,6 +903,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
903903 assign_identity = None ,
904904 auto_upgrade_channel = None ,
905905 enable_pod_identity = False ,
906+ enable_pod_identity_with_kubenet = False ,
906907 enable_encryption_at_host = False ,
907908 no_wait = False ,
908909 yes = False ):
@@ -1188,6 +1189,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
11881189 if not enable_managed_identity :
11891190 raise CLIError ('--enable-pod-identity can only be specified when --enable-managed-identity is specified' )
11901191 pod_identity_profile = ManagedClusterPodIdentityProfile (enabled = True )
1192+ _ensure_pod_identity_kubenet_consent (network_profile , pod_identity_profile , enable_pod_identity_with_kubenet )
11911193
11921194 enable_rbac = True
11931195 if disable_rbac :
@@ -1314,6 +1316,7 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
13141316 enable_managed_identity = False ,
13151317 assign_identity = None ,
13161318 enable_pod_identity = False ,
1319+ enable_pod_identity_with_kubenet = False ,
13171320 disable_pod_identity = False ,
13181321 yes = False ,
13191322 tags = None ):
@@ -1561,7 +1564,7 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
15611564 )
15621565
15631566 if enable_pod_identity :
1564- _update_addon_pod_identity (instance , enable = True )
1567+ _update_addon_pod_identity (instance , enable = True , allow_kubenet_consent = enable_pod_identity_with_kubenet )
15651568
15661569 if disable_pod_identity :
15671570 _update_addon_pod_identity (instance , enable = False )
@@ -3402,22 +3405,40 @@ def _ensure_pod_identity_addon_is_enabled(instance):
34023405 'To enable, run "az aks update --enable-pod-identity' )
34033406
34043407
3405- def _update_addon_pod_identity (instance , enable , pod_identities = None , pod_identity_exceptions = None ):
3408+ def _ensure_pod_identity_kubenet_consent (network_profile , pod_identity_profile , customer_consent ):
3409+ if not network_profile or not network_profile .network_plugin :
3410+ # invalid data
3411+ return
3412+ if network_profile .network_plugin .lower () != 'kubenet' :
3413+ # not kubenet, no need to check
3414+ return
3415+
3416+ if customer_consent is None :
3417+ # no set this time, read from previous value
3418+ customer_consent = bool (pod_identity_profile .allow_network_plugin_kubenet )
3419+
3420+ if not customer_consent :
3421+ raise CLIError ('--enable-pod-identity-with-kubenet is required for enabling pod identity addon when using Kubenet network plugin' )
3422+ pod_identity_profile .allow_network_plugin_kubenet = True
3423+
3424+
3425+ def _update_addon_pod_identity (instance , enable , pod_identities = None , pod_identity_exceptions = None , allow_kubenet_consent = None ):
34063426 if not enable :
3407- # when disable, null out the profile
3408- instance .pod_identity_profile = None
3427+ # when disable, remove previous saved value
3428+ instance .pod_identity_profile = ManagedClusterPodIdentityProfile ( enabled = False )
34093429 return
34103430
34113431 if not instance .pod_identity_profile :
34123432 # not set before
34133433 instance .pod_identity_profile = ManagedClusterPodIdentityProfile (
3414- enabled = True ,
3434+ enabled = enable ,
34153435 user_assigned_identities = pod_identities ,
34163436 user_assigned_identity_exceptions = pod_identity_exceptions ,
34173437 )
3418- return
34193438
3420- instance .pod_identity_profile .enabled = True
3439+ _ensure_pod_identity_kubenet_consent (instance .network_profile , instance .pod_identity_profile , allow_kubenet_consent )
3440+
3441+ instance .pod_identity_profile .enabled = enable
34213442 instance .pod_identity_profile .user_assigned_identities = pod_identities or []
34223443 instance .pod_identity_profile .user_assigned_identity_exceptions = pod_identity_exceptions or []
34233444
0 commit comments