Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ aks update:
load_balancer_outbound_ports:
rule_exclusions:
- option_length_too_long
enable_managed_identity:
rule_exclusions:
- option_length_too_long
batch job create:
parameters:
job_manager_task_command_line:
Expand Down
16 changes: 14 additions & 2 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

from knack.help_files import helps

ACS_SERVICE_PRINCIPAL_CACHE = os.path.join('$HOME', '.azure', 'acsServicePrincipal.json')
AKS_SERVICE_PRINCIPAL_CACHE = os.path.join('$HOME', '.azure', 'aksServicePrincipal.json')
ACS_SERVICE_PRINCIPAL_CACHE = os.path.join(
'$HOME', '.azure', 'acsServicePrincipal.json')
AKS_SERVICE_PRINCIPAL_CACHE = os.path.join(
'$HOME', '.azure', 'aksServicePrincipal.json')

# AKS command help
helps['aks create'] = """
Expand Down Expand Up @@ -397,6 +399,12 @@
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
- name: --enable-managed-identity
type: bool
short-summary: (PREVIEW) Update current cluster to managed identity to manage cluster resource group.
- name: --assign-identity
type: string
short-summary: (PREVIEW) Specify an existing user assigned identity to manage cluster resource group.
examples:
- name: Enable cluster-autoscaler within node count range [1,5]
text: az aks update --enable-cluster-autoscaler --min-count 1 --max-count 5 -g MyResourceGroup -n MyManagedCluster
Expand Down Expand Up @@ -430,6 +438,10 @@
text: az aks update -g MyResourceGroup -n MyManagedCluster --enable-ahub
- name: Disable Azure Hybrid User Benefits featture for a kubernetes cluster.
text: az aks update -g MyResourceGroup -n MyManagedCluster --disable-ahub
- name: Update the cluster to use system assigned managed identity in control plane.
text: az aks update -g MyResourceGroup -n MyManagedCluster --enable-managed-identity
- name: Update the cluster to use user assigned managed identity in control plane.
text: az aks update -g MyResourceGroup -n MyManagedCluster --enable-managed-identity --assign-identity <user_assigned_identity_resource_id>
"""

helps['aks kollect'] = """
Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def load_arguments(self, _):
c.argument('attach_acr', acr_arg_type, validator=validate_acr)
c.argument('detach_acr', acr_arg_type, validator=validate_acr)
c.argument('aks_custom_headers')
c.argument('enable_managed_identity', action='store_true')
c.argument('assign_identity', type=str, validator=validate_assign_identity)
c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

with self.argument_context('aks scale') as c:
c.argument('nodepool_name', type=str,
Expand Down
52 changes: 49 additions & 3 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,10 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
aad_admin_group_object_ids=None,
enable_ahub=False,
disable_ahub=False,
aks_custom_headers=None):
aks_custom_headers=None,
enable_managed_identity=False,
assign_identity=None,
yes=False):
update_autoscaler = enable_cluster_autoscaler or disable_cluster_autoscaler or update_cluster_autoscaler
update_acr = attach_acr is not None or detach_acr is not None
update_pod_security = enable_pod_security_policy or disable_pod_security_policy
Expand All @@ -1243,7 +1246,9 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
not enable_aad and \
not update_aad_profile and \
not enable_ahub and \
not disable_ahub:
not disable_ahub and \
not enable_managed_identity and \
not assign_identity:
raise CLIError('Please specify "--enable-cluster-autoscaler" or '
'"--disable-cluster-autoscaler" or '
'"--update-cluster-autoscaler" or '
Expand All @@ -1261,7 +1266,8 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
'"--aad-tenant-id" or '
'"--aad-admin-group-object-ids" or '
'"--enable-ahub" or '
'"--disable-ahub"')
'"--disable-ahub" or'
'"--enable-managed-identity"')

instance = client.get(resource_group_name, name)

Expand Down Expand Up @@ -1397,6 +1403,46 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
if disable_ahub:
instance.windows_profile.license_type = 'None'

if not enable_managed_identity and assign_identity:
raise CLIError('--assign-identity can only be specified when --enable-managed-identity is specified')

current_identity_type = "spn"
if instance.identity is not None:
current_identity_type = instance.identity.type.casefold()

goal_identity_type = current_identity_type
if enable_managed_identity:
if not assign_identity:
goal_identity_type = "systemassigned"
else:
goal_identity_type = "userassigned"

if current_identity_type != goal_identity_type:
from knack.prompting import prompt_y_n
msg = ""
if current_identity_type == "spn":
msg = ('Your cluster is using service principal, and you are going to update the cluster to use {} managed identity.\n'
'After updating, your cluster\'s control plane and addon pods will switch to use managed identity, but kubelet '
'will KEEP USING SERVICE PRINCIPAL until you upgrade your agentpool.\n '
'Are you sure you want to perform this operation?').format(goal_identity_type)
else:
msg = ('Your cluster is already using {} managed identity, and you are going to update the cluster to use {} managed identity. \n'
'Are you sure you want to perform this operation?').format(current_identity_type, goal_identity_type)
if not yes and not prompt_y_n(msg, default="n"):
return None
if goal_identity_type == "systemassigned":
instance.identity = ManagedClusterIdentity(
type="SystemAssigned"
)
elif goal_identity_type == "userassigned":
user_assigned_identity = {
assign_identity: ManagedClusterIdentityUserAssignedIdentitiesValue()
}
instance.identity = ManagedClusterIdentity(
type="UserAssigned",
user_assigned_identities=user_assigned_identity
)

headers = get_aks_custom_headers(aks_custom_headers)
return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance, custom_headers=headers)

Expand Down
Loading