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

[Azurestack][ACR][AKS] add azurestack hybrid profile for AKS #18118

Merged
merged 31 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
78e954c
Adding ACR and AKS for azurestack hybrid profile
May 18, 2021
65fd82a
Change managed cluster SDK profile for acs
May 19, 2021
e31c68f
Container service resource type to managed cluster sdk
May 21, 2021
c1d3fdc
Removing hardcoded api-version to import models
May 21, 2021
7fcc7fc
Removing versioned models import
May 27, 2021
19ac1f2
Removing versioned models import
May 28, 2021
ae844d4
Fixing style and models
May 28, 2021
f76fc0c
Changing Azure stack API version for container service
May 28, 2021
bba1cd3
Adding operation-group to container service
Jun 1, 2021
d96d92e
Changing container service test_validator
Jun 1, 2021
0b0cde5
Changing container service test_validator
Jun 1, 2021
dde88da
Modifying operation_group to managed_clusters
Jun 2, 2021
55d8260
Adding managed_clusters operation group to aks run command
Jun 2, 2021
c551f3b
Container service test code changes
Jun 2, 2021
aa50108
Revert "Container service test code changes"
Jun 2, 2021
124fcd4
Adding mock cmd to acs test
Jun 3, 2021
20a60f0
Fix resource tyope in acs test
Jun 3, 2021
4c206ea
Fix resource tyope in acs test
Jun 3, 2021
98bd825
Removing resource type in mock cmd
Jun 3, 2021
990dcf0
Changing acs get_models
Jun 4, 2021
a648103
Adding operation group to get_models
Jun 4, 2021
e01899e
Adding magicmock to acs test
Jun 5, 2021
0f152fc
Ading magicmock to acs test
Jun 5, 2021
c0ac58d
Modifying mock cmd
Jun 5, 2021
f1b643f
Modifying acs mock cmd
Jun 5, 2021
e8eb6a0
Adding operation_group to acs mock
Jun 5, 2021
fed1fc1
Adding mod=models for acs mock cmd
Jun 5, 2021
9195f70
Adding aks acr hybrid profiles
Jun 12, 2021
bc7c74a
removing redundant operation_group properties
Jun 15, 2021
668ad41
Adding operation_group to acs loadbalancer
Jun 15, 2021
8a63a8e
merging dev
Jun 21, 2021
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
15 changes: 12 additions & 3 deletions src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class ResourceType(Enum): # pylint: disable=too-few-public-methods
MGMT_ARO = ('azure.mgmt.redhatopenshift', 'AzureRedHatOpenShiftClient')
MGMT_DATABOXEDGE = ('azure.mgmt.databoxedge', 'DataBoxEdgeManagementClient')
MGMT_CUSTOMLOCATION = ('azure.mgmt.extendedlocation', 'CustomLocations')
MGMT_CONTAINERSERVICE = ('azure.mgmt.containerservice', 'ContainerServiceClient')
# the "None" below will stay till a command module fills in the type so "get_mgmt_service_client"
# can be provided with "ResourceType.XXX" to initialize the client object. This usually happens
# when related commands start to support Multi-API

DATA_COSMOS_TABLE = ('azure.multiapi.cosmosdb', None)
MGMT_CONTAINERSERVICE = ('azure.mgmt.containerservice', None)
MGMT_ADVISOR = ('azure.mgmt.advisor', None)
MGMT_MEDIA = ('azure.mgmt.media', None)
MGMT_BACKUP = ('azure.mgmt.recoveryservicesbackup', None)
Expand Down Expand Up @@ -212,7 +212,11 @@ def default_api_version(self):
ResourceType.MGMT_IOTHUB: '2021-03-31',
ResourceType.MGMT_ARO: '2020-04-30',
ResourceType.MGMT_DATABOXEDGE: '2019-08-01',
ResourceType.MGMT_CUSTOMLOCATION: '2021-03-15-preview'
ResourceType.MGMT_CUSTOMLOCATION: '2021-03-15-preview',
ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2021-03-01', {
'container_services': '2017-07-01',
'open_shift_managed_clusters': '2019-10-27-preview'
})
},
'2020-09-01-hybrid': {
ResourceType.MGMT_STORAGE: '2019-06-01',
Expand Down Expand Up @@ -252,7 +256,12 @@ def default_api_version(self):
ResourceType.MGMT_APPSERVICE: '2018-02-01',
ResourceType.MGMT_EVENTHUB: '2018-01-01-preview',
ResourceType.MGMT_IOTHUB: '2019-07-01-preview',
ResourceType.MGMT_DATABOXEDGE: '2019-08-01'
ResourceType.MGMT_DATABOXEDGE: '2019-08-01',
ResourceType.MGMT_CONTAINERREGISTRY: '2019-05-01',
ResourceType.MGMT_CONTAINERSERVICE: SDKProfile('2020-11-01', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you specify different api version for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will bring in the "profile" support effort for AKS team.
because we were always testing/release the freshest api version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Azure Stack environment, we may not use the latest API version. Here is for 2020-09-01-hybrid profile. @Bhuvaneswari-Santharam for confirmation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these are for the 2020-09-01-hybrid profile, and I have another PR to add test for hybrid profiles

'container_services': '2017-07-01',
'open_shift_managed_clusters': '2019-10-27-preview'
})
},
'2019-03-01-hybrid': {
ResourceType.MGMT_STORAGE: '2017-10-01',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def get_auth_management_client(cli_ctx, scope=None, **_):


def get_container_service_client(cli_ctx, **_):
from azure.mgmt.containerservice import ContainerServiceClient

return get_mgmt_service_client(cli_ctx, ContainerServiceClient)
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_CONTAINERSERVICE)


