diff --git a/src/connectedk8s/HISTORY.rst b/src/connectedk8s/HISTORY.rst index 26167b8bc70..ef982c24ce4 100644 --- a/src/connectedk8s/HISTORY.rst +++ b/src/connectedk8s/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +0.2.2 +++++++ +* `az connectedk8s connect`: Added CLI params to support proxy. + 0.2.1 ++++++ * `az connectedk8s connect`: Added kubernetes distribution. diff --git a/src/connectedk8s/azext_connectedk8s/_help.py b/src/connectedk8s/azext_connectedk8s/_help.py index f2687611908..de251701dce 100644 --- a/src/connectedk8s/azext_connectedk8s/_help.py +++ b/src/connectedk8s/azext_connectedk8s/_help.py @@ -20,6 +20,9 @@ text: az connectedk8s connect -g resourceGroupName -n connectedClusterName - name: Onboard a connected kubernetes cluster by specifying the kubeconfig and kubecontext. text: az connectedk8s connect -g resourceGroupName -n connectedClusterName --kube-config /path/to/kubeconfig --kube-context kubeContextName + - name: Onboard a connected kubernetes cluster by specifying the https proxy, http proxy, no proxy settings. + text: az connectedk8s connect -g resourceGroupName -n connectedClusterName --https-proxy https://proxy-url --http-proxy http://proxy-url --no-proxy excludedIP,excludedCIDR,exampleCIDRfollowed,10.0.0.0/24 + """ helps['connectedk8s list'] = """ diff --git a/src/connectedk8s/azext_connectedk8s/_params.py b/src/connectedk8s/azext_connectedk8s/_params.py index e5e93d995fc..3c62118b6fd 100644 --- a/src/connectedk8s/azext_connectedk8s/_params.py +++ b/src/connectedk8s/azext_connectedk8s/_params.py @@ -18,6 +18,9 @@ def load_arguments(self, _): c.argument('cluster_name', options_list=['--name', '-n'], 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.') + c.argument('https_proxy', options_list=['--https-proxy'], help='Https proxy url to be used.') + c.argument('http_proxy', options_list=['--http-proxy'], help='Http proxy url to be used.') + c.argument('no_proxy', options_list=['--no-proxy'], help='List of urls/CIDRs for which proxy should not to be used.') with self.argument_context('connectedk8s list') as c: pass diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index eafb6b8460c..e3cea6ee2cc 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -65,7 +65,7 @@ # pylint: disable=too-many-branches # pylint: disable=too-many-statements # pylint: disable=line-too-long -def create_connectedk8s(cmd, client, resource_group_name, cluster_name, location=None, +def create_connectedk8s(cmd, client, resource_group_name, cluster_name, https_proxy=None, http_proxy=None, no_proxy=None, location=None, kube_config=None, kube_context=None, no_wait=False, tags=None): logger.warning("Ensure that you have the latest helm version installed before proceeding.") logger.warning("This operation might take a while...\n") @@ -86,6 +86,15 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, location # Removing quotes from kubeconfig path. This is necessary for windows OS. trim_kube_config(kube_config) + # Escaping comma, forward slash present in https proxy urls, needed for helm params. + https_proxy = escape_proxy_settings(https_proxy) + + # Escaping comma, forward slash present in http proxy urls, needed for helm params. + http_proxy = escape_proxy_settings(http_proxy) + + # Escaping comma, forward slash present in no proxy urls, needed for helm params. + no_proxy = escape_proxy_settings(no_proxy) + # Loading the kubeconfig file in kubernetes client configuration try: config.load_kube_config(config_file=kube_config, context=kube_context) @@ -250,6 +259,9 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, location "--set", "global.resourceName={}".format(cluster_name), "--set", "global.location={}".format(location), "--set", "global.tenantId={}".format(onboarding_tenant_id), + "--set", "global.httpsProxy={}".format(https_proxy), + "--set", "global.httpProxy={}".format(http_proxy), + "--set", "global.noProxy={}".format(no_proxy), "--set", "global.onboardingPrivateKey={}".format(private_key_pem), "--set", "systemDefaultValues.spnOnboarding=false", "--kubeconfig", kube_config, "--output", "json"] @@ -305,6 +317,14 @@ def trim_kube_config(kube_config): kube_config = kube_config[:-1] +def escape_proxy_settings(proxy_setting): + if proxy_setting is None: + return "" + proxy_setting = proxy_setting.replace(',', r'\,') + proxy_setting = proxy_setting.replace('/', r'\/') + return proxy_setting + + def check_kube_connection(configuration): api_instance = kube_client.NetworkingV1Api(kube_client.ApiClient(configuration)) try: