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
88 changes: 59 additions & 29 deletions src/aks-preview/azext_aks_preview/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
InvalidArgumentValueError,
MutuallyExclusiveArgumentError,
RequiredArgumentMissingError,
UnknownError,
)
from azure.cli.core.commands import AzCliCommand
from azure.cli.core.profiles import ResourceType
Expand Down Expand Up @@ -1014,15 +1015,16 @@ def _get_enable_windows_gmsa(self, enable_validation: bool = False, **kwargs) ->
"""
# read the original value passed by the command
enable_windows_gmsa = self.raw_param.get("enable_windows_gmsa")
# try to read the property value corresponding to the parameter from the `mc` object
if (
self.mc and
self.mc.windows_profile and
hasattr(self.mc.windows_profile, "gmsa_profile") and # backward compatibility
self.mc.windows_profile.gmsa_profile and
self.mc.windows_profile.gmsa_profile.enabled is not None
):
enable_windows_gmsa = self.mc.windows_profile.gmsa_profile.enabled
# In create mode, try to read the property value corresponding to the parameter from the `mc` object.
if self.decorator_mode == DecoratorMode.CREATE:
if (
self.mc and
self.mc.windows_profile and
hasattr(self.mc.windows_profile, "gmsa_profile") and # backward compatibility
self.mc.windows_profile.gmsa_profile and
self.mc.windows_profile.gmsa_profile.enabled is not None
):
enable_windows_gmsa = self.mc.windows_profile.gmsa_profile.enabled

# this parameter does not need dynamic completion
# validation
Expand Down Expand Up @@ -1064,32 +1066,34 @@ def _get_gmsa_dns_server_and_root_domain_name(self, enable_validation: bool = Fa
# gmsa_dns_server
# read the original value passed by the command
gmsa_dns_server = self.raw_param.get("gmsa_dns_server")
# try to read the property value corresponding to the parameter from the `mc` object
# In create mode, try to read the property value corresponding to the parameter from the `mc` object.
gmsa_dns_read_from_mc = False
if (
self.mc and
self.mc.windows_profile and
hasattr(self.mc.windows_profile, "gmsa_profile") and # backward compatibility
self.mc.windows_profile.gmsa_profile and
self.mc.windows_profile.gmsa_profile.dns_server is not None
):
gmsa_dns_server = self.mc.windows_profile.gmsa_profile.dns_server
gmsa_dns_read_from_mc = True
if self.decorator_mode == DecoratorMode.CREATE:
if (
self.mc and
self.mc.windows_profile and
hasattr(self.mc.windows_profile, "gmsa_profile") and # backward compatibility
self.mc.windows_profile.gmsa_profile and
self.mc.windows_profile.gmsa_profile.dns_server is not None
):
gmsa_dns_server = self.mc.windows_profile.gmsa_profile.dns_server
gmsa_dns_read_from_mc = True

# gmsa_root_domain_name
# read the original value passed by the command
gmsa_root_domain_name = self.raw_param.get("gmsa_root_domain_name")
# try to read the property value corresponding to the parameter from the `mc` object
# In create mode, try to read the property value corresponding to the parameter from the `mc` object.
gmsa_root_read_from_mc = False
if (
self.mc and
self.mc.windows_profile and
hasattr(self.mc.windows_profile, "gmsa_profile") and # backward compatibility
self.mc.windows_profile.gmsa_profile and
self.mc.windows_profile.gmsa_profile.root_domain_name is not None
):
gmsa_root_domain_name = self.mc.windows_profile.gmsa_profile.root_domain_name
gmsa_root_read_from_mc = True
if self.decorator_mode == DecoratorMode.CREATE:
if (
self.mc and
self.mc.windows_profile and
hasattr(self.mc.windows_profile, "gmsa_profile") and # backward compatibility
self.mc.windows_profile.gmsa_profile and
self.mc.windows_profile.gmsa_profile.root_domain_name is not None
):
gmsa_root_domain_name = self.mc.windows_profile.gmsa_profile.root_domain_name
gmsa_root_read_from_mc = True

# consistent check
if gmsa_dns_read_from_mc != gmsa_root_read_from_mc:
Expand Down Expand Up @@ -1718,6 +1722,8 @@ def __init__(
def update_load_balancer_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Update load balancer profile for the ManagedCluster object.

Note: Inherited and extended in aks-preview to set dual stack related properties.

:return: the ManagedCluster object
"""
mc = super().update_load_balancer_profile(mc)
Expand Down Expand Up @@ -1750,6 +1756,30 @@ def update_pod_security_policy(self, mc: ManagedCluster) -> ManagedCluster:
mc.enable_pod_security_policy = False
return mc

def update_windows_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Update windows profile for the ManagedCluster object.

Note: Inherited and extended in aks-preview to set gmsa related properties.

:return: the ManagedCluster object
"""
mc = super().update_windows_profile(mc)
windows_profile = mc.windows_profile

if self.context.get_enable_windows_gmsa():
if not windows_profile:
raise UnknownError(
"Encounter an unexpected error while getting windows profile "
"from the cluster in the process of update."
)
gmsa_dns_server, gmsa_root_domain_name = self.context.get_gmsa_dns_server_and_root_domain_name()
windows_profile.gmsa_profile = self.models.WindowsGmsaProfile(
enabled=True,
dns_server=gmsa_dns_server,
root_domain_name=gmsa_root_domain_name,
)
return mc

def update_mc_preview_profile(self) -> ManagedCluster:
"""The overall controller used to update the preview ManagedCluster profile.

Expand Down
Loading