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
4 changes: 4 additions & 0 deletions src/connectedk8s/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = """
Expand Down
3 changes: 3 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion src/connectedk8s/azext_connectedk8s/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down