Skip to content

Commit

Permalink
aks: add --enable-pod-identity-with-kubenet flag (Azure#3062)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcho authored Mar 2, 2021
1 parent 8746092 commit 32ccfec
Show file tree
Hide file tree
Showing 10 changed files with 4,103 additions and 1,227 deletions.
6 changes: 6 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ aks create:
enable_encryption_at_host:
rule_exclusions:
- option_length_too_long
enable_pod_identity_with_kubenet:
rule_exclusions:
- option_length_too_long
aks enable-addons:
parameters:
appgw_watch_namespace:
Expand Down Expand Up @@ -133,6 +136,9 @@ aks update:
enable_managed_identity:
rule_exclusions:
- option_length_too_long
enable_pod_identity_with_kubenet:
rule_exclusions:
- option_length_too_long
attestation policy set:
parameters:
new_attestation_policy:
Expand Down
6 changes: 6 additions & 0 deletions src/aks-preview/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Release History
===============

0.5.3
+++++
* Add `--enable-pod-identity-with-kubenet` for enabling AAD Pod Identity in Kubenet cluster
* Add `--fqdn-subdomain parameter` to create private cluster with custom private dns zone scenario

0.5.2
+++++
* Add support for node public IP prefix ID '--node-public-ip-prefix-id'
Expand Down
6 changes: 6 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@
- name: --enable-pod-identity
type: bool
short-summary: (PREVIEW) Enable pod identity addon.
- name: --enable-pod-identity-with-kubenet
type: bool
short-summary: (PREVIEW) Enable pod identity addon for cluster using Kubnet network plugin.
- name: --aci-subnet-name
type: string
short-summary: The name of a subnet in an existing VNet into which to deploy the virtual nodes.
Expand Down Expand Up @@ -475,6 +478,9 @@
- name: --enable-pod-identity
type: bool
short-summary: (PREVIEW) Enable Pod Identity addon for cluster.
- name: --enable-pod-identity-with-kubenet
type: bool
short-summary: (PREVIEW) Enable pod identity addon for cluster using Kubnet network plugin.
- name: --disable-pod-identity
type: bool
short-summary: (PREVIEW) Disable Pod Identity addon for cluster.
Expand Down
35 changes: 28 additions & 7 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
assign_identity=None,
auto_upgrade_channel=None,
enable_pod_identity=False,
enable_pod_identity_with_kubenet=False,
enable_encryption_at_host=False,
no_wait=False,
yes=False):
Expand Down Expand Up @@ -1188,6 +1189,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
if not enable_managed_identity:
raise CLIError('--enable-pod-identity can only be specified when --enable-managed-identity is specified')
pod_identity_profile = ManagedClusterPodIdentityProfile(enabled=True)
_ensure_pod_identity_kubenet_consent(network_profile, pod_identity_profile, enable_pod_identity_with_kubenet)

enable_rbac = True
if disable_rbac:
Expand Down Expand Up @@ -1314,6 +1316,7 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
enable_managed_identity=False,
assign_identity=None,
enable_pod_identity=False,
enable_pod_identity_with_kubenet=False,
disable_pod_identity=False,
yes=False,
tags=None):
Expand Down Expand Up @@ -1561,7 +1564,7 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
)

if enable_pod_identity:
_update_addon_pod_identity(instance, enable=True)
_update_addon_pod_identity(instance, enable=True, allow_kubenet_consent=enable_pod_identity_with_kubenet)

if disable_pod_identity:
_update_addon_pod_identity(instance, enable=False)
Expand Down Expand Up @@ -3402,22 +3405,40 @@ def _ensure_pod_identity_addon_is_enabled(instance):
'To enable, run "az aks update --enable-pod-identity')


def _update_addon_pod_identity(instance, enable, pod_identities=None, pod_identity_exceptions=None):
def _ensure_pod_identity_kubenet_consent(network_profile, pod_identity_profile, customer_consent):
if not network_profile or not network_profile.network_plugin:
# invalid data
return
if network_profile.network_plugin.lower() != 'kubenet':
# not kubenet, no need to check
return

if customer_consent is None:
# no set this time, read from previous value
customer_consent = bool(pod_identity_profile.allow_network_plugin_kubenet)

if not customer_consent:
raise CLIError('--enable-pod-identity-with-kubenet is required for enabling pod identity addon when using Kubenet network plugin')
pod_identity_profile.allow_network_plugin_kubenet = True


def _update_addon_pod_identity(instance, enable, pod_identities=None, pod_identity_exceptions=None, allow_kubenet_consent=None):
if not enable:
# when disable, null out the profile
instance.pod_identity_profile = None
# when disable, remove previous saved value
instance.pod_identity_profile = ManagedClusterPodIdentityProfile(enabled=False)
return

if not instance.pod_identity_profile:
# not set before
instance.pod_identity_profile = ManagedClusterPodIdentityProfile(
enabled=True,
enabled=enable,
user_assigned_identities=pod_identities,
user_assigned_identity_exceptions=pod_identity_exceptions,
)
return

instance.pod_identity_profile.enabled = True
_ensure_pod_identity_kubenet_consent(instance.network_profile, instance.pod_identity_profile, allow_kubenet_consent)

instance.pod_identity_profile.enabled = enable
instance.pod_identity_profile.user_assigned_identities = pod_identities or []
instance.pod_identity_profile.user_assigned_identity_exceptions = pod_identity_exceptions or []

Expand Down
Loading

0 comments on commit 32ccfec

Please sign in to comment.