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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_container_service_client(cli_ctx, **_):
def get_osa_container_service_client(cli_ctx, **_):
from azure.mgmt.containerservice import ContainerServiceClient

return get_mgmt_service_client(cli_ctx, ContainerServiceClient, api_version='2019-09-30-preview')
return get_mgmt_service_client(cli_ctx, ContainerServiceClient, api_version='2019-10-27-preview')


def get_graph_rbac_management_client(cli_ctx, **_):
Expand Down
49 changes: 14 additions & 35 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,50 +931,17 @@
helps['openshift create'] = """
type: command
short-summary: Create a new managed OpenShift cluster.
parameters:
- name: --compute-vm-size -s
type: string
short-summary: Size of Virtual Machines to create as OpenShift nodes.
- name: --compute-count -c
type: int
short-summary: Number of nodes in the OpenShift node pool.
- name: --aad-client-app-id
type: string
short-summary: The ID of an Azure Active Directory client application. If not specified, a new Azure Active Directory client is created.
- name: --aad-client-app-secret
type: string
short-summary: The secret of an Azure Active Directory client application.
- name: --aad-tenant-id
type: string
short-summary: The ID of an Azure Active Directory tenant.
- name: --vnet-peer
type: string
short-summary: The ID or the name of a subnet in an existing VNet into which to peer the cluster.
- name: --vnet-prefix
type: string
short-summary: The CIDR used on the VNet into which to deploy the cluster.
- name: --subnet-prefix
type: string
short-summary: The CIDR used on the Subnet into which to deploy the cluster.
- name: --customer-admin-group-id
type: string
short-summary: The Object ID of an Azure Active Directory Group that memberships will get synced into the OpenShift group "osa-customer-admins". If not specified, no cluster admin access will be granted.
- name: --workspace-id
type: string
short-summary: The resource id of an existing Log Analytics Workspace to use for storing monitoring data.


examples:
- name: Create an OpenShift cluster and auto create an AAD Client
text: az openshift create -g MyResourceGroup -n MyManagedCluster
- name: Create an OpenShift cluster and auto create an AAD Client and setup cluster admin group
text: az openshift create -g MyResourceGroup -n MyManagedCluster --customer-admin-group-id {GROUP_ID}
- name: Create an OpenShift cluster with 5 compute nodes and a custom AAD Client.
text: az openshift create -g MyResourceGroup -n MyManagedCluster --aad-client-app-id {APP_ID} --aad-client-app-secret {APP_SECRET} --aad-tenant-id {TENANT_ID} --compute-count 5
- name: Create an Openshift cluster using a custom vnet
text: az openshift create -g MyResourceGroup -n MyManagedCluster --vnet-peer "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/openshift-vnet/providers/Microsoft.Network/virtualNetworks/test"
- name: Create an Openshift cluster with Log Analytics monitoring enabled
text: az openshift create -g MyResourceGroup -n MyManagedCluster --workspace-id "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/{workspace-id}"
- name: Create a private OpenShift cluster
text: az openshift create -g MyResourceGroup -n MyManagedCluster --private-cluster --management-subnet-cidr 10.0.1.0/24
"""

helps['openshift delete'] = """
Expand Down Expand Up @@ -1045,3 +1012,15 @@
text: |-
az openshift monitor disable -g MyResourceGroup -n MyManagedCluster
"""

helps['openshift update'] = """
type: command
short-summary: Commands to manage existing Openshift cluster.
parameters:
- name: --refresh-cluster
type: boolean
examples:
- name: Trigger nodes rotation.
text: az openshift update -g MyResourceGroup -n MyManagedCluster --refresh-cluster
crafted: true
"""
24 changes: 20 additions & 4 deletions src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from argcomplete.completers import FilesCompleter
from azure.cli.core.commands.parameters import (
file_type, get_enum_type, get_resource_name_completion_list, name_type, tags_type, zones_type)
file_type, get_enum_type, get_resource_name_completion_list, name_type, tags_type, zones_type, get_three_state_flag)
from azure.cli.core.commands.validators import validate_file_or_dict
from knack.arguments import CLIArgumentType

Expand Down Expand Up @@ -341,9 +341,25 @@ def load_arguments(self, _):

with self.argument_context('openshift create') 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')
c.argument('aad_client_app_id', help='The ID of an Azure Active Directory client application. If not specified, a new Azure Active Directory client is created.')
c.argument('aad_client_app_secret', help='The secret of an Azure Active Directory client application.')
c.argument('aad_tenant_id', help='The ID of an Azure Active Directory tenant.')
c.argument('compute_count', options_list=['--compute-count', '-c'], help='Number of nodes in the OpenShift node pool.')
c.argument('compute_vm_size', options_list=['--compute-vm-size', '-s'], help='Size of Virtual Machines to create as OpenShift nodes.')
c.argument('customer_admin_group_id',
help='The Object ID of an Azure Active Directory Group that memberships will get synced into the OpenShift group "osa-customer-admins".'
'If not specified, no cluster admin access will be granted.')
c.argument('management_subnet_cidr', help='CIDR of subnet used to create PLS needed for management of the cluster. If provided, also set --private-cluster flag.')
c.argument('private_cluster', arg_type=get_three_state_flag(), help='Create private Openshift cluster. If this flag is set, also supply --management-subnet-cidr.')
c.argument('subnet_prefix', help='The CIDR used on the Subnet into which to deploy the cluster.')
c.argument('vnet_peer',
help='Vnet peering is no longer supported during cluster creation, instead it is possible to edit vnet properties after cluster creation')
c.argument('vnet_prefix', help='The CIDR used on the VNet into which to deploy the cluster.')
c.argument('workspace_id', help='The resource id of an existing Log Analytics Workspace to use for storing monitoring data.')

with self.argument_context('openshift update') as c:
c.argument('refresh_cluster', arg_type=get_three_state_flag(),
help='Allow nodes to be rotated. Use this flag to trigger nodes rotation after DNS settings change.')

with self.argument_context('openshift monitor enable') as c:
c.argument('workspace_id', help='The resource ID of an existing Log Analytics Workspace to use for storing monitoring data.')
Expand Down
3 changes: 2 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def load_command_table(self, _):
)

openshift_managed_clusters_sdk = CliCommandType(
operations_tmpl='azure.mgmt.containerservice.v2018_09_30_preview.operations.'
operations_tmpl='azure.mgmt.containerservice.v2019_10_27_preview.operations.'
'_open_shift_managed_clusters_operations#OpenShiftManagedClustersOperations.{}',
client_factory=cf_openshift_managed_clusters
)
Expand Down Expand Up @@ -119,6 +119,7 @@ def load_command_table(self, _):
with self.command_group('openshift', openshift_managed_clusters_sdk,
client_factory=cf_openshift_managed_clusters) as g:
g.custom_command('create', 'openshift_create', supports_no_wait=True)
g.custom_command('update', 'openshift_update', supports_no_wait=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a wait command as there are so many support_to_wait commands ?

Copy link
Author

Choose a reason for hiding this comment

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

@arrownj yes we do have wait command:

g.command('delete', 'delete', supports_no_wait=True, confirmation=True)
g.custom_command('scale', 'openshift_scale', supports_no_wait=True)
g.custom_show_command('show', 'openshift_show')
Expand Down
64 changes: 38 additions & 26 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@
from azure.mgmt.containerservice.v2020_03_01.models import AgentPool
from azure.mgmt.containerservice.v2020_03_01.models import ManagedClusterSKU

from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterAgentPoolProfile
from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftAgentPoolProfileRole
from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterIdentityProvider
from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterAADIdentityProvider
from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedCluster
from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftRouterProfile
from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterAuthProfile
from azure.mgmt.containerservice.v2019_09_30_preview.models import NetworkProfile
from azure.mgmt.containerservice.v2019_09_30_preview.models import OpenShiftManagedClusterMonitorProfile
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftManagedClusterAgentPoolProfile
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftManagedClusterMasterPoolProfile
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftAgentPoolProfileRole
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftManagedClusterIdentityProvider
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftManagedClusterAADIdentityProvider
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftManagedCluster
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftRouterProfile
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftManagedClusterAuthProfile
from azure.mgmt.containerservice.v2019_10_27_preview.models import NetworkProfile
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftManagedClusterMonitorProfile
from azure.mgmt.containerservice.v2019_10_27_preview.models import OpenShiftAPIProperties
Copy link
Contributor

Choose a reason for hiding this comment

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

Per https://github.com/Azure/sdk-release-request/issues/46 this should be available in the latest release (8.3.0).

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to be missing the right models, I've pinged the release manager on the ticket.


from ._client_factory import cf_container_services
from ._client_factory import cf_resource_groups
Expand Down Expand Up @@ -3215,17 +3217,13 @@ def _remove_osa_nulls(managed_clusters):
"""
attrs = ['tags', 'plan', 'type', 'id']
ap_master_attrs = ['name', 'os_type']
net_attrs = ['peer_vnet_id']
for managed_cluster in managed_clusters:
for attr in attrs:
if getattr(managed_cluster, attr, None) is None:
delattr(managed_cluster, attr)
for attr in ap_master_attrs:
if getattr(managed_cluster.master_pool_profile, attr, None) is None:
delattr(managed_cluster.master_pool_profile, attr)
for attr in net_attrs:
if getattr(managed_cluster.network_profile, attr, None) is None:
delattr(managed_cluster.network_profile, attr)
return managed_clusters


Expand Down Expand Up @@ -3290,7 +3288,13 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=
tags=None,
no_wait=False,
workspace_id=None,
customer_admin_group_id=None):
customer_admin_group_id=None,
management_subnet_cidr=None,
private_cluster=None):

if vnet_peer is not None:
raise CLIError('Vnet peering is no longer supported during cluster creation.'
'Instead it is possible to edit vnet properties after cluster creation')

if location is None:
location = _get_rg_location(cmd.cli_ctx, resource_group_name)
Expand All @@ -3304,6 +3308,13 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=
subnet_cidr=subnet_prefix
)

if bool(private_cluster) != bool(management_subnet_cidr is not None):
raise CLIError('Both --private-cluster and --management-subnet-cidr need to be supplied or neither.')

api_properties = OpenShiftAPIProperties(
private_api_server=bool(private_cluster)
)

agent_infra_pool_profile = OpenShiftManagedClusterAgentPoolProfile(
name='infra', # Must be 12 chars or less before ACS RP adds to it
count=int(3),
Expand All @@ -3316,13 +3327,15 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=
agent_pool_profiles.append(agent_node_pool_profile)
agent_pool_profiles.append(agent_infra_pool_profile)

agent_master_pool_profile = OpenShiftManagedClusterAgentPoolProfile(
agent_master_pool_profile = OpenShiftManagedClusterMasterPoolProfile(
name='master', # Must be 12 chars or less before ACS RP adds to it
count=int(3),
vm_size="Standard_D4s_v3",
os_type="Linux",
subnet_cidr=subnet_prefix
subnet_cidr=subnet_prefix,
api_properties=api_properties
)

identity_providers = []

create_aad = False
Expand Down Expand Up @@ -3351,22 +3364,13 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=

default_router_profile = OpenShiftRouterProfile(name='default')

if vnet_peer is not None:
from msrestazure.tools import is_valid_resource_id, resource_id
if not is_valid_resource_id(vnet_peer):
vnet_peer = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=resource_group_name,
namespace='Microsoft.Network', type='virtualNetwork',
name=vnet_peer
)
if workspace_id is not None:
workspace_id = _format_workspace_id(workspace_id)
monitor_profile = OpenShiftManagedClusterMonitorProfile(enabled=True, workspace_resource_id=workspace_id) # pylint: disable=line-too-long
else:
monitor_profile = None

network_profile = NetworkProfile(vnet_cidr=vnet_prefix, peer_vnet_id=vnet_peer)
network_profile = NetworkProfile(vnet_cidr=vnet_prefix, management_subnet_cidr=management_subnet_cidr)
osamc = OpenShiftManagedCluster(
location=location, tags=tags,
open_shift_version="v3.11",
Expand Down Expand Up @@ -3396,6 +3400,14 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=
raise ex


def openshift_update(cmd, client, resource_group_name, name, refresh_cluster=None, no_wait=False):
instance = client.get(resource_group_name, name)
if refresh_cluster:
instance.refresh_cluster = True

return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance)


def openshift_show(cmd, client, resource_group_name, name):
mc = client.get(resource_group_name, name)
return _remove_osa_nulls([mc])[0]
Expand Down