Skip to content

Commit 3f187dc

Browse files
authored
[AKS] Add mesh Istio CNI commands for az aks mesh (#9286)
1 parent dafc697 commit 3f187dc

File tree

10 files changed

+3087
-111
lines changed

10 files changed

+3087
-111
lines changed

src/aks-preview/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ To release a new version, please select a new version number (usually plus 1 to
1111

1212
Pending
1313
+++++++
14+
15+
19.0.0b5
16+
+++++++
1417
* `az aks get-credentials`: Convert device code mode kubeconfig to Azure CLI token format to bypass conditional access login blocks.
18+
* Add `enable-istio-cni` and `disable-istio-cni` commands under `az aks mesh`.
1519

1620
19.0.0b4
1721
+++++++

src/aks-preview/azext_aks_preview/_consts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@
334334
CONST_AZURE_SERVICE_MESH_UPGRADE_COMMAND_ROLLBACK = "Rollback"
335335
CONST_AZURE_SERVICE_MESH_DEFAULT_EGRESS_NAMESPACE = "aks-istio-egress"
336336
CONST_AZURE_SERVICE_MESH_MAX_EGRESS_NAME_LENGTH = 253
337+
CONST_AZURE_SERVICE_MESH_PROXY_REDIRECTION_INIT_CONTAINERS = "InitContainers"
338+
CONST_AZURE_SERVICE_MESH_PROXY_REDIRECTION_CNI_CHAINING = "CNIChaining"
337339

338340
# Node Provisioning Mode Consts
339341
CONST_NODE_PROVISIONING_MODE_MANUAL = "Manual"

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,30 @@
35543554
text: az aks mesh upgrade rollback --resource-group MyResourceGroup --name MyManagedCluster
35553555
"""
35563556

3557+
helps['aks mesh enable-istio-cni'] = """
3558+
type: command
3559+
short-summary: Enable Istio CNI chaining for Azure Service Mesh proxy redirection mechanism.
3560+
long-summary: >
3561+
This command enables Istio CNI chaining as the proxy redirection mechanism
3562+
for Azure Service Mesh. CNI chaining provides better security and performance
3563+
compared to init containers by using CNI plugins to set up traffic redirection.
3564+
examples:
3565+
- name: Enable Istio CNI chaining for Azure Service Mesh.
3566+
text: az aks mesh enable-istio-cni --resource-group MyResourceGroup --name MyManagedCluster
3567+
"""
3568+
3569+
helps['aks mesh disable-istio-cni'] = """
3570+
type: command
3571+
short-summary: Disable Istio CNI chaining for Azure Service Mesh proxy redirection mechanism.
3572+
long-summary: >
3573+
This command disables Istio CNI chaining and reverts to using init
3574+
containers as the proxy redirection mechanism for Azure Service Mesh. This
3575+
is the traditional method using privileged init containers to set up
3576+
iptables rules.
3577+
examples:
3578+
- name: Disable Istio CNI chaining for Azure Service Mesh.
3579+
text: az aks mesh disable-istio-cni --resource-group MyResourceGroup --name MyManagedCluster
3580+
"""
35573581

35583582
helps['aks approuting'] = """
35593583
type: group

src/aks-preview/azext_aks_preview/commands.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,16 @@ def load_command_table(self, _):
441441
"aks_mesh_get_upgrades",
442442
table_transformer=aks_mesh_upgrades_table_format,
443443
)
444+
g.custom_command(
445+
"enable-istio-cni",
446+
"aks_mesh_enable_istio_cni",
447+
supports_no_wait=True,
448+
)
449+
g.custom_command(
450+
"disable-istio-cni",
451+
"aks_mesh_disable_istio_cni",
452+
supports_no_wait=True,
453+
)
444454

445455
# AKS mesh upgrade commands
446456
with self.command_group(

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3972,6 +3972,38 @@ def aks_mesh_upgrade_rollback(
39723972
mesh_upgrade_command=CONST_AZURE_SERVICE_MESH_UPGRADE_COMMAND_ROLLBACK)
39733973

39743974

3975+
def aks_mesh_enable_istio_cni(
3976+
cmd,
3977+
client,
3978+
resource_group_name,
3979+
name,
3980+
):
3981+
"""Enable Istio CNI chaining for the Azure Service Mesh proxy redirection mechanism."""
3982+
return _aks_mesh_update(
3983+
cmd,
3984+
client,
3985+
resource_group_name,
3986+
name,
3987+
enable_istio_cni=True,
3988+
)
3989+
3990+
3991+
def aks_mesh_disable_istio_cni(
3992+
cmd,
3993+
client,
3994+
resource_group_name,
3995+
name,
3996+
):
3997+
"""Disable Istio CNI chaining for the Azure Service Mesh proxy redirection mechanism."""
3998+
return _aks_mesh_update(
3999+
cmd,
4000+
client,
4001+
resource_group_name,
4002+
name,
4003+
disable_istio_cni=True,
4004+
)
4005+
4006+
39754007
def _aks_mesh_get_supported_revisions(
39764008
cmd,
39774009
client,
@@ -4006,6 +4038,8 @@ def _aks_mesh_update(
40064038
revision=None,
40074039
yes=False,
40084040
mesh_upgrade_command=None,
4041+
enable_istio_cni=None,
4042+
disable_istio_cni=None,
40094043
):
40104044
raw_parameters = locals()
40114045

src/aks-preview/azext_aks_preview/managed_cluster_decorator.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
CONST_AZURE_SERVICE_MESH_UPGRADE_COMMAND_ROLLBACK,
2020
CONST_AZURE_SERVICE_MESH_UPGRADE_COMMAND_START,
2121
CONST_AZURE_SERVICE_MESH_DEFAULT_EGRESS_NAMESPACE,
22+
CONST_AZURE_SERVICE_MESH_PROXY_REDIRECTION_CNI_CHAINING,
23+
CONST_AZURE_SERVICE_MESH_PROXY_REDIRECTION_INIT_CONTAINERS,
2224
CONST_LOAD_BALANCER_SKU_BASIC,
2325
CONST_MANAGED_CLUSTER_SKU_NAME_BASE,
2426
CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC,
@@ -3233,6 +3235,45 @@ def _handle_enable_disable_asm(self, new_profile: ServiceMeshProfile) -> Tuple[S
32333235

32343236
return new_profile, updated
32353237

3238+
def _handle_istio_cni_asm(self, new_profile: ServiceMeshProfile) -> Tuple[ServiceMeshProfile, bool]:
3239+
"""Handle enable/disable Istio CNI proxy redirection mechanism."""
3240+
updated = False
3241+
enable_istio_cni = self.raw_param.get("enable_istio_cni", False)
3242+
disable_istio_cni = self.raw_param.get("disable_istio_cni", False)
3243+
3244+
if enable_istio_cni and disable_istio_cni:
3245+
raise MutuallyExclusiveArgumentError(
3246+
"Cannot specify --enable-istio-cni and "
3247+
"--disable-istio-cni at the same time."
3248+
)
3249+
3250+
# Check if service mesh is enabled before allowing CNI changes
3251+
if enable_istio_cni or disable_istio_cni:
3252+
if new_profile is None or new_profile.mode == CONST_AZURE_SERVICE_MESH_MODE_DISABLED:
3253+
raise ArgumentUsageError(
3254+
"Istio has not been enabled for this cluster, please refer to https://aka.ms/asm-aks-addon-docs "
3255+
"for more details on enabling Azure Service Mesh."
3256+
)
3257+
3258+
# Ensure istio profile exists
3259+
if new_profile.istio is None:
3260+
new_profile.istio = self.models.IstioServiceMesh() # pylint: disable=no-member
3261+
3262+
# Ensure components exist
3263+
if new_profile.istio.components is None:
3264+
new_profile.istio.components = self.models.IstioComponents() # pylint: disable=no-member
3265+
3266+
if enable_istio_cni:
3267+
new_profile.istio.components.proxy_redirection_mechanism = \
3268+
CONST_AZURE_SERVICE_MESH_PROXY_REDIRECTION_CNI_CHAINING
3269+
updated = True
3270+
elif disable_istio_cni:
3271+
new_profile.istio.components.proxy_redirection_mechanism = \
3272+
CONST_AZURE_SERVICE_MESH_PROXY_REDIRECTION_INIT_CONTAINERS
3273+
updated = True
3274+
3275+
return new_profile, updated
3276+
32363277
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
32373278
def update_azure_service_mesh_profile(self) -> ServiceMeshProfile:
32383279
""" Update azure service mesh profile.
@@ -3267,6 +3308,9 @@ def update_azure_service_mesh_profile(self) -> ServiceMeshProfile:
32673308
new_profile, updated_upgrade_asm = self._handle_upgrade_asm(new_profile)
32683309
updated |= updated_upgrade_asm
32693310

3311+
new_profile, updated_istio_cni = self._handle_istio_cni_asm(new_profile)
3312+
updated |= updated_istio_cni
3313+
32703314
if updated:
32713315
return new_profile
32723316
return self.mc.service_mesh_profile

0 commit comments

Comments
 (0)