diff --git a/plugins/modules/azure_rm_aks.py b/plugins/modules/azure_rm_aks.py index 1b4971a11..8f8e0433c 100644 --- a/plugins/modules/azure_rm_aks.py +++ b/plugins/modules/azure_rm_aks.py @@ -108,6 +108,10 @@ - 'System' - 'User' type: str + node_labels: + description: + - Agent pool node labels to be persisted across all nodes in agent pool. + type: dict vnet_subnet_id: description: - Specifies the VNet's subnet identifier. @@ -333,6 +337,7 @@ os_disk_size_gb: Null os_type: Linux moode: System + node_labels: { "environment": "dev", "release": "stable" } ports: Null storage_profile: ManagedDisks vm_size: Standard_B2s @@ -462,6 +467,7 @@ def create_agent_pool_profiles_dict(agentpoolprofiles): mode=profile.mode, enable_auto_scaling=profile.enable_auto_scaling, max_count=profile.max_count, + node_labels=profile.node_labels, min_count=profile.min_count, max_pods=profile.max_pods ) for profile in agentpoolprofiles] if agentpoolprofiles else None @@ -519,6 +525,7 @@ def create_addon_profiles_spec(): mode=dict(type='str', choice=['System', 'User'], requried=True), 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') ) @@ -740,6 +747,7 @@ def compare_addon(origin, patch, config): enable_auto_scaling = profile_self['enable_auto_scaling'] mode = profile_self['mode'] max_count = profile_self['max_count'] + node_labels = profile_self['node_labels'] min_count = profile_self['min_count'] max_pods = profile_self['max_pods'] @@ -775,6 +783,9 @@ def compare_addon(origin, patch, config): elif mode is not None and profile_result['mode'] != mode: self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) to_be_updated = True + elif node_labels is not None and profile_result['node_labels'] != node_labels: + self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self)))) + to_be_updated = True if not matched: self.log("Agent Pool not found") to_be_updated = True @@ -888,6 +899,7 @@ def create_update_agentpool(self, to_update_name_list): vm_size=profile["vm_size"], os_disk_size_gb=profile["os_disk_size_gb"], max_count=profile["max_count"], + node_labels=profile["node_labels"], min_count=profile["min_count"], max_pods=profile["max_pods"], enable_auto_scaling=profile["enable_auto_scaling"], diff --git a/tests/integration/targets/azure_rm_aks/tasks/main.yml b/tests/integration/targets/azure_rm_aks/tasks/main.yml index ff28f50cf..29becfa17 100644 --- a/tests/integration/targets/azure_rm_aks/tasks/main.yml +++ b/tests/integration/targets/azure_rm_aks/tasks/main.yml @@ -26,6 +26,7 @@ vm_size: Standard_B2s type: VirtualMachineScaleSets mode: System + node_labels: {"release":"stable"} max_pods: 42 availability_zones: - 1 @@ -66,6 +67,7 @@ vm_size: Standard_B2s type: VirtualMachineScaleSets mode: System + node_labels: {"release":"stable"} max_pods: 42 availability_zones: - 1 @@ -95,6 +97,55 @@ - fact.aks[0].id == output.id - fact.aks[0].properties.agentPoolProfiles[0].availabilityZones == ["1", "2"] - fact.aks[0].properties.agentPoolProfiles[0].mode == "System" + - fact.aks[0].properties.agentPoolProfiles[0].nodeLabels | length == 1 + + - name: Update an AKS instance node_labels + azure_rm_aks: + name: "aks{{ rpfx }}" + resource_group: "{{ resource_group }}" + location: eastus + dns_prefix: "aks{{ rpfx }}" + kubernetes_version: "{{ versions.azure_aks_versions[0] }}" + service_principal: + client_id: "{{ azure_client_id }}" + client_secret: "{{ azure_secret }}" + linux_profile: + admin_username: azureuser + ssh_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSPmiqkvDH1/+MDAVDZT8381aYqp73Odz8cnD5hegNhqtXajqtiH0umVg7HybX3wt1HjcrwKJovZURcIbbcDvzdH2bnYbF93T4OLXA0bIfuIp6M86x1iutFtXdpN3TTicINrmSXEE2Ydm51iMu77B08ZERjVaToya2F7vC+egfoPvibf7OLxE336a5tPCywavvNihQjL8sjgpDT5AAScjb3YqK/6VLeQ18Ggt8/ufINsYkb+9/Ji/3OcGFeflnDXq80vPUyF3u4iIylob6RSZenC38cXmQB05tRNxS1B6BXCjMRdy0v4pa7oKM2GA4ADKpNrr0RI9ed+peRFwmsclH test@ansible + agent_pool_profiles: + - name: default + count: 1 + vm_size: Standard_B2s + type: VirtualMachineScaleSets + mode: System + node_labels: {"release":"stable", "environment":"dev"} + max_pods: 42 + availability_zones: + - 1 + - 2 + node_resource_group: "node{{ noderpfx }}" + enable_rbac: yes + network_profile: + load_balancer_sku: standard + register: output + + - name: Assert the AKS instance is well update + assert: + that: + - output.changed + + - name: Get AKS fact + azure_rm_aks_info: + name: "aks{{ rpfx }}" + resource_group: "{{ resource_group }}" + register: fact + + - name: Assert fact returns the created one + assert: + that: + - "fact.aks | length == 1" + - fact.aks[0].id == output.id + - fact.aks[0].properties.agentPoolProfiles[0].nodeLabels | length == 2 - name: Get AKS upgrade versions azure_rm_aksupgrade_info: