Skip to content

Commit 60fbf22

Browse files
authored
{AKS} Replace Workload Identity related functions in aks-preview with azure-cli (#6987)
1 parent 40f07b1 commit 60fbf22

File tree

5 files changed

+10
-93
lines changed

5 files changed

+10
-93
lines changed

src/aks-preview/HISTORY.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ To release a new version, please select a new version number (usually plus 1 to
1111

1212
Pending
1313
+++++++
14+
15+
0.5.174
16+
+++++++
1417
* Fix the response format for `az aks mesh get-revisions` and `az aks mesh get-upgrades`.
1518
* Fix for `az aks approuting update` command failing on granting keyvault permissions to managed identity.
19+
* Replace Workload Identity related functions with stable version.
1620

1721
0.5.173
1822
+++++++
@@ -1426,4 +1430,4 @@ Pending
14261430
+++++
14271431

14281432
* new feature `enable-cluster-autoscaler`
1429-
* default agentType is VMSS
1433+
* default agentType is VMSS

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def load_arguments(self, _):
465465
c.argument('enable_pod_security_policy', action='store_true', deprecate_info=c.deprecate(target='--enable-pod-security-policy', hide=True))
466466
c.argument('enable_pod_identity', action='store_true')
467467
c.argument('enable_pod_identity_with_kubenet', action='store_true')
468-
c.argument('enable_workload_identity', action='store_true', is_preview=True)
468+
c.argument('enable_workload_identity', action='store_true')
469469
c.argument('enable_image_cleaner', action='store_true')
470470
c.argument('enable_azure_service_mesh',
471471
options_list=["--enable-azure-service-mesh", "--enable-asm"],
@@ -614,8 +614,8 @@ def load_arguments(self, _):
614614
c.argument('enable_pod_identity', action='store_true')
615615
c.argument('enable_pod_identity_with_kubenet', action='store_true')
616616
c.argument('disable_pod_identity', action='store_true')
617-
c.argument('enable_workload_identity', action='store_true', is_preview=True)
618-
c.argument('disable_workload_identity', action='store_true', is_preview=True)
617+
c.argument('enable_workload_identity', action='store_true')
618+
c.argument('disable_workload_identity', action='store_true')
619619
c.argument('enable_image_cleaner', action='store_true')
620620
c.argument('disable_image_cleaner', action='store_true', validator=validate_image_cleaner_enable_disable_mutually_exclusive)
621621
c.argument('image_cleaner_interval_hours', type=int)

src/aks-preview/azext_aks_preview/managed_cluster_decorator.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,58 +1014,6 @@ def get_enable_pod_identity_with_kubenet(self) -> bool:
10141014
"""
10151015
return self._get_enable_pod_identity_with_kubenet(enable_validation=True)
10161016

1017-
def get_workload_identity_profile(self) -> Optional[ManagedClusterSecurityProfileWorkloadIdentity]:
1018-
"""Obtrain the value of security_profile.workload_identity.
1019-
1020-
:return: Optional[ManagedClusterSecurityProfileWorkloadIdentity]
1021-
"""
1022-
# NOTE: enable_workload_identity can be one of:
1023-
#
1024-
# - True: sets by user, to enable the workload identity feature
1025-
# - False: sets by user, to disable the workload identity feature
1026-
# - None: user unspecified, don't set the profile and let server side to backfill
1027-
enable_workload_identity = self.raw_param.get("enable_workload_identity")
1028-
disable_workload_identity = self.raw_param.get("disable_workload_identity")
1029-
1030-
if not enable_workload_identity and not disable_workload_identity:
1031-
return None
1032-
1033-
if enable_workload_identity and disable_workload_identity:
1034-
raise MutuallyExclusiveArgumentError(
1035-
"Cannot specify --enable-workload-identity and "
1036-
"--disable-workload-identity at the same time."
1037-
)
1038-
1039-
if not hasattr(self.models, "ManagedClusterSecurityProfileWorkloadIdentity"):
1040-
raise UnknownError("Workload Identity's data model not found")
1041-
1042-
profile = self.models.ManagedClusterSecurityProfileWorkloadIdentity()
1043-
1044-
if self.decorator_mode == DecoratorMode.UPDATE:
1045-
if self.mc.security_profile is not None and self.mc.security_profile.workload_identity is not None:
1046-
# reuse previous profile is has been set
1047-
profile = self.mc.security_profile.workload_identity
1048-
1049-
profile.enabled = bool(enable_workload_identity)
1050-
1051-
if profile.enabled:
1052-
# in enable case, we need to check if OIDC issuer has been enabled
1053-
oidc_issuer_profile = self.get_oidc_issuer_profile()
1054-
if self.decorator_mode == DecoratorMode.UPDATE and oidc_issuer_profile is None:
1055-
# if the cluster has enabled OIDC issuer before, in update call:
1056-
#
1057-
# az aks update --enable-workload-identity
1058-
#
1059-
# we need to use previous OIDC issuer profile
1060-
oidc_issuer_profile = self.mc.oidc_issuer_profile
1061-
oidc_issuer_enabled = oidc_issuer_profile is not None and oidc_issuer_profile.enabled
1062-
if not oidc_issuer_enabled:
1063-
raise RequiredArgumentMissingError(
1064-
"Enabling workload identity requires enabling OIDC issuer (--enable-oidc-issuer)."
1065-
)
1066-
1067-
return profile
1068-
10691017
def get_enable_image_integrity(self) -> bool:
10701018
"""Obtain the value of enable_image_integrity.
10711019
@@ -2684,21 +2632,6 @@ def set_up_pod_identity_profile(self, mc: ManagedCluster) -> ManagedCluster:
26842632
mc.pod_identity_profile = pod_identity_profile
26852633
return mc
26862634

2687-
def set_up_workload_identity_profile(self, mc: ManagedCluster) -> ManagedCluster:
2688-
"""Set up workload identity for the ManagedCluster object.
2689-
2690-
:return: the ManagedCluster object
2691-
"""
2692-
self._ensure_mc(mc)
2693-
2694-
profile = self.context.get_workload_identity_profile()
2695-
if profile:
2696-
if mc.security_profile is None:
2697-
mc.security_profile = self.models.ManagedClusterSecurityProfile()
2698-
mc.security_profile.workload_identity = profile
2699-
2700-
return mc
2701-
27022635
def set_up_image_integrity(self, mc: ManagedCluster) -> ManagedCluster:
27032636
"""Set up security profile imageIntegrity for the ManagedCluster object.
27042637
@@ -3697,26 +3630,6 @@ def update_pod_identity_profile(self, mc: ManagedCluster) -> ManagedCluster:
36973630
mc, enable=False, models=self.models.pod_identity_models)
36983631
return mc
36993632

3700-
def update_workload_identity_profile(self, mc: ManagedCluster) -> ManagedCluster:
3701-
"""Update workload identity profile for the ManagedCluster object.
3702-
3703-
:return: the ManagedCluster object
3704-
"""
3705-
self._ensure_mc(mc)
3706-
3707-
profile = self.context.get_workload_identity_profile()
3708-
if profile is None:
3709-
if mc.security_profile is not None:
3710-
# set the value to None to let server side to fill in the default value
3711-
mc.security_profile.workload_identity = None
3712-
return mc
3713-
3714-
if mc.security_profile is None:
3715-
mc.security_profile = self.models.ManagedClusterSecurityProfile()
3716-
mc.security_profile.workload_identity = profile
3717-
3718-
return mc
3719-
37203633
def update_k8s_support_plan(self, mc: ManagedCluster) -> ManagedCluster:
37213634
"""Update supportPlan for the ManagedCluster object.
37223635
:return: the ManagedCluster object

src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5924,7 +5924,7 @@ def test_update_workload_identity_profile__default_value_mc_enabled(self):
59245924
)
59255925
dec.context.attach_mc(mc)
59265926
updated_mc = dec.update_workload_identity_profile(mc)
5927-
self.assertIsNone(updated_mc.security_profile.workload_identity)
5927+
self.assertIsNotNone(updated_mc.security_profile.workload_identity)
59285928

59295929
def test_update_workload_identity_profile__enabled(self):
59305930
dec = AKSPreviewManagedClusterUpdateDecorator(

src/aks-preview/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from setuptools import setup, find_packages
1111

12-
VERSION = "0.5.173"
12+
VERSION = "0.5.174"
1313

1414
CLASSIFIERS = [
1515
"Development Status :: 4 - Beta",

0 commit comments

Comments
 (0)