Skip to content

Commit 32ccfec

Browse files
authored
aks: add --enable-pod-identity-with-kubenet flag (Azure#3062)
1 parent 8746092 commit 32ccfec

File tree

10 files changed

+4103
-1227
lines changed

10 files changed

+4103
-1227
lines changed

linter_exclusions.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ aks create:
7979
enable_encryption_at_host:
8080
rule_exclusions:
8181
- option_length_too_long
82+
enable_pod_identity_with_kubenet:
83+
rule_exclusions:
84+
- option_length_too_long
8285
aks enable-addons:
8386
parameters:
8487
appgw_watch_namespace:
@@ -133,6 +136,9 @@ aks update:
133136
enable_managed_identity:
134137
rule_exclusions:
135138
- option_length_too_long
139+
enable_pod_identity_with_kubenet:
140+
rule_exclusions:
141+
- option_length_too_long
136142
attestation policy set:
137143
parameters:
138144
new_attestation_policy:

src/aks-preview/HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Release History
44
===============
5+
6+
0.5.3
7+
+++++
8+
* Add `--enable-pod-identity-with-kubenet` for enabling AAD Pod Identity in Kubenet cluster
9+
* Add `--fqdn-subdomain parameter` to create private cluster with custom private dns zone scenario
10+
511
0.5.2
612
+++++
713
* Add support for node public IP prefix ID '--node-public-ip-prefix-id'

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@
304304
- name: --enable-pod-identity
305305
type: bool
306306
short-summary: (PREVIEW) Enable pod identity addon.
307+
- name: --enable-pod-identity-with-kubenet
308+
type: bool
309+
short-summary: (PREVIEW) Enable pod identity addon for cluster using Kubnet network plugin.
307310
- name: --aci-subnet-name
308311
type: string
309312
short-summary: The name of a subnet in an existing VNet into which to deploy the virtual nodes.
@@ -475,6 +478,9 @@
475478
- name: --enable-pod-identity
476479
type: bool
477480
short-summary: (PREVIEW) Enable Pod Identity addon for cluster.
481+
- name: --enable-pod-identity-with-kubenet
482+
type: bool
483+
short-summary: (PREVIEW) Enable pod identity addon for cluster using Kubnet network plugin.
478484
- name: --disable-pod-identity
479485
type: bool
480486
short-summary: (PREVIEW) Disable Pod Identity addon for cluster.

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)