def get_osa_container_service_client(cli_ctx, **_):
Expand Down
9 changes: 7 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acs/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@

from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error
# pylint: disable=no-name-in-module,import-error
from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterAPIServerAccessProfile
from knack.util import CLIError
from azure.cli.core.profiles import ResourceType
from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING


def _populate_api_server_access_profile(api_server_authorized_ip_ranges, enable_private_cluster=False, instance=None):
def _populate_api_server_access_profile(cmd,
api_server_authorized_ip_ranges,
enable_private_cluster=False, instance=None):
if instance is None or instance.api_server_access_profile is None:
ManagedClusterAPIServerAccessProfile = cmd.get_models('ManagedClusterAPIServerAccessProfile',
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
operation_group='managed_clusters')
profile = ManagedClusterAPIServerAccessProfile()
else:
profile = instance.api_server_access_profile
Expand Down
43 changes: 29 additions & 14 deletions src/azure-cli/azure/cli/command_modules/acs/_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error

# pylint: disable=no-name-in-module,import-error
from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfile
from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileManagedOutboundIPs
from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPPrefixes
from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterLoadBalancerProfileOutboundIPs
from azure.mgmt.containerservice.v2021_03_01.models import ResourceReference
from azure.cli.core.profiles import ResourceType

from knack.log import get_logger

Expand All @@ -28,37 +24,40 @@ def set_load_balancer_sku(sku, kubernetes_version):
return "standard"


def update_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
def update_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
outbound_ports, idle_timeout, profile):
"""parse and update an existing load balancer profile"""
if not is_load_balancer_profile_provided(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
outbound_ports, idle_timeout):
return profile
return configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
return configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
outbound_ports, idle_timeout, profile)


def create_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
def create_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
outbound_ports, idle_timeout):
"""parse and build load balancer profile"""
if not is_load_balancer_profile_provided(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
outbound_ports, idle_timeout):
return None

ManagedClusterLoadBalancerProfile = cmd.get_models('ManagedClusterLoadBalancerProfile',
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
operation_group='managed_clusters')
profile = ManagedClusterLoadBalancerProfile()
return configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
return configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes,
outbound_ports, idle_timeout, profile)


def configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports,
def configure_load_balancer_profile(cmd, managed_outbound_ip_count, outbound_ips, outbound_ip_prefixes, outbound_ports,
idle_timeout, profile):
"""configure a load balancer with customer supplied values"""
if not profile:
return profile

outbound_ip_resources = _get_load_balancer_outbound_ips(outbound_ips)
outbound_ip_resources = _get_load_balancer_outbound_ips(cmd, outbound_ips)
outbound_ip_prefix_resources = _get_load_balancer_outbound_ip_prefixes(
outbound_ip_prefixes)
cmd, outbound_ip_prefixes)

if managed_outbound_ip_count or outbound_ip_resources or outbound_ip_prefix_resources:
# ips -> i_ps due to track 2 naming issue
Expand All @@ -68,16 +67,28 @@ def configure_load_balancer_profile(managed_outbound_ip_count, outbound_ips, out
profile.outbound_ip_prefixes = None
if managed_outbound_ip_count:
# ips -> i_ps due to track 2 naming issue
ManagedClusterLoadBalancerProfileManagedOutboundIPs = cmd.get_models(
'ManagedClusterLoadBalancerProfileManagedOutboundIPs',
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
operation_group='managed_clusters')
profile.managed_outbound_i_ps = ManagedClusterLoadBalancerProfileManagedOutboundIPs(
count=managed_outbound_ip_count
)
if outbound_ip_resources:
# ips -> i_ps due to track 2 naming issue
ManagedClusterLoadBalancerProfileOutboundIPs = cmd.get_models(
'ManagedClusterLoadBalancerProfileOutboundIPs',
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
operation_group='managed_clusters')
profile.outbound_i_ps = ManagedClusterLoadBalancerProfileOutboundIPs(
# ips -> i_ps due to track 2 naming issue
public_i_ps=outbound_ip_resources
)
if outbound_ip_prefix_resources:
ManagedClusterLoadBalancerProfileOutboundIPPrefixes = cmd.get_models(
'ManagedClusterLoadBalancerProfileOutboundIPPrefixes',
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
operation_group='managed_clusters')
profile.outbound_ip_prefixes = ManagedClusterLoadBalancerProfileOutboundIPPrefixes(
public_ip_prefixes=outbound_ip_prefix_resources
)
Expand All @@ -97,20 +108,24 @@ def is_load_balancer_profile_provided(managed_outbound_ip_count, outbound_ips, i
idle_timeout])


