Skip to content

Commit

Permalink
Private Link Changes in connectedk8s CLI (#3506)
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkeshari authored Aug 22, 2022
1 parent e373ae7 commit adb37ef
Show file tree
Hide file tree
Showing 27 changed files with 3,587 additions and 1,665 deletions.
5 changes: 5 additions & 0 deletions src/connectedk8s/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Release History
===============
1.3.0
++++++

* Added private link support

1.2.11
++++++

Expand Down
13 changes: 9 additions & 4 deletions src/connectedk8s/azext_connectedk8s/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ def cf_connected_cluster(cli_ctx, _):
return cf_connectedk8s(cli_ctx).connected_cluster


def cf_connectedk8s_prev_2021_04_01(cli_ctx, *_):
from azext_connectedk8s.vendored_sdks.preview_2021_04_01 import ConnectedKubernetesClient
def cf_connectedk8s_prev_2022_05_01(cli_ctx, *_):
from azext_connectedk8s.vendored_sdks.preview_2022_05_01 import ConnectedKubernetesClient
return get_mgmt_service_client(cli_ctx, ConnectedKubernetesClient)


def cf_connected_cluster_prev_2021_04_01(cli_ctx, _):
return cf_connectedk8s_prev_2021_04_01(cli_ctx).connected_cluster
def cf_connected_cluster_prev_2022_05_01(cli_ctx, _):
return cf_connectedk8s_prev_2022_05_01(cli_ctx).connected_cluster


def cf_connectedmachine(cli_ctx, subscription_id):
from azure.mgmt.hybridcompute import HybridComputeManagementClient
return get_mgmt_service_client(cli_ctx, HybridComputeManagementClient, subscription_id=subscription_id).private_link_scopes


def cf_resource_groups(cli_ctx, subscription_id=None):
Expand Down
3 changes: 3 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
Default_Onboarding_Source_Tracking_Guid = "77ade16b-0f55-403b-b7d2-739554a897f2"
Helm_Environment_File_Fault_Type = 'helm-environment-file-error'
Invalid_Location_Fault_Type = 'location-validation-error'
Pls_Location_Mismatch_Fault_Type = 'pls-location-mismatch-error'
Invalid_Argument_Fault_Type = 'argument-validation-error'
Load_Kubeconfig_Fault_Type = 'kubeconfig-load-error'
Read_ConfigMap_Fault_Type = 'configmap-read-error'
Get_ResourceProvider_Fault_Type = 'resource-provider-fetch-error'
Get_ConnectedCluster_Fault_Type = 'connected-cluster-fetch-error'
Create_ConnectedCluster_Fault_Type = 'connected-cluster-create-error'
Update_ConnectedCluster_Fault_Type = 'connected-cluster-update-error'
Delete_ConnectedCluster_Fault_Type = 'connected-cluster-delete-error'
Bad_DeleteRequest_Fault_Type = 'bad-delete-request-error'
Cluster_Already_Onboarded_Fault_Type = 'cluster-already-onboarded-error'
Expand Down
4 changes: 3 additions & 1 deletion src/connectedk8s/azext_connectedk8s/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
text: az connectedk8s connect -g resourceGroupName -n connectedClusterName --proxy-https https://proxy-url --proxy-http http://proxy-url --proxy-skip-range excludedIP,excludedCIDR,exampleCIDRfollowed,10.0.0.0/24
- name: Onboard a connected kubernetes cluster by specifying the https proxy, http proxy, no proxy with cert settings.
text: az connectedk8s connect -g resourceGroupName -n connectedClusterName --proxy-cert /path/to/crt --proxy-https https://proxy-url --proxy-http http://proxy-url --proxy-skip-range excludedIP,excludedCIDR,exampleCIDRfollowed,10.0.0.0/24
- name: Onboard a connected kubernetes cluster with private link feature enabled by specifying private link parameters.
text: az connectedk8s connect -g resourceGroupName -n connectedClusterName --enable-private-link true --private-link-scope-resource-id pls/resource/arm/id
- name: Onboard a connected kubernetes cluster with custom onboarding timeout.
text: az connectedk8s connect -g resourceGroupName -n connectedClusterName --onboarding-timeout 600
"""

helps['connectedk8s update'] = """
type: command
short-summary: Update properties of the onboarded agents.
short-summary: Update properties of the arc onboarded kubernetes cluster.
examples:
- name: Update proxy values for the agents
text: az connectedk8s update -g resourceGroupName -n connectedClusterName --proxy-cert /path/to/crt --proxy-https https://proxy-url --proxy-http http://proxy-url --proxy-skip-range excludedIP,excludedCIDR,exampleCIDRfollowed,10.0.0.0/24
Expand Down
8 changes: 7 additions & 1 deletion src/connectedk8s/azext_connectedk8s/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import os.path
from ._validators import override_client_request_id_header
from argcomplete.completers import FilesCompleter
from azure.cli.core.commands.parameters import get_location_type, get_enum_type, file_type, tags_type
from azure.cli.core.commands.parameters import get_location_type, get_enum_type, file_type, tags_type, get_three_state_flag
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from azext_connectedk8s._constants import Distribution_Enum_Values, Infrastructure_Enum_Values, Feature_Values
from knack.arguments import (CLIArgumentType, CaseInsensitiveList)

from._validators import validate_private_link_properties

features_types = CLIArgumentType(
nargs='+',
Expand All @@ -21,6 +22,8 @@

def load_arguments(self, _):

pls_arm_id_type = CLIArgumentType(options_list=['--private-link-scope-resource-id', '--pls-arm-id'], arg_group='PrivateLink', help='ARM resource id of the private link scope resource to which this connected cluster is associated.', is_preview=True)

with self.argument_context('connectedk8s connect') as c:
c.argument('tags', tags_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
Expand All @@ -35,11 +38,14 @@ def load_arguments(self, _):
c.argument('infrastructure', options_list=['--infrastructure'], help='The infrastructure on which the Kubernetes cluster represented by this connected cluster will be running on.', arg_type=get_enum_type(Infrastructure_Enum_Values))
c.argument('disable_auto_upgrade', options_list=['--disable-auto-upgrade'], action='store_true', help='Flag to disable auto upgrade of arc agents.')
c.argument('cl_oid', options_list=['--custom-locations-oid'], help="OID of 'custom-locations' app")
c.argument('enable_private_link', arg_type=get_three_state_flag(), arg_group='PrivateLink', help='Flag to enable/disable private link support on a connected cluster resource. Allowed values: false, true.', is_preview=True, validator=validate_private_link_properties)
c.argument('private_link_scope_resource_id', pls_arm_id_type)
c.argument('onboarding_timeout', options_list=['--onboarding-timeout'], arg_group='Timeout', help='Time required (in seconds) for the arc-agent pods to be installed on the kubernetes cluster. Override this value if the hardware/network constraints on your cluster requires more time for installing the arc-agent pods.')
c.argument('no_wait', options_list=['--no-wait'], arg_group='Timeout', help="Do not wait for the long-running operation to finish.")
c.argument('correlation_id', options_list=['--correlation-id'], help='A guid that is used to internally track the source of cluster onboarding. Please do not modify it unless advised', validator=override_client_request_id_header)

with self.argument_context('connectedk8s update') as c:
c.argument('tags', tags_type)
c.argument('cluster_name', options_list=['--name', '-n'], id_part='name', help='The name of the connected cluster.')
c.argument('kube_config', options_list=['--kube-config'], help='Path to the kube config file.')
c.argument('kube_context', options_list=['--kube-context'], help='Kubconfig context from current machine.')
Expand Down
7 changes: 5 additions & 2 deletions src/connectedk8s/azext_connectedk8s/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def delete_arc_agents(release_namespace, kube_config, kube_context, configuratio
def helm_install_release(chart_path, subscription_id, kubernetes_distro, kubernetes_infra, resource_group_name, cluster_name,
location, onboarding_tenant_id, http_proxy, https_proxy, no_proxy, proxy_cert, private_key_pem,
kube_config, kube_context, no_wait, values_file_provided, values_file, cloud_name, disable_auto_upgrade,
enable_custom_locations, custom_locations_oid, helm_client_location, onboarding_timeout="600"):
enable_custom_locations, custom_locations_oid, helm_client_location, enable_private_link, onboarding_timeout="600"):
cmd_helm_install = [helm_client_location, "upgrade", "--install", "azure-arc", chart_path,
"--set", "global.subscriptionId={}".format(subscription_id),
"--set", "global.kubernetesDistro={}".format(kubernetes_distro),
Expand All @@ -306,9 +306,12 @@ def helm_install_release(chart_path, subscription_id, kubernetes_distro, kuberne
"--set", "systemDefaultValues.clusterconnect-agent.enabled=true",
"--output", "json"]
# Add custom-locations related params
if enable_custom_locations:
if enable_custom_locations and not enable_private_link:
cmd_helm_install.extend(["--set", "systemDefaultValues.customLocations.enabled=true"])
cmd_helm_install.extend(["--set", "systemDefaultValues.customLocations.oid={}".format(custom_locations_oid)])
# Disable cluster connect if private link is enabled
if enable_private_link is True:
cmd_helm_install.extend(["--set", "systemDefaultValues.clusterconnect-agent.enabled=false"])
# To set some other helm parameters through file
if values_file_provided:
cmd_helm_install.extend(["-f", values_file])
Expand Down
11 changes: 11 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import azext_connectedk8s._constants as consts


from os import name
from azure.cli.core.azclierror import ArgumentUsageError


def example_name_or_id_validator(cmd, namespace):
# Example of a storage account name or ID validator.
from azure.cli.core.commands.client_factory import get_subscription_id
Expand All @@ -20,6 +24,13 @@ def example_name_or_id_validator(cmd, namespace):
)


def validate_private_link_properties(namespace):
if not namespace.enable_private_link and namespace.private_link_scope_resource_id:
raise ArgumentUsageError("Conflicting private link parameters received. The parameter '--private-link-scope-resource-id' should not be set if '--enable-private-link' is passed as null or False.")
if namespace.enable_private_link is True and not namespace.private_link_scope_resource_id:
raise ArgumentUsageError("The parameter '--private-link-scope-resource-id' was not provided. It is mandatory to pass this parameter for enabling private link on the connected cluster resource.")


def override_client_request_id_header(cmd, namespace):
if namespace.correlation_id is not None:
cmd.cli_ctx.data['headers'][consts.Client_Request_Id_Header] = namespace.correlation_id
Expand Down
10 changes: 5 additions & 5 deletions src/connectedk8s/azext_connectedk8s/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# pylint: disable=line-too-long
from azure.cli.core.commands import CliCommandType
from azext_connectedk8s._client_factory import (cf_connectedk8s, cf_connected_cluster, cf_connectedk8s_prev_2021_04_01, cf_connected_cluster_prev_2021_04_01)
from azext_connectedk8s._client_factory import (cf_connectedk8s, cf_connected_cluster, cf_connectedk8s_prev_2022_05_01, cf_connected_cluster_prev_2022_05_01)
from ._format import connectedk8s_show_table_format
from ._format import connectedk8s_list_table_format

Expand All @@ -17,12 +17,12 @@ def load_command_table(self, _):
client_factory=cf_connectedk8s
)
connectedk8s_sdk_prev = CliCommandType(
operations_tmpl='azext_connectedk8s.vendored_sdks.preview_2021_04_01.operations#ConnectedClusterOperations.{}',
client_factory=cf_connectedk8s_prev_2021_04_01
operations_tmpl='azext_connectedk8s.vendored_sdks.preview_2022_05_01.operations#ConnectedClusterOperations.{}',
client_factory=cf_connectedk8s_prev_2022_05_01
)
with self.command_group('connectedk8s', connectedk8s_sdk, client_factory=cf_connected_cluster) as g:
g.custom_command('connect', 'create_connectedk8s', supports_no_wait=True)
g.custom_command('update', 'update_agents')
g.custom_command('update', 'update_connected_cluster')
g.custom_command('upgrade', 'upgrade_agents')
g.custom_command('delete', 'delete_connectedk8s', confirmation=True, supports_no_wait=True)
g.custom_command('enable-features', 'enable_features', is_preview=True)
Expand All @@ -32,6 +32,6 @@ def load_command_table(self, _):
g.custom_command('proxy', 'client_side_proxy_wrapper')
g.custom_command('troubleshoot', 'troubleshoot', is_preview=True)

with self.command_group('connectedk8s', connectedk8s_sdk_prev, client_factory=cf_connected_cluster_prev_2021_04_01) as g:
with self.command_group('connectedk8s', connectedk8s_sdk_prev, client_factory=cf_connected_cluster_prev_2022_05_01) as g:
pass
# use this block for using preview sdk client for a command
Loading

0 comments on commit adb37ef

Please sign in to comment.