From f98347178b23867407cddf8ffe5a5f151428183e Mon Sep 17 00:00:00 2001 From: Fred-sun <37327967+Fred-sun@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:05:56 +0800 Subject: [PATCH] Add agentpool module (#974) * add new module support --- node agent pool * add test case * new change * new change 02 * small change * new change * last change * new change * small change * Remove required * add new change * last chan * remove unused case * small fix --- plugins/modules/azure_rm_aksagentpool.py | 526 ++++++++++++++++++ plugins/modules/azure_rm_aksagentpool_info.py | 335 +++++++++++ .../azure_rm_aksagentpoolversion_info.py | 116 ++++ pr-pipelines.yml | 1 + .../targets/azure_rm_aksagentpool/aliases | 3 + .../azure_rm_aksagentpool/meta/main.yml | 2 + .../azure_rm_aksagentpool/tasks/main.yml | 172 ++++++ 7 files changed, 1155 insertions(+) create mode 100644 plugins/modules/azure_rm_aksagentpool.py create mode 100644 plugins/modules/azure_rm_aksagentpool_info.py create mode 100644 plugins/modules/azure_rm_aksagentpoolversion_info.py create mode 100644 tests/integration/targets/azure_rm_aksagentpool/aliases create mode 100644 tests/integration/targets/azure_rm_aksagentpool/meta/main.yml create mode 100644 tests/integration/targets/azure_rm_aksagentpool/tasks/main.yml diff --git a/plugins/modules/azure_rm_aksagentpool.py b/plugins/modules/azure_rm_aksagentpool.py new file mode 100644 index 000000000..b578826f6 --- /dev/null +++ b/plugins/modules/azure_rm_aksagentpool.py @@ -0,0 +1,526 @@ +#!/usr/bin/python +# +# Copyright (c) 2022 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun) +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = ''' +--- +module: azure_rm_aksagentpool +version_added: '1.14.0' +short_description: Manage node pools in Kubernetes kubernetes cluster +description: + - Create, update or delete node pools in kubernetes cluster. + +options: + resource_group: + description: + - The name of the resource group. + type: str + required: True + cluster_name: + description: + - The name of the kubernetes cluster. + type: str + required: True + name: + description: + - The name of the node agent pool. + type: str + required: True + count: + description: + - Number of agents (VMs) to host docker containers. + type: int + vm_size: + description: + - Size of agent VMs + type: str + os_disk_size_gb: + description: + - OS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. + type: int + vnet_subnet_id: + description: + - VNet SubnetID specifies the VNet's subnet identifier. + type: str + availability_zones: + description: + - Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType. + type: list + elements: int + choices: + - 1 + - 2 + - 3 + os_type: + description: + - OsType to be used to specify os type. + type: str + choices: + - Linux + - Windows + orchestrator_version: + description: + - Version of orchestrator specified when creating the managed cluster. + type: str + type_properties_type: + description: + - AgentPoolType represents types of an agent pool. + type: str + choices: + - VirtualMachineScaleSets + - AvailabilitySet + mode: + description: + - AgentPoolMode represents mode of an agent pool. + type: str + choices: + - System + - User + enable_auto_scaling: + description: + - Whether to enable auto-scaler. + type: bool + max_count: + description: + - Maximum number of nodes for auto-scaling. + type: int + node_labels: + description: + - Agent pool node labels to be persisted across all nodes in agent pool. + type: dict + min_count: + description: + - Minimum number of nodes for auto-scaling. + type: int + max_pods: + description: + - Maximum number of pods that can run on a node. + type: int + state: + description: + - State of the automation runbook. Use C(present) to create or update a automation runbook and use C(absent) to delete. + type: str + default: present + choices: + - present + - absent + +extends_documentation_fragment: + - azure.azcollection.azure + - azure.azcollection.azure_tags + +author: + - xuzhang3 (@xuzhang3) + - Fred Sun (@Fred-sun) + +''' + +EXAMPLES = ''' +- name: Add new node agent pool + azure_rm_aksagentpool: + resource_group: "{{ resource_group }}" + cluster_name: aksfred01 + name: default-new + count: 2 + vm_size: Standard_B2s + type_properties_type: VirtualMachineScaleSets + mode: System + node_labels: {"release":"stable"} + max_pods: 42 + orchestrator_version: 1.23.5 + availability_zones: + - 1 + - 2 +- name: Delete node agent pool + azure_rm_aksagentpool: + resource_group: "{{ resource_group }}" + cluster_name: aksfred01 + name: default-new +''' + +RETURN = ''' +aks_agent_pools: + description: + - Details for a node pool in the managed Kubernetes cluster. + returned: always + type: complex + contains: + id: + description: + - Resource ID. + type: str + returned: always + sample: "/subscriptions/xxx-xxxf/resourcegroups/myRG/providers/Microsoft.ContainerService/managedClusters/cluster/agentPools/default" + resource_group: + description: + - Resource group name. + type: str + returned: always + sample: myRG + name: + description: + - Resource name. + type: str + returned: always + sample: default + cluster_name: + description: + - The cluster name. + type: str + returned: always + sample: testcluster + availability_zones: + description: + - Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType. + type: list + returned: always + sample: [1, 2] + count: + description: + - Number of agents (VMs) to host docker containers. + type: int + returned: always + sample: 2 + enable_auto_scaling: + description: + - Whether to enable auto-scaler. + type: str + returned: always + sample: null + enable_node_public_ip: + description: + - Enable public IP for nodes. + type: str + returned: always + sample: bool + max_count: + description: + - Maximum number of nodes for auto-scaling. + type: int + returned: always + sample: 10 + min_count: + description: + - Minimum number of nodes for auto-scaling. + type: int + returned: always + sample: 1 + max_pods: + description: + - Maximum number of pods that can run on a node. + type: int + returned: always + sample: 42 + mode: + description: + - AgentPoolMode represents mode of an agent pool. + type: str + returned: always + sample: System + node_image_version: + description: + - Version of node image. + type: str + returned: always + sample: AKSUbuntu-1804gen2containerd-2022.08.23 + node_labels: + description: + - Agent pool node labels to be persisted across all nodes in agent pool. + type: list + returned: always + sample: ["release": "stable"] + node_taints: + description: + - Taints added to new nodes during node pool create and scale. + type: str + returned: always + sample: null + orchestrator_version: + description: + - Version of orchestrator specified when creating the managed cluster. + type: str + returned: always + sample: 1.22.11 + os_disk_size_gb: + description: + - OS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. + type: int + returned: always + sample: 128 + os_type: + description: + - OsType to be used to specify os type. + type: str + returned: always + sample: Linux + provisioning_state: + description: + - The current deployment or provisioning state, which only appears in the response. + type: str + returned: always + sample: Succeeded + scale_set_eviction_policy: + description: + - ScaleSetEvictionPolicy to be used to specify eviction policy for Spot virtual machine scale set. + type: str + returned: always + sample: null + scale_set_priority: + description: + - caleSetPriority to be used to specify virtual machine scale set priority. + type: str + returned: always + sample: null + spot_max_price: + description: + - SpotMaxPrice to be used to specify the maximum price you are willing to pay in US Dollars. + type: float + returned: always + sample: null + type: + description: + - Resource Type. + type: str + returned: always + sample: Microsoft.ContainerService/managedClusters/agentPools + type_properties_type: + description: + - AgentPoolType represents types of an agent pool. + type: str + returned: always + sample: VirtualMachineScaleSets + upgrade_settings: + description: + - Settings for upgrading the agentpool. + type: str + returned: always + sample: null + vm_size: + description: + - Size of agent VMs. + type: str + returned: always + sample: Standard_B2s + vnet_subnet_id: + description: + - VNet SubnetID specifies the VNet's subnet identifier. + type: str + returned: always + sample: null +''' + +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase + +try: + from azure.core.exceptions import ResourceNotFoundError + from azure.core.polling import LROPoller +except ImportError: + pass + + +class AzureRMAksAgentPool(AzureRMModuleBase): + def __init__(self): + # define user inputs into argument + self.module_arg_spec = dict( + resource_group=dict( + type='str', + required=True + ), + name=dict( + type='str', + required=True + ), + cluster_name=dict( + type='str', + required=True + ), + count=dict( + type='int', + ), + vm_size=dict( + type='str', + ), + os_disk_size_gb=dict( + type='int' + ), + vnet_subnet_id=dict( + type='str' + ), + availability_zones=dict( + type='list', + elements='int', + choices=[1, 2, 3] + ), + os_type=dict( + type='str', + choices=['Linux', 'Windows'] + ), + orchestrator_version=dict( + type='str', + ), + type_properties_type=dict( + type='str', + choices=['VirtualMachineScaleSets', 'AvailabilitySet'] + ), + mode=dict( + type='str', + choices=['System', 'User'], + ), + enable_auto_scaling=dict( + type='bool' + ), + max_count=dict( + type='int' + ), + node_labels=dict( + type='dict' + ), + min_count=dict( + type='int' + ), + max_pods=dict( + type='int' + ), + state=dict( + type='str', + choices=['present', 'absent'], + default='present' + ) + ) + # store the results of the module operation + self.results = dict() + self.resource_group = None + self.name = None + self.cluster_name = None + self.count = None + self.vm_size = None + self.mode = None + self.os_disk_size_gb = None + self.storage_profiles = None + self.vnet_subnet_id = None + self.availability_zones = None + self.os_type = None + self.orchestrator_version = None + self.type_properties_type = None + self.enable_auto_scaling = None + self.max_count = None + self.node_labels = None + self.min_count = None + self.max_pods = None + self.body = dict() + + super(AzureRMAksAgentPool, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=True) + + def exec_module(self, **kwargs): + + for key in list(self.module_arg_spec): + setattr(self, key, kwargs[key]) + if key not in ['resource_group', 'cluster_name', 'name', 'state']: + self.body[key] = kwargs[key] + + agent_pool = self.get() + changed = False + response = None + + if self.state == 'present': + if agent_pool: + for key in self.body.keys(): + if self.body[key] is not None and self.body[key] != agent_pool[key]: + changed = True + else: + self.body[key] = agent_pool[key] + else: + changed = True + + if changed: + if not self.check_mode: + response = self.create_or_update(self.body) + + else: + if not self.check_mode: + if agent_pool: + response = self.delete_agentpool() + changed = True + else: + changed = False + else: + changed = True + + self.results['changed'] = changed + self.results['aks_agent_pools'] = response + return self.results + + def get(self): + try: + response = self.managedcluster_client.agent_pools.get(self.resource_group, self.cluster_name, self.name) + return self.to_dict(response) + except ResourceNotFoundError: + pass + + def create_or_update(self, parameters): + try: + response = self.managedcluster_client.agent_pools.begin_create_or_update(self.resource_group, self.cluster_name, self.name, parameters) + if isinstance(response, LROPoller): + response = self.get_poller_result(response) + return self.to_dict(response) + except Exception as exc: + self.fail('Error when creating cluster node agent pool {0}: {1}'.format(self.name, exc)) + + def delete_agentpool(self): + try: + response = self.managedcluster_client.agent_pools.begin_delete(self.resource_group, self.cluster_name, self.name) + except Exception as exc: + self.fail('Error when deleting cluster agent pool {0}: {1}'.format(self.name, exc)) + + def to_dict(self, agent_pool): + if not agent_pool: + return None + agent_pool_dict = dict( + resource_group=self.resource_group, + cluster_name=self.cluster_name, + id=agent_pool.id, + type=agent_pool.type, + name=agent_pool.name, + count=agent_pool.count, + vm_size=agent_pool.vm_size, + os_disk_size_gb=agent_pool.os_disk_size_gb, + vnet_subnet_id=agent_pool.vnet_subnet_id, + max_pods=agent_pool.max_pods, + os_type=agent_pool.os_type, + max_count=agent_pool.max_count, + min_count=agent_pool.min_count, + enable_auto_scaling=agent_pool.enable_auto_scaling, + type_properties_type=agent_pool.type_properties_type, + mode=agent_pool.mode, + orchestrator_version=agent_pool.orchestrator_version, + node_image_version=agent_pool.node_image_version, + upgrade_settings=agent_pool.upgrade_settings, + provisioning_state=agent_pool.provisioning_state, + availability_zones=[], + enable_node_public_ip=agent_pool.enable_node_public_ip, + scale_set_priority=agent_pool.scale_set_priority, + scale_set_eviction_policy=agent_pool.scale_set_eviction_policy, + spot_max_price=agent_pool.spot_max_price, + node_labels=agent_pool.node_labels, + node_taints=agent_pool.node_taints, + ) + + if agent_pool.availability_zones is not None: + for key in agent_pool.availability_zones: + agent_pool_dict['availability_zones'].append(int(key)) + + return agent_pool_dict + + +def main(): + AzureRMAksAgentPool() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/azure_rm_aksagentpool_info.py b/plugins/modules/azure_rm_aksagentpool_info.py new file mode 100644 index 000000000..756dd3733 --- /dev/null +++ b/plugins/modules/azure_rm_aksagentpool_info.py @@ -0,0 +1,335 @@ +#!/usr/bin/python +# +# Copyright (c) 2022 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun) +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = ''' +--- +module: azure_rm_aksagentpool_info +version_added: '1.14.0' +short_description: Show the details for a node pool in the managed Kubernetes cluster +description: + - Get the details for a node pool in the managed Kubernetes cluster + +options: + resource_group: + description: + - The name of the resource group. + type: str + required: True + cluster_name: + description: + - The cluster name. + type: str + required: True + name: + description: + - The node pool name. + type: str + +extends_documentation_fragment: + - azure.azcollection.azure + +author: + - xuzhang3 (@xuzhang3) + - Fred Sun (@Fred-sun) +''' + +EXAMPLES = ''' + - name: Get node agent pool by cluster name + azure_rm_aksagentpool_info: + resource_group: myRG + cluster_name: testcluster + + - name: Get node agent pool by name + azure_rm_aksagentpool_info: + resource_group: myRG + cluster_name: testcluster + name: default + +''' + +RETURN = ''' +aks_agent_pools: + description: + - Details for a node pool in the managed Kubernetes cluster. + returned: always + type: complex + contains: + id: + description: + - Resource ID. + type: str + returned: always + sample: "/subscriptions/xxx-xxxf/resourcegroups/myRG/providers/Microsoft.ContainerService/managedClusters/cluster/agentPools/default" + resource_group: + description: + - Resource group name. + type: str + returned: always + sample: myRG + name: + description: + - Resource name. + type: str + returned: always + sample: default + cluster_name: + description: + - The cluster name. + type: str + returned: always + sample: testcluster + availability_zones: + description: + - Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType. + type: list + returned: always + sample: [1, 2] + count: + description: + - Number of agents (VMs) to host docker containers. + type: int + returned: always + sample: 2 + enable_auto_scaling: + description: + - Whether to enable auto-scaler. + type: bool + returned: always + sample: null + enable_node_public_ip: + description: + - Enable public IP for nodes. + type: bool + returned: always + sample: True + max_count: + description: + - Maximum number of nodes for auto-scaling. + type: int + returned: always + sample: 10 + min_count: + description: + - Minimum number of nodes for auto-scaling. + type: int + returned: always + sample: 1 + max_pods: + description: + - Maximum number of pods that can run on a node. + type: int + returned: always + sample: 42 + mode: + description: + - AgentPoolMode represents mode of an agent pool. + type: str + returned: always + sample: System + node_image_version: + description: + - Version of node image. + type: str + returned: always + sample: AKSUbuntu-1804gen2containerd-2022.08.23 + node_labels: + description: + - Agent pool node labels to be persisted across all nodes in agent pool. + type: list + returned: always + sample: ["release":"stable"] + node_taints: + description: + - Taints added to new nodes during node pool create and scale. + type: str + returned: always + sample: null + orchestrator_version: + description: + - Version of orchestrator specified when creating the managed cluster. + type: str + returned: always + sample: 1.22.11 + os_disk_size_gb: + description: + - OS Disk Size in GB to be used to specify the disk size for every machine in this master agent pool. + type: int + returned: always + sample: 128 + os_type: + description: + - OsType to be used to specify os type. + type: str + returned: always + sample: Linux + provisioning_state: + description: + - The current deployment or provisioning state, which only appears in the response. + type: str + returned: always + sample: Succeeded + scale_set_eviction_policy: + description: + - ScaleSetEvictionPolicy to be used to specify eviction policy for Spot virtual machine scale set. + type: str + returned: always + sample: null + scale_set_priority: + description: + - caleSetPriority to be used to specify virtual machine scale set priority. + type: str + returned: always + sample: null + spot_max_price: + description: + - SpotMaxPrice to be used to specify the maximum price you are willing to pay in US Dollars. + type: float + returned: always + sample: null + type: + description: + - Resource Type. + type: str + returned: always + sample: Microsoft.ContainerService/managedClusters/agentPools + type_properties_type: + description: + - AgentPoolType represents types of an agent pool. + type: str + returned: always + sample: VirtualMachineScaleSets + upgrade_settings: + description: + - Settings for upgrading the agentpool. + type: str + returned: always + sample: null + vm_size: + description: + - Size of agent VMs. + type: str + returned: always + sample: Standard_B2s + vnet_subnet_id: + description: + - VNet SubnetID specifies the VNet's subnet identifier. + type: str + returned: always + sample: null +''' + +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase + +try: + from azure.core.exceptions import ResourceNotFoundError +except ImportError: + pass + + +class AzureRMAgentPoolInfo(AzureRMModuleBase): + def __init__(self): + # define user inputs into argument + self.module_arg_spec = dict( + resource_group=dict( + type='str', + required=True + ), + name=dict( + type='str' + ), + cluster_name=dict( + type='str', + required=True + ) + ) + # store the results of the module operation + self.results = dict() + self.resource_group = None + self.name = None + self.cluster_name = None + + super(AzureRMAgentPoolInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True) + + def exec_module(self, **kwargs): + + for key in list(self.module_arg_spec): + setattr(self, key, kwargs[key]) + + if self.name: + aks_agent_pools = [self.get_agentpool()] + else: + aks_agent_pools = self.list_agentpool() + self.results['aks_agent_pools'] = [self.to_dict(x) for x in aks_agent_pools] + return self.results + + def get_agentpool(self): + try: + return self.managedcluster_client.agent_pools.get(self.resource_group, self.cluster_name, self.name) + except ResourceNotFoundError: + pass + + def list_agentpool(self): + result = [] + try: + resp = self.managedcluster_client.agent_pools.list(self.resource_group, self.cluster_name) + while True: + result.append(resp.next()) + except StopIteration: + pass + except Exception: + pass + return result + + def to_dict(self, agent_pool): + if not agent_pool: + return None + agent_pool_dict = dict( + resource_group=self.resource_group, + cluster_name=self.cluster_name, + id=agent_pool.id, + type=agent_pool.type, + name=agent_pool.name, + count=agent_pool.count, + vm_size=agent_pool.vm_size, + os_disk_size_gb=agent_pool.os_disk_size_gb, + vnet_subnet_id=agent_pool.vnet_subnet_id, + max_pods=agent_pool.max_pods, + os_type=agent_pool.os_type, + max_count=agent_pool.max_count, + min_count=agent_pool.min_count, + enable_auto_scaling=agent_pool.enable_auto_scaling, + type_properties_type=agent_pool.type_properties_type, + mode=agent_pool.mode, + availability_zones=[], + orchestrator_version=agent_pool.orchestrator_version, + node_image_version=agent_pool.node_image_version, + upgrade_settings=agent_pool.upgrade_settings, + provisioning_state=agent_pool.provisioning_state, + enable_node_public_ip=agent_pool.enable_node_public_ip, + scale_set_priority=agent_pool.scale_set_priority, + scale_set_eviction_policy=agent_pool.scale_set_eviction_policy, + spot_max_price=agent_pool.spot_max_price, + node_labels=agent_pool.node_labels, + node_taints=agent_pool.node_taints, + ) + + if agent_pool.availability_zones is not None: + for key in agent_pool.availability_zones: + agent_pool_dict['availability_zones'].append(int(key)) + + return agent_pool_dict + + +def main(): + AzureRMAgentPoolInfo() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/azure_rm_aksagentpoolversion_info.py b/plugins/modules/azure_rm_aksagentpoolversion_info.py new file mode 100644 index 000000000..33cf24317 --- /dev/null +++ b/plugins/modules/azure_rm_aksagentpoolversion_info.py @@ -0,0 +1,116 @@ +#!/usr/bin/python +# +# Copyright (c) 2022 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun) +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = ''' +--- +module: azure_rm_aksagentpoolversion_info + +version_added: "1.14.0" + +short_description: Gets a list of supported versions for the specified agent pool + +description: + - Gets a list of supported versions for the specified agent pool. + +options: + resource_group: + description: + - The name of the resource group. + required: true + type: str + cluster_name: + description: + - The name of the managed cluster resource. + required: true + type: str + +extends_documentation_fragment: + - azure.azcollection.azure + +author: + - xuzhang3 (@xuzhang3) + - Fred-sun (@Fred-sun) +''' + +EXAMPLES = ''' + - name: Get available versions an AKS can be upgrade to + azure_rm_aksagentpoolversion_info: + resource_group: myResourceGroup + cluster_name: myAKSName +''' + +RETURN = ''' +azure_orchestrator_version: + description: + - List of supported kubernetes versions. + returned: always + type: list + sample: ['1.22.6', '1.22.11'] +''' + +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase + + +class AzureRMAksAgentPoolVersion(AzureRMModuleBase): + + def __init__(self): + + self.module_args = dict( + resource_group=dict(type='str', required=True), + cluster_name=dict(type='str', required=True), + ) + + self.results = dict( + changed=False, + azure_orchestrator_version=[] + ) + + self.resource_group = None + self.cluster_name = None + + super(AzureRMAksAgentPoolVersion, self).__init__( + derived_arg_spec=self.module_args, + supports_check_mode=True, + supports_tags=False, + facts_module=True + ) + + def exec_module(self, **kwargs): + + for key in self.module_args: + setattr(self, key, kwargs[key]) + + self.results['azure_orchestrator_version'] = self.get_all_versions() + + return self.results + + def get_all_versions(self): + ''' + Get all avaliable orchestrator version + ''' + try: + result = list() + response = self.managedcluster_client.agent_pools.get_available_agent_pool_versions(self.resource_group, self.cluster_name) + orchestrators = response.agent_pool_versions + for item in orchestrators: + result.append(item.kubernetes_version) + return result + except Exception as exc: + self.fail('Error when getting Agentpool supported orchestrator version list for locatio', exc) + + +def main(): + """Main module execution code path""" + + AzureRMAksAgentPoolVersion() + + +if __name__ == '__main__': + main() diff --git a/pr-pipelines.yml b/pr-pipelines.yml index 703fff280..a754f5a62 100644 --- a/pr-pipelines.yml +++ b/pr-pipelines.yml @@ -31,6 +31,7 @@ parameters: - "azure_rm_adgroup" - "azure_rm_aduser" - "azure_rm_aks" + - "azure_rm_aksagentpool" - "azure_rm_apimanagement" - "azure_rm_appgateway" - "azure_rm_appserviceplan" diff --git a/tests/integration/targets/azure_rm_aksagentpool/aliases b/tests/integration/targets/azure_rm_aksagentpool/aliases new file mode 100644 index 000000000..7aca0ce4f --- /dev/null +++ b/tests/integration/targets/azure_rm_aksagentpool/aliases @@ -0,0 +1,3 @@ +cloud/azure +destructive +shippable/azure/group11 diff --git a/tests/integration/targets/azure_rm_aksagentpool/meta/main.yml b/tests/integration/targets/azure_rm_aksagentpool/meta/main.yml new file mode 100644 index 000000000..95e1952f9 --- /dev/null +++ b/tests/integration/targets/azure_rm_aksagentpool/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_azure diff --git a/tests/integration/targets/azure_rm_aksagentpool/tasks/main.yml b/tests/integration/targets/azure_rm_aksagentpool/tasks/main.yml new file mode 100644 index 000000000..d6434d024 --- /dev/null +++ b/tests/integration/targets/azure_rm_aksagentpool/tasks/main.yml @@ -0,0 +1,172 @@ +- set_fact: + rpfx: "{{ resource_group | hash('md5') | truncate(8, True, '') }}" + +- name: Find available k8s version + azure_rm_aksversion_info: + location: eastus + register: versions + +- name: Create a kubernet service with minimal parameters + azure_rm_aks: + name: "min{{ rpfx }}" + location: eastus + resource_group: "{{ resource_group }}" + kubernetes_version: "{{ versions.azure_aks_versions[0] }}" + dns_prefix: "aks{{ rpfx }}" + enable_rbac: true + aad_profile: + managed: true + agent_pool_profiles: + - name: default + count: 1 + vm_size: Standard_B2s + mode: System + api_server_access_profile: + authorized_ip_ranges: + - "192.0.2.0" + - "198.51.100.0" + - "203.0.113.0" + enable_private_cluster: no + network_profile: + load_balancer_sku: standard + outbound_type: loadBalancer + register: output + +- name: Get cluster's node agent pool info + azure_rm_aksagentpool_info: + resource_group: "{{ resource_group }}" + cluster_name: "min{{ rpfx }}" + register: output + +- name: Assert the cluster with one agent pool + assert: + that: + - "output.aks_agent_pools | length == 1" + +- name: Get aks agent pool support version + azure_rm_aksagentpoolversion_info: + resource_group: "{{ resource_group }}" + cluster_name: "min{{ rpfx }}" + register: agentpool_version + +- name: Assert the orchestrator version is not None + assert: + that: + - "agentpool_version.azure_orchestrator_version | length >= 1" + +- name: Add agent pool + azure_rm_aksagentpool: + resource_group: "{{ resource_group }}" + cluster_name: "min{{ rpfx }}" + name: default03 + count: 1 + vm_size: Standard_B2s + type_properties_type: VirtualMachineScaleSets + mode: System + node_labels: {"release":"stable"} + max_pods: 42 + enable_auto_scaling: True + min_count: 1 + max_count: 10 + orchestrator_version: "1.22.6" + availability_zones: + - 1 + - 2 + register: output + +- name: Assert the node agent pool created + assert: + that: + - output.changed + +- name: Add agent pool (Idempotent test) + azure_rm_aksagentpool: + resource_group: "{{ resource_group }}" + cluster_name: "min{{ rpfx }}" + name: default03 + count: 1 + vm_size: Standard_B2s + type_properties_type: VirtualMachineScaleSets + mode: System + node_labels: {"release":"stable"} + max_pods: 42 + enable_auto_scaling: True + min_count: 1 + max_count: 10 + orchestrator_version: "1.22.6" + availability_zones: + - 1 + - 2 + register: output + +- name: Assert the node agent pool not changed + assert: + that: + - not output.changed + +- name: Get cluster's node agent pool info + azure_rm_aksagentpool_info: + resource_group: "{{ resource_group }}" + cluster_name: "min{{ rpfx }}" + register: output + +- name: Assert node agent pool + assert: + that: + - "output.aks_agent_pools | length == 2" + +- name: Upgrade node agent pool + azure_rm_aksagentpool: + resource_group: "{{ resource_group }}" + cluster_name: "min{{ rpfx }}" + name: default03 + count: 1 + vm_size: Standard_B2s + type_properties_type: VirtualMachineScaleSets + mode: System + node_labels: {"release":"stable"} + max_pods: 42 + enable_auto_scaling: True + min_count: 1 + max_count: 10 + orchestrator_version: "1.22.11" + availability_zones: + - 1 + - 2 + register: output + +- name: Assert the node agent pool udpated + assert: + that: + - output.changed + +- name: Get cluster's node agent pool info + azure_rm_aksagentpool_info: + resource_group: "{{ resource_group }}" + cluster_name: "min{{ rpfx }}" + name: default03 + register: output + +- name: Assert node agent configuration + assert: + that: + - output.aks_agent_pools[0].availability_zones == [1, 2] + - output.aks_agent_pools[0].count == 1 + - output.aks_agent_pools[0].min_count == 1 + - output.aks_agent_pools[0].max_count == 10 + - output.aks_agent_pools[0].type_properties_type == "VirtualMachineScaleSets" + - output.aks_agent_pools[0].max_pods == 42 + - output.aks_agent_pools[0].orchestrator_version == "1.22.11" + +- name: Delete node agent pool + azure_rm_aksagentpool: + resource_group: "{{ resource_group }}" + cluster_name: "min{{ rpfx }}" + name: default03 + state: absent + register: output + +- name: Assert the node agent pool has deleted + assert: + that: + - output.changed