def _get_load_balancer_outbound_ips(load_balancer_outbound_ips):
def _get_load_balancer_outbound_ips(cmd, load_balancer_outbound_ips):
"""parse load balancer profile outbound IP ids and return an array of references to the outbound IP resources"""
load_balancer_outbound_ip_resources = None
ResourceReference = cmd.get_models('ResourceReference', resource_type=ResourceType.MGMT_CONTAINERSERVICE,
operation_group='managed_clusters')
if load_balancer_outbound_ips:
load_balancer_outbound_ip_resources = \
[ResourceReference(id=x.strip())
for x in load_balancer_outbound_ips.split(',')]
return load_balancer_outbound_ip_resources


def _get_load_balancer_outbound_ip_prefixes(load_balancer_outbound_ip_prefixes):
def _get_load_balancer_outbound_ip_prefixes(cmd, load_balancer_outbound_ip_prefixes):
"""parse load balancer profile outbound IP prefix ids and return an array \
of references to the outbound IP prefix resources"""
load_balancer_outbound_ip_prefix_resources = None
ResourceReference = cmd.get_models('ResourceReference', resource_type=ResourceType.MGMT_CONTAINERSERVICE,
operation_group='managed_clusters')
if load_balancer_outbound_ip_prefixes:
load_balancer_outbound_ip_prefix_resources = \
[ResourceReference(id=x.strip())
Expand Down
27 changes: 14 additions & 13 deletions src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from azure.cli.core.commands.parameters import (
file_type, get_enum_type, get_resource_name_completion_list, name_type, tags_type, zones_type)
from azure.cli.core.commands.validators import validate_file_or_dict
from azure.cli.core.profiles import ResourceType
from knack.arguments import CLIArgumentType

from ._completers import (
Expand Down Expand Up @@ -157,7 +158,7 @@ def load_arguments(self, _):
completer=FilesCompleter(), help='Path to an SSH key file to use.')

# AKS command argument configuration
with self.argument_context('aks') as c:
with self.argument_context('aks', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('resource_name', name_type, help='Name of the managed cluster.',
completer=get_resource_name_completion_list('Microsoft.ContainerService/ManagedClusters'))
c.argument('name', name_type, help='Name of the managed cluster.',
Expand All @@ -167,7 +168,7 @@ def load_arguments(self, _):
c.argument('node_count', options_list=['--node-count', '-c'], type=int)
c.argument('tags', tags_type)

with self.argument_context('aks create') as c:
with self.argument_context('aks create', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('name', validator=validate_linux_host_name)
c.argument('kubernetes_version',
completer=get_k8s_versions_completion_list)
Expand Down Expand Up @@ -265,7 +266,7 @@ def load_arguments(self, _):
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')
c.argument('enable_sgxquotehelper', action='store_true')

with self.argument_context('aks update') as c:
with self.argument_context('aks update', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('attach_acr', acr_arg_type, validator=validate_acr)
c.argument('detach_acr', acr_arg_type, validator=validate_acr)

Expand Down Expand Up @@ -303,10 +304,10 @@ def load_arguments(self, _):
c.argument('yes', options_list=[
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

with self.argument_context('aks disable-addons') as c:
with self.argument_context('aks disable-addons', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('addons', options_list=['--addons', '-a'])

with self.argument_context('aks enable-addons') as c:
with self.argument_context('aks enable-addons', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('addons', options_list=['--addons', '-a'])
c.argument('subnet_name', options_list=[
'--subnet-name', '-s'], help='Name of an existing subnet to use with the virtual-node add-on.')
Expand All @@ -322,7 +323,7 @@ def load_arguments(self, _):
'--appgw-watch-namespace'], arg_group='Application Gateway')
c.argument('enable_sgxquotehelper', action='store_true')

with self.argument_context('aks get-credentials') as c:
with self.argument_context('aks get-credentials', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('admin', options_list=['--admin', '-a'], default=False)
c.argument('context_name', options_list=['--context'],
help='If specified, overwrite the default context name.')
Expand Down Expand Up @@ -356,17 +357,17 @@ def load_arguments(self, _):
c.argument('aad_server_app_secret')
c.argument('aad_tenant_id')

with self.argument_context('aks upgrade') as c:
with self.argument_context('aks upgrade', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('kubernetes_version',
completer=get_k8s_upgrades_completion_list)
c.argument('yes', options_list=[
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

with self.argument_context('aks scale') as c:
with self.argument_context('aks scale', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('nodepool_name', type=str,
help='Node pool name, up to 12 alphanumeric characters', validator=validate_nodepool_name)

with self.argument_context('aks nodepool') as c:
with self.argument_context('aks nodepool', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
c.argument('cluster_name', type=str, help='The cluster name.')

for scope in ['aks nodepool add']:
Expand Down Expand Up @@ -405,7 +406,7 @@ def load_arguments(self, _):
c.argument('nodepool_name', type=str, options_list=[
'--name', '-n'], validator=validate_nodepool_name, help='The node pool name.')

with self.argument_context('aks nodepool update') as c:
with self.argument_context('aks nodepool update', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='agent_pools') as c:
c.argument('enable_cluster_autoscaler', options_list=[
"--enable-cluster-autoscaler", "-e"], action='store_true')
c.argument('disable_cluster_autoscaler', options_list=[
Expand Down Expand Up @@ -439,7 +440,7 @@ def load_arguments(self, _):
'--yes', '-y'], action='store_true', help='Do not prompt for confirmation')

# OpenShift command argument configuration
with self.argument_context('openshift') as c:
with self.argument_context('openshift', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') as c:
c.argument('resource_name', name_type, help='Name of the managed OpenShift cluster.',
completer=get_resource_name_completion_list('Microsoft.ContainerService/OpenShiftManagedClusters'))
c.argument('name', name_type, help='Name of the managed OpenShift cluster.',
Expand All @@ -448,14 +449,14 @@ def load_arguments(self, _):
'--compute-count', '-c'], type=int, default=4)
c.argument('tags', tags_type)

with self.argument_context('openshift create') as c:
with self.argument_context('openshift create', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') as c:
c.argument('name', validator=validate_linux_host_name)
c.argument('compute_vm_size', options_list=['--compute-vm-size', '-s'])
c.argument('customer_admin_group_id', options_list=[
'--customer-admin-group-id'])
c.argument('workspace_id')

with self.argument_context('openshift monitor enable') as c:
with self.argument_context('openshift monitor enable', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='open_shift_managed_clusters') as c:
c.argument(
'workspace_id', help='The resource ID of an existing Log Analytics Workspace to use for storing monitoring data.')

Expand Down
12 changes: 8 additions & 4 deletions src/azure-cli/azure/cli/command_modules/acs/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# pylint: disable=no-name-in-module,import-error
from knack.log import get_logger

from azure.cli.core.profiles import ResourceType

from azure.cli.core.commands.validators import validate_tag
from azure.cli.core.util import CLIError
from azure.cli.core.azclierror import InvalidArgumentValueError
import azure.cli.core.keys as keys

from azure.mgmt.containerservice.v2021_03_01.models import ManagedClusterPropertiesAutoScalerProfile

logger = get_logger(__name__)

Expand Down Expand Up @@ -107,7 +108,7 @@ def validate_k8s_version(namespace):
'such as "1.11.8" or "1.12.6"')


def validate_cluster_autoscaler_profile(namespace):
def validate_cluster_autoscaler_profile(cmd, namespace):
""" Validates that cluster autoscaler profile is acceptable by:
1. Extracting the key[=value] format to map
2. Validating that the key isn't empty and that the key is valid
Expand All @@ -116,12 +117,15 @@ def validate_cluster_autoscaler_profile(namespace):
_extract_cluster_autoscaler_params(namespace)
if namespace.cluster_autoscaler_profile is not None:
for key in namespace.cluster_autoscaler_profile.keys():
_validate_cluster_autoscaler_key(key)
_validate_cluster_autoscaler_key(cmd, key)


def _validate_cluster_autoscaler_key(key):
def _validate_cluster_autoscaler_key(cmd, key):
if not key:
raise CLIError('Empty key specified for cluster-autoscaler-profile')
ManagedClusterPropertiesAutoScalerProfile = cmd.get_models('ManagedClusterPropertiesAutoScalerProfile',
resource_type=ResourceType.MGMT_CONTAINERSERVICE,
operation_group='managed_clusters')
valid_keys = list(k.replace("_", "-") for k, v in ManagedClusterPropertiesAutoScalerProfile._attribute_map.items()) # pylint: disable=protected-access
if key not in valid_keys:
raise CLIError("'{0}' is an invalid key for cluster-autoscaler-profile. "
Expand Down
Loading