-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[AKS] Add arguments --asg-ids and --allowed-host-ports for az aks create | az aks nodepool add | az aks nodepool update
#27900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
d823423
d5589cd
07fe3fd
8cdd7cf
af6d50e
4b7cbac
5a769b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ | |
| # type variables | ||
| AgentPool = TypeVar("AgentPool") | ||
| AgentPoolsOperations = TypeVar("AgentPoolsOperations") | ||
| PortRange = TypeVar("PortRange") | ||
| Snapshot = TypeVar("Snapshot") | ||
| KubeletConfig = TypeVar("KubeletConfig") | ||
| LinuxOSConfig = TypeVar("LinuxOSConfig") | ||
|
|
@@ -1256,6 +1257,49 @@ def get_gpu_instance_profile(self) -> Union[str, None]: | |
| # this parameter does not need validation | ||
| return gpu_instance_profile | ||
|
|
||
| def get_asg_ids(self) -> Union[List[str], None]: | ||
| if self.agentpool_decorator_mode == AgentPoolDecoratorMode.MANAGED_CLUSTER: | ||
| asg_ids = self.raw_param.get('nodepool_asg_ids') | ||
| else: | ||
| asg_ids = self.raw_param.get('asg_ids') | ||
|
|
||
| if asg_ids is None: | ||
| return None | ||
| if asg_ids == '': | ||
| return [] | ||
|
|
||
| return asg_ids.split(',') | ||
|
|
||
| def get_allowed_host_ports(self) -> Union[List[PortRange], None]: | ||
| if self.agentpool_decorator_mode == AgentPoolDecoratorMode.MANAGED_CLUSTER: | ||
| ports = self.raw_param.get('nodepool_allowed_host_ports') | ||
| else: | ||
| ports = self.raw_param.get('allowed_host_ports') | ||
|
|
||
| if ports is None: | ||
| return None | ||
| if ports == '': | ||
| return [] | ||
|
|
||
| ports = ports.split(',') | ||
| port_ranges = [] | ||
| import re | ||
| regex = re.compile(r'^((\d+)|((\d+)-(\d+)))/(tcp|udp)$') | ||
clnv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for port in ports: | ||
| r = regex.findall(port) | ||
| if r[0][1] != '': | ||
| # single port | ||
| port_start, port_end = int(r[0][1]), int(r[0][1]) | ||
| else: | ||
| # port range | ||
| port_start, port_end = int(r[0][3]), int(r[0][4]) | ||
| port_ranges.append(self.models.PortRange( | ||
| port_start=port_start, | ||
| port_end=port_end, | ||
| protocol=r[0][5].upper(), | ||
| )) | ||
| return port_ranges | ||
|
|
||
|
|
||
| class AKSAgentPoolAddDecorator: | ||
| def __init__( | ||
|
|
@@ -1540,6 +1584,17 @@ def set_up_gpu_properties(self, agentpool: AgentPool) -> AgentPool: | |
| agentpool.gpu_instance_profile = self.context.get_gpu_instance_profile() | ||
| return agentpool | ||
|
|
||
| def set_up_agentpool_network_profile(self, agentpool: AgentPool) -> AgentPool: | ||
| self._ensure_agentpool(agentpool) | ||
|
|
||
| asg_ids = self.context.get_asg_ids() | ||
| allowed_host_ports = self.context.get_allowed_host_ports() | ||
| if allowed_host_ports is not None: | ||
| agentpool.network_profile = self.models.AgentPoolNetworkProfile() | ||
| agentpool.network_profile.allowed_host_ports = allowed_host_ports | ||
| agentpool.network_profile.application_security_groups = asg_ids | ||
| return agentpool | ||
|
|
||
| def construct_agentpool_profile_default(self, bypass_restore_defaults: bool = False) -> AgentPool: | ||
| """The overall controller used to construct the AgentPool profile by default. | ||
|
|
||
|
|
@@ -1574,6 +1629,8 @@ def construct_agentpool_profile_default(self, bypass_restore_defaults: bool = Fa | |
| agentpool = self.set_up_custom_node_config(agentpool) | ||
| # set up gpu instance profile | ||
| agentpool = self.set_up_gpu_properties(agentpool) | ||
| # set up agentpool network profile | ||
| agentpool = self.set_up_agentpool_network_profile(agentpool) | ||
| # restore defaults | ||
| if not bypass_restore_defaults: | ||
| agentpool = self._restore_defaults_in_agentpool(agentpool) | ||
|
|
@@ -1777,6 +1834,19 @@ def update_vm_properties(self, agentpool: AgentPool) -> AgentPool: | |
| agentpool.mode = mode | ||
| return agentpool | ||
|
|
||
| def update_network_profile(self, agentpool: AgentPool) -> AgentPool: | ||
| self._ensure_agentpool(agentpool) | ||
|
|
||
| asg_ids = self.context.get_asg_ids() | ||
| allowed_host_ports = self.context.get_allowed_host_ports() | ||
| if asg_ids or allowed_host_ports: | ||
| agentpool.network_profile = self.models.AgentPoolNetworkProfile() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could overwrite existing fields in network_profile by creating a new one. I will fix it in a following PR. |
||
| if asg_ids is not None: | ||
| agentpool.network_profile.application_security_groups = asg_ids | ||
| if allowed_host_ports is not None: | ||
| agentpool.network_profile.allowed_host_ports = allowed_host_ports | ||
|
Comment on lines
+1836
to
+1841
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this profile support partial update? For example, for an existing nodepool network profile, both
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No. If this feature is turned on, you’ve got to set both values when updating the network profile. You can change ASGs from your own to a managed one if you don’t specify ‘–asg-ids’, and also the other way round. |
||
| return agentpool | ||
|
|
||
| def update_agentpool_profile_default(self, agentpools: List[AgentPool] = None) -> AgentPool: | ||
| """The overall controller used to update AgentPool profile by default. | ||
|
|
||
|
|
@@ -1795,6 +1865,8 @@ def update_agentpool_profile_default(self, agentpools: List[AgentPool] = None) - | |
| agentpool = self.update_upgrade_settings(agentpool) | ||
| # update misc vm properties | ||
| agentpool = self.update_vm_properties(agentpool) | ||
| # update network profile | ||
| agentpool = self.update_network_profile(agentpool) | ||
| return agentpool | ||
|
|
||
| def update_agentpool(self, agentpool: AgentPool) -> AgentPool: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the input is a list, it is a better way to define the parameter with
nargs='+'and it is not necessary to manually separate the string. After defining with that, the input should be a space-separated list.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated. TIL thanks