Skip to content
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

azure_rm_aks: cluster client & models API version #497

Merged
merged 12 commits into from
Jun 30, 2021
4 changes: 2 additions & 2 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,15 +1134,15 @@ def containerservice_client(self):
@property
def managedcluster_models(self):
self.log("Getting container service models")
return ContainerServiceClient.models('2019-04-01')
return ContainerServiceClient.models('2020-04-01')

@property
def managedcluster_client(self):
self.log('Getting container service client')
if not self._managedcluster_client:
self._managedcluster_client = self.get_mgmt_svc_client(ContainerServiceClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2019-04-01')
api_version='2020-04-01')
return self._managedcluster_client

@property
Expand Down
40 changes: 35 additions & 5 deletions plugins/modules/azure_rm_aks.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@
- 'VirtualMachineScaleSets'
- 'AvailabilitySet'
type: str
mode:
description:
- AgentPoolMode represents mode of an agent pool.
- Possible values include C(System) and C(User).
- System AgentPoolMode requires a minimum VM SKU of at least 2 vCPUs and 4GB memory.
choices:
- 'System'
- 'User'
type: str
vnet_subnet_id:
description:
- Specifies the VNet's subnet identifier.
Expand Down Expand Up @@ -251,7 +260,7 @@
'''

EXAMPLES = '''
- name: Create an AKS instance
- name: Create an AKS instance With A System Node Pool & A User Node Pool
azure_rm_aks:
name: myAKS
resource_group: myResourceGroup
Expand All @@ -267,9 +276,19 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
enable_auto_scaling: True
type: VirtualMachineScaleSets
mode: System
max_count: 3
min_count: 1
enable_rbac: yes
- name: user
count: 1
vm_size: Standard_D2_v2
enable_auto_scaling: True
type: VirtualMachineScaleSets
mode: User
max_count: 3
min_count: 1
enable_rbac: yes
Expand All @@ -290,7 +309,8 @@
agent_pool_profiles:
- name: default
count: 5
vm_size: Standard_D2_v2
mode: System
vm_size: Standard_B2s
tags:
Environment: Production

Expand All @@ -312,9 +332,10 @@
name: default
os_disk_size_gb: Null
os_type: Linux
moode: System
ports: Null
storage_profile: ManagedDisks
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
vnet_subnet_id: Null
changed: false
dns_prefix: aks9860bdcd89
Expand Down Expand Up @@ -438,6 +459,7 @@ def create_agent_pool_profiles_dict(agentpoolprofiles):
availability_zones=profile.availability_zones,
os_type=profile.os_type,
type=profile.type,
mode=profile.mode,
enable_auto_scaling=profile.enable_auto_scaling,
max_count=profile.max_count,
min_count=profile.min_count,
Expand Down Expand Up @@ -494,6 +516,7 @@ def create_addon_profiles_spec():
availability_zones=dict(type='list', elements='int', choices=[1, 2, 3]),
os_type=dict(type='str', choices=['Linux', 'Windows']),
type=dict(type='str', choice=['VirtualMachineScaleSets', 'AvailabilitySet']),
mode=dict(type='str', choice=['System', 'User'], requried=True),
enable_auto_scaling=dict(type='bool'),
max_count=dict(type='int'),
min_count=dict(type='int'),
Expand Down Expand Up @@ -715,6 +738,7 @@ def compare_addon(origin, patch, config):
vm_size = profile_self['vm_size']
availability_zones = profile_self['availability_zones']
enable_auto_scaling = profile_self['enable_auto_scaling']
mode = profile_self['mode']
max_count = profile_self['max_count']
min_count = profile_self['min_count']
max_pods = profile_self['max_pods']
Expand Down Expand Up @@ -748,6 +772,9 @@ def compare_addon(origin, patch, config):
elif min_count is not None and profile_result['min_count'] != min_count:
self.log(("Agent Profile Diff - Origin {0} / Update {1}".format(str(profile_result), str(profile_self))))
to_be_updated = True
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
if not matched:
self.log("Agent Pool not found")
to_be_updated = True
Expand Down Expand Up @@ -857,12 +884,15 @@ def create_update_agentpool(self, to_update_name_list):
if (profile['name'] in to_update_name_list):
self.log("Creating / Updating the AKS agentpool {0}".format(profile['name']))
parameters = self.managedcluster_models.AgentPool(
count=profile["count"],
vm_size=profile["vm_size"],
os_disk_size_gb=profile["os_disk_size_gb"],
max_count=profile["max_count"],
min_count=profile["min_count"],
max_pods=profile["max_pods"],
enable_auto_scaling=profile["enable_auto_scaling"],
agent_pool_type=profile["type"]
agent_pool_type=profile["type"],
mode=profile["mode"]
)
try:
poller = self.managedcluster_client.agent_pools.create_or_update(self.resource_group, self.name, profile["name"], parameters)
Expand Down
121 changes: 106 additions & 15 deletions tests/integration/targets/azure_rm_aks/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
max_pods: 42
availability_zones:
- 1
Expand Down Expand Up @@ -62,8 +63,9 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
max_pods: 42
availability_zones:
- 1
Expand Down Expand Up @@ -92,18 +94,17 @@
- "fact.aks | length == 1"
- fact.aks[0].id == output.id
- fact.aks[0].properties.agentPoolProfiles[0].availabilityZones == ["1", "2"]
- fact.aks[0].properties.agentPoolProfiles[0].mode == "System"

- name: Get AKS upgrade versions
azure_rm_aksupgrade_info:
name: "aks{{ rpfx }}"
resource_group: "{{ resource_group }}"
register: upgrades

- name: Assert available versions for upgrade
- name: Assert available control-plane versions for upgrade
assert:
that:
- "upgrades.azure_aks_upgrades.agent_pool_profiles[0].kubernetes_version == versions.azure_aks_versions[0]"
- "upgrades.azure_aks_upgrades.agent_pool_profiles[0].upgrades | length > 0"
- "upgrades.azure_aks_upgrades.control_plane_profile.kubernetes_version == versions.azure_aks_versions[0]"
- "upgrades.azure_aks_upgrades.control_plane_profile.upgrades | length > 0"

Expand All @@ -122,8 +123,9 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
max_pods: 42
availability_zones:
- 1
Expand Down Expand Up @@ -160,8 +162,9 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
max_pods: 42
availability_zones:
- 1
Expand Down Expand Up @@ -199,8 +202,9 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
max_pods: 42
availability_zones:
- 1
Expand Down Expand Up @@ -234,8 +238,9 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
enable_auto_scaling: True
max_count: 6
min_count: 1
Expand Down Expand Up @@ -271,8 +276,9 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
enable_auto_scaling: True
max_count: 6
min_count: 1
Expand Down Expand Up @@ -307,8 +313,9 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
enable_auto_scaling: True
max_count: 6
min_count: 1
Expand All @@ -318,8 +325,9 @@
- 2
- name: default2
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: User
node_resource_group: "node{{ noderpfx }}"
enable_rbac: yes
network_profile:
Expand All @@ -332,8 +340,9 @@
- output.changed
- "output.agent_pool_profiles | length == 2"
- output.provisioning_state == 'Succeeded'
- output.agent_pool_profiles[1].mode == 'User'

- name: Upgrade the AKS instance with agent pool profiles (idempontent)
- name: Upgrade the AKS instance with multiple agent pool profiles (idempontent)
azure_rm_aks:
name: "aks{{ rpfx }}"
resource_group: "{{ resource_group }}"
Expand All @@ -349,7 +358,7 @@
agent_pool_profiles:
- name: default
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
enable_auto_scaling: True
max_count: 6
Expand All @@ -360,8 +369,9 @@
- 2
- name: default2
count: 1
vm_size: Standard_DS1_v2
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: User
node_resource_group: "node{{ noderpfx }}"
enable_rbac: yes
network_profile:
Expand All @@ -373,6 +383,87 @@
that:
- not output.changed

- name: Update the default2 agent_pool mode from User to System
azure_rm_aks:
name: "aks{{ rpfx }}"
resource_group: "{{ resource_group }}"
location: eastus
dns_prefix: "aks{{ rpfx }}"
kubernetes_version: "{{ version1.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
enable_auto_scaling: True
max_count: 6
min_count: 1
max_pods: 42
availability_zones:
- 1
- 2
- name: default2
count: 1
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
node_resource_group: "node{{ noderpfx }}"
enable_rbac: yes
network_profile:
load_balancer_sku: standard
register: output

- name: Assert the AKS instance is well created
assert:
that:
- output.changed
- "output.agent_pool_profiles | length == 2"
- output.provisioning_state == 'Succeeded'
- output.agent_pool_profiles[1].mode == 'System'

- name: Update the default2 agent_pool mode from User to System (idempontent)
azure_rm_aks:
name: "aks{{ rpfx }}"
resource_group: "{{ resource_group }}"
location: eastus
dns_prefix: "aks{{ rpfx }}"
kubernetes_version: "{{ version1.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
enable_auto_scaling: True
max_count: 6
min_count: 1
max_pods: 42
availability_zones:
- 1
- 2
- name: default2
count: 1
vm_size: Standard_B2s
type: VirtualMachineScaleSets
mode: System
node_resource_group: "node{{ noderpfx }}"
enable_rbac: yes
network_profile:
load_balancer_sku: standard
register: output

- name: Get AKS fact
azure_rm_aks_info:
name: "aks{{ rpfx }}"
Expand Down