Skip to content

Commit efacebb

Browse files
author
German Robayo Paz
committed
[AKS] Add mesh Istio CNI commands for az aks mesh
1 parent dafc697 commit efacebb

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,23 @@
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: This command enables Istio CNI chaining as the proxy redirection mechanism for Azure Service Mesh. CNI chaining provides better security and performance compared to init containers by using CNI plugins to set up traffic redirection.
3561+
examples:
3562+
- name: Enable Istio CNI chaining for Azure Service Mesh.
3563+
text: az aks mesh enable-istio-cni --resource-group MyResourceGroup --name MyManagedCluster
3564+
"""
3565+
3566+
helps['aks mesh disable-istio-cni'] = """
3567+
type: command
3568+
short-summary: Disable Istio CNI chaining for Azure Service Mesh proxy redirection mechanism.
3569+
long-summary: This command disables Istio CNI chaining and reverts to using init containers as the proxy redirection mechanism for Azure Service Mesh. This is the traditional method using privileged init containers to set up iptables rules.
3570+
examples:
3571+
- name: Disable Istio CNI chaining for Azure Service Mesh.
3572+
text: az aks mesh disable-istio-cni --resource-group MyResourceGroup --name MyManagedCluster
3573+
"""
35573574

35583575
helps['aks approuting'] = """
35593576
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: 41 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,42 @@ 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 both enable and disable Istio CNI at the same time.",
3247+
)
3248+
3249+
# Check if service mesh is enabled before allowing CNI changes
3250+
if enable_istio_cni or disable_istio_cni:
3251+
if new_profile is None or new_profile.mode == CONST_AZURE_SERVICE_MESH_MODE_DISABLED:
3252+
raise ArgumentUsageError(
3253+
"Istio has not been enabled for this cluster, please refer to https://aka.ms/asm-aks-addon-docs "
3254+
"for more details on enabling Azure Service Mesh."
3255+
)
3256+
3257+
# Ensure istio profile exists
3258+
if new_profile.istio is None:
3259+
new_profile.istio = self.models.IstioServiceMesh() # pylint: disable=no-member
3260+
3261+
# Ensure components exist
3262+
if new_profile.istio.components is None:
3263+
new_profile.istio.components = self.models.IstioComponents() # pylint: disable=no-member
3264+
3265+
if enable_istio_cni:
3266+
new_profile.istio.components.proxy_redirection_mechanism = CONST_AZURE_SERVICE_MESH_PROXY_REDIRECTION_CNI_CHAINING
3267+
updated = True
3268+
elif disable_istio_cni:
3269+
new_profile.istio.components.proxy_redirection_mechanism = CONST_AZURE_SERVICE_MESH_PROXY_REDIRECTION_INIT_CONTAINERS
3270+
updated = True
3271+
3272+
return new_profile, updated
3273+
32363274
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
32373275
def update_azure_service_mesh_profile(self) -> ServiceMeshProfile:
32383276
""" Update azure service mesh profile.
@@ -3267,6 +3305,9 @@ def update_azure_service_mesh_profile(self) -> ServiceMeshProfile:
32673305
new_profile, updated_upgrade_asm = self._handle_upgrade_asm(new_profile)
32683306
updated |= updated_upgrade_asm
32693307

3308+
new_profile, updated_istio_cni = self._handle_istio_cni_asm(new_profile)
3309+
updated |= updated_istio_cni
3310+
32703311
if updated:
32713312
return new_profile
32723313
return self.mc.service_mesh_profile

0 commit comments

Comments
 (0)