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
12 changes: 11 additions & 1 deletion src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@ To release a new version, please select a new version number (usually plus 1 to

Pending
++++++
* Vendor new SDK and bump API version to 2023-05-02-preview.

0.5.145
+++++++
* Add support for option --aks-custom-headers to some aks commands
* aks get-credentials
* aks nodepool scale
* aks nodepool update
* aks enable-addons
* aks show
* aks scale

0.5.144
+++++++
* Fix setup network profile with network observability due to incorrect property

0.5.143
+++++++
* Vendor new SDK and bump API version to 2023-05-02-preview.
* Add `--enable-network-observability` flag to `az aks create` and `az aks update`.

0.5.142
Expand Down
29 changes: 29 additions & 0 deletions src/aks-preview/azext_aks_preview/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ def version_to_tuple(version):
return tuple(map(int, (version.split('.'))))


# helper function used by aks get-versions, should be removed once dependency bumped to 2.50.0
def flatten_version_table(release_info):
"""Flattens version table"""
flattened = []
for release in release_info:
isPreview = release.get("isPreview", False)
for k, v in release.get("patchVersions", {}).items():
item = {"version": k, "upgrades": v.get("upgrades", []), "isPreview": isPreview}
flattened.append(item)
return flattened


def _custom_functions(preview_versions):
class CustomFunctions(functions.Functions): # pylint: disable=too-few-public-methods

Expand Down Expand Up @@ -217,6 +229,23 @@ def aks_pod_identities_table_format(result):
return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))


# helper function used by aks get-versions, should be removed once dependency bumped to 2.50.0
def aks_versions_table_format(result):
"""Format get-versions results as a summary for display with "-o table"."""

version_table = flatten_version_table(result.get("values", []))

parsed = compile_jmes("""[].{
kubernetesVersion: version,
isPreview: isPreview,
upgrades: upgrades || [`None available`] | sort_versions(@) | join(`, `, @)
}""")
# use ordered dicts so headers are predictable
results = parsed.search(version_table, Options(
dict_cls=OrderedDict, custom_functions=_custom_functions({})))
return sorted(results, key=lambda x: version_to_tuple(x.get("kubernetesVersion")), reverse=True)


def aks_list_nodepool_snapshot_table_format(results):
""""Format a list of nodepool snapshots as summary results for display with "-o table"."""
return [_aks_nodepool_snapshot_table_format(r) for r in results]
Expand Down
25 changes: 25 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@
- name: --node-count -c
type: int
short-summary: Number of nodes in the Kubernetes node pool.
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
"""

helps['aks upgrade'] = """
Expand Down Expand Up @@ -1620,6 +1623,9 @@
- name: --node-count -c
type: int
short-summary: Number of nodes in the Kubernetes node pool.
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
"""

helps['aks nodepool upgrade'] = """
Expand Down Expand Up @@ -2023,6 +2029,9 @@
- name: --dns-zone-resource-id
type: string
short-summary: The resource ID of the DNS zone resource to use with the web_application_routing addon.
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
examples:
- name: Enable Kubernetes addons. (autogenerated)
text: az aks enable-addons --addons virtual-node --name MyManagedCluster --resource-group MyResourceGroup --subnet-name VirtualNodeSubnet
Expand All @@ -2035,6 +2044,19 @@
crafted: true
"""

helps['aks show'] = """
type: command
short-summary: Show the details for a managed Kubernetes cluster.
parameters:
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
examples:
- name: Show the details for a managed Kubernetes cluster
text: az aks show -g MyResourceGroup -n MyManagedCluster
crafted: true
"""

helps['aks get-versions'] = """
type: command
short-summary: Get the versions available for creating a managed Kubernetes cluster.
Expand Down Expand Up @@ -2079,6 +2101,9 @@
type: string
short-summary: Specify the format of the returned credential. Available values are ["exec", "azure"].
Only take effect when requesting clusterUser credential of AAD clusters.
- name: --aks-custom-headers
type: string
short-summary: Send custom headers. When specified, format should be Key1=Value1,Key2=Value2
examples:
- name: Get access credentials for a managed Kubernetes cluster. (autogenerated)
text: az aks get-credentials --name MyManagedCluster --resource-group MyResourceGroup
Expand Down
2 changes: 2 additions & 0 deletions src/aks-preview/azext_aks_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
aks_show_snapshot_table_format,
aks_show_table_format,
aks_upgrades_table_format,
aks_versions_table_format,
)
from knack.log import get_logger

Expand Down Expand Up @@ -138,6 +139,7 @@ def load_command_table(self, _):
g.command('stop', 'begin_stop', supports_no_wait=True)
g.command('start', 'begin_start', supports_no_wait=True)
g.wait_command('wait')
g.custom_command('get-versions', 'aks_get_versions', table_transformer=aks_versions_table_format)
# aks-preview only
g.custom_command('kollect', 'aks_kollect')
g.custom_command('kanalyze', 'aks_kanalyze')
Expand Down
33 changes: 20 additions & 13 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,9 @@ def aks_update(


# pylint: disable=unused-argument
def aks_show(cmd, client, resource_group_name, name):
mc = client.get(resource_group_name, name)
def aks_show(cmd, client, resource_group_name, name, aks_custom_headers=None):
headers = get_aks_custom_headers(aks_custom_headers)
mc = client.get(resource_group_name, name, headers=headers)
return _remove_nulls([mc])[0]


Expand Down Expand Up @@ -825,7 +826,9 @@ def aks_get_credentials(
context_name=None,
public_fqdn=False,
credential_format=None,
aks_custom_headers=None,
):
headers = get_aks_custom_headers(aks_custom_headers)
credentialResults = None
serverType = None
if public_fqdn:
Expand All @@ -836,14 +839,14 @@ def aks_get_credentials(
raise InvalidArgumentValueError("--format can only be specified when requesting clusterUser credential.")
if admin:
credentialResults = client.list_cluster_admin_credentials(
resource_group_name, name, serverType)
resource_group_name, name, serverType, headers=headers)
else:
if user.lower() == 'clusteruser':
credentialResults = client.list_cluster_user_credentials(
resource_group_name, name, serverType, credential_format)
resource_group_name, name, serverType, credential_format, headers=headers)
elif user.lower() == 'clustermonitoringuser':
credentialResults = client.list_cluster_monitoring_user_credentials(
resource_group_name, name, serverType)
resource_group_name, name, serverType, headers=headers)
else:
raise InvalidArgumentValueError("The value of option --user is invalid.")

Expand Down Expand Up @@ -876,7 +879,9 @@ def aks_scale(cmd, # pylint: disable=unused-argument
name,
node_count,
nodepool_name="",
no_wait=False):
no_wait=False,
aks_custom_headers=None):
headers = get_aks_custom_headers(aks_custom_headers)
instance = client.get(resource_group_name, name)
_fill_defaults_for_pod_identity_profile(instance.pod_identity_profile)

Expand All @@ -893,7 +898,7 @@ def aks_scale(cmd, # pylint: disable=unused-argument
agent_profile.count = int(node_count) # pylint: disable=no-member
# null out the SP profile because otherwise validation complains
instance.service_principal_profile = None
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, name, instance)
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, name, instance, headers=headers)
raise CLIError('The nodepool "{}" was not found.'.format(nodepool_name))


Expand Down Expand Up @@ -1157,7 +1162,9 @@ def aks_agentpool_scale(cmd, # pylint: disable=unused-argument
cluster_name,
nodepool_name,
node_count=3,
no_wait=False):
no_wait=False,
aks_custom_headers=None):
headers = get_aks_custom_headers(aks_custom_headers)
instance = client.get(resource_group_name, cluster_name, nodepool_name)
new_node_count = int(node_count)
if instance.enable_auto_scaling:
Expand All @@ -1166,7 +1173,7 @@ def aks_agentpool_scale(cmd, # pylint: disable=unused-argument
raise CLIError(
"The new node count is the same as the current node count.")
instance.count = new_node_count # pylint: disable=no-member
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, cluster_name, nodepool_name, instance)
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name, cluster_name, nodepool_name, instance, headers=headers)


def aks_agentpool_upgrade(cmd,
Expand Down Expand Up @@ -1576,8 +1583,8 @@ def aks_disable_addons(cmd, client, resource_group_name, name, addons, no_wait=F
def aks_enable_addons(cmd, client, resource_group_name, name, addons, workspace_resource_id=None,
subnet_name=None, appgw_name=None, appgw_subnet_prefix=None, appgw_subnet_cidr=None, appgw_id=None, appgw_subnet_id=None,
appgw_watch_namespace=None, enable_sgxquotehelper=False, enable_secret_rotation=False, rotation_poll_interval=None, no_wait=False, enable_msi_auth_for_monitoring=True,
dns_zone_resource_id=None, enable_syslog=False, data_collection_settings=None):

dns_zone_resource_id=None, enable_syslog=False, data_collection_settings=None, aks_custom_headers=None):
headers = get_aks_custom_headers(aks_custom_headers)
instance = client.get(resource_group_name, name)
# this is overwritten by _update_addons(), so the value needs to be recorded here
msi_auth = False
Expand Down Expand Up @@ -1661,7 +1668,7 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons, workspace_

else:
result = sdk_no_wait(no_wait, client.begin_create_or_update,
resource_group_name, name, instance)
resource_group_name, name, instance, headers=headers)
return result


Expand Down Expand Up @@ -1856,7 +1863,7 @@ def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements


def aks_get_versions(cmd, client, location): # pylint: disable=unused-argument
return client.list_orchestrators(location, resource_type='managedClusters')
return client.list_kubernetes_versions(location)


def aks_get_os_options(cmd, client, location): # pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
- AZURECLI/2.49.0 azsdk-python-azure-mgmt-containerservice/23.0.0 Python/3.8.10
(Linux-5.15.0-1039-azure-x86_64-with-glibc2.29)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/westcentralus/kubernetesVersions?api-version=2023-04-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/westcentralus/kubernetesVersions?api-version=2023-05-02-preview
response:
body:
string: "{\n \"values\": [\n {\n \"version\": \"1.27\",\n \"capabilities\":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
- AZURECLI/2.49.0 azsdk-python-azure-mgmt-containerservice/23.0.0 Python/3.8.10
(Linux-5.15.0-1039-azure-x86_64-with-glibc2.29)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/centraluseuap/kubernetesVersions?api-version=2023-04-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/centraluseuap/kubernetesVersions?api-version=2023-05-02-preview
response:
body:
string: "{\n \"values\": [\n {\n \"version\": \"1.24\",\n \"capabilities\":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
- AZURECLI/2.49.0 azsdk-python-azure-mgmt-containerservice/23.0.0 Python/3.8.10
(Linux-5.15.0-1039-azure-x86_64-with-glibc2.29)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/westus2/kubernetesVersions?api-version=2023-04-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/westus2/kubernetesVersions?api-version=2023-05-02-preview
response:
body:
string: "{\n \"values\": [\n {\n \"version\": \"1.27\",\n \"capabilities\":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
- AZURECLI/2.49.0 azsdk-python-azure-mgmt-containerservice/23.0.0 Python/3.8.10
(Linux-5.15.0-1039-azure-x86_64-with-glibc2.29)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/westus2/kubernetesVersions?api-version=2023-04-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/westus2/kubernetesVersions?api-version=2023-05-02-preview
response:
body:
string: "{\n \"values\": [\n {\n \"version\": \"1.25\",\n \"capabilities\":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
- AZURECLI/2.49.0 azsdk-python-azure-mgmt-containerservice/23.0.0 Python/3.8.10
(Linux-5.15.0-1039-azure-x86_64-with-glibc2.29)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/centraluseuap/kubernetesVersions?api-version=2023-04-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/centraluseuap/kubernetesVersions?api-version=2023-05-02-preview
response:
body:
string: "{\n \"values\": [\n {\n \"version\": \"1.27\",\n \"capabilities\":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
- AZURECLI/2.49.0 azsdk-python-azure-mgmt-containerservice/23.0.0 Python/3.8.10
(Linux-5.15.0-1039-azure-x86_64-with-glibc2.29)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/centraluseuap/kubernetesVersions?api-version=2023-04-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ContainerService/locations/centraluseuap/kubernetesVersions?api-version=2023-05-02-preview
response:
body:
string: "{\n \"values\": [\n {\n \"version\": \"1.27\",\n \"capabilities\":
Expand Down
Loading