From 83397287f5bfb7d79154286ab17b85d77cf7920d Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Wed, 8 Jan 2020 22:31:14 +0800 Subject: [PATCH 1/9] switch to use the kube proxy to open the dashboard. --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index f73b4b3e6ed..8533e38b3fd 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1563,9 +1563,7 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, wait_then_open_async(proxy_url) try: try: - subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "--namespace", "kube-system", - "port-forward", "--address", listen_address, dashboard_pod, - "{0}:{1}".format(listen_port, dashboard_port)], stderr=subprocess.STDOUT) + subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "proxy", stderr=subprocess.STDOUT) except subprocess.CalledProcessError as err: if err.output.find(b'unknown flag: --address'): if listen_address != '127.0.0.1': From 1157ded2285c6bbd12a52024315d3cf4bf8acdbe Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Thu, 9 Jan 2020 14:18:52 +0800 Subject: [PATCH 2/9] fix --- .../azure/cli/command_modules/acs/custom.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index 8533e38b3fd..dc6f8c42b21 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1543,8 +1543,10 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, protocol = 'https' else: protocol = 'http' - + proxy_url = '{0}://{1}:{2}/'.format(protocol, listen_address, listen_port) + uiURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy'.format(proxy_url,protocol) + # launch kubectl port-forward locally to access the remote dashboard if in_cloud_console(): # TODO: better error handling here. @@ -1560,17 +1562,12 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, logger.warning('Press CTRL+C to close the tunnel...') if not disable_browser: - wait_then_open_async(proxy_url) + wait_then_open_async(uiURL) try: try: subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "proxy", stderr=subprocess.STDOUT) except subprocess.CalledProcessError as err: - if err.output.find(b'unknown flag: --address'): - if listen_address != '127.0.0.1': - logger.warning('"--address" is only supported in kubectl v1.13 and later.') - logger.warning('The "--listen-address" argument will be ignored.') - subprocess.call(["kubectl", "--kubeconfig", browse_path, "--namespace", "kube-system", - "port-forward", dashboard_pod, "{0}:{1}".format(listen_port, dashboard_port)]) + logger.warning("error occured when setup the proxy: %s", err) except KeyboardInterrupt: # Let command processing finish gracefully after the user presses [Ctrl+C] pass From 1d357abdd16092a702b131dd08099f683caaacc4 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Thu, 9 Jan 2020 14:19:11 +0800 Subject: [PATCH 3/9] fix --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index dc6f8c42b21..146e9c70109 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1547,7 +1547,7 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, proxy_url = '{0}://{1}:{2}/'.format(protocol, listen_address, listen_port) uiURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy'.format(proxy_url,protocol) - # launch kubectl port-forward locally to access the remote dashboard + # launch kubectl proxy locally to access the remote dashboard if in_cloud_console(): # TODO: better error handling here. response = requests.post('http://localhost:8888/openport/{0}'.format(listen_port)) From 83616f8aa93021d9720061a3d92f0bd27de42437 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Thu, 9 Jan 2020 15:32:45 +0800 Subject: [PATCH 4/9] fix --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index 146e9c70109..604ba969d1b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1544,10 +1544,9 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, else: protocol = 'http' - proxy_url = '{0}://{1}:{2}/'.format(protocol, listen_address, listen_port) - uiURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy'.format(proxy_url,protocol) - - # launch kubectl proxy locally to access the remote dashboard + proxy_url = 'http://{1}:{2}/'.format(protocol, listen_address, listen_port) + dashboardURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy'.format(proxy_url,protocol) + # launch kubectl port-forward locally to access the remote dashboard if in_cloud_console(): # TODO: better error handling here. response = requests.post('http://localhost:8888/openport/{0}'.format(listen_port)) @@ -1562,10 +1561,10 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, logger.warning('Press CTRL+C to close the tunnel...') if not disable_browser: - wait_then_open_async(uiURL) + wait_then_open_async(dashboardURL) try: try: - subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "proxy", stderr=subprocess.STDOUT) + subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "proxy"], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as err: logger.warning("error occured when setup the proxy: %s", err) except KeyboardInterrupt: From 61c653cc97a2b19fb0c4f652dfa577d8b6098558 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Thu, 9 Jan 2020 20:51:59 +0800 Subject: [PATCH 5/9] fix --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index 604ba969d1b..e25653d2bc0 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1543,9 +1543,10 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, protocol = 'https' else: protocol = 'http' - - proxy_url = 'http://{1}:{2}/'.format(protocol, listen_address, listen_port) - dashboardURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy'.format(proxy_url,protocol) + + proxy_url = 'http://{1}:{2}/'.format(listen_address, listen_port) + dashboardURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy' + .format(proxy_url, protocol) # launch kubectl port-forward locally to access the remote dashboard if in_cloud_console(): # TODO: better error handling here. From 8fbca67cec5ab7c8dc9bb70d37dd0bfffc4245bc Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Thu, 9 Jan 2020 21:01:19 +0800 Subject: [PATCH 6/9] fix --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index e25653d2bc0..1296c6084d0 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1545,8 +1545,8 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, protocol = 'http' proxy_url = 'http://{1}:{2}/'.format(listen_address, listen_port) - dashboardURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy' - .format(proxy_url, protocol) + dashboardURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy'.format(proxy_url, + protocol) # launch kubectl port-forward locally to access the remote dashboard if in_cloud_console(): # TODO: better error handling here. From 97959ac96dac97b170185946632ec0607c802b30 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Fri, 10 Jan 2020 21:12:20 +0800 Subject: [PATCH 7/9] fix --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index 1296c6084d0..0c1c5f48491 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1544,7 +1544,7 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, else: protocol = 'http' - proxy_url = 'http://{1}:{2}/'.format(listen_address, listen_port) + proxy_url = 'http://{0}:{1}/'.format(listen_address, listen_port) dashboardURL = '{0}/api/v1/namespaces/kube-system/services/{1}:kubernetes-dashboard:/proxy'.format(proxy_url, protocol) # launch kubectl port-forward locally to access the remote dashboard From 8472106dc4ffeccdd22011daaa6469cb277d2618 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Tue, 14 Jan 2020 11:25:32 +0800 Subject: [PATCH 8/9] fix --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index 0c1c5f48491..b91d291b297 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1565,9 +1565,13 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, wait_then_open_async(dashboardURL) try: try: - subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "proxy"], stderr=subprocess.STDOUT) + subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "proxy", "--address", listen_address, "--port", listen_port], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as err: - logger.warning("error occured when setup the proxy: %s", err) + if err.output.find(b'unknown flag: --address'): + if listen_address != '127.0.0.1': + logger.warning('"--address" is only supported in kubectl v1.13 and later.') + logger.warning('The "--listen-address" argument will be ignored.') + subprocess.call(["kubectl", "--kubeconfig", browse_path, "proxy", "--port", listen_port]) except KeyboardInterrupt: # Let command processing finish gracefully after the user presses [Ctrl+C] pass From 6f364f1e1e29190b56ca0859bb9a608f29985719 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Tue, 14 Jan 2020 12:13:33 +0800 Subject: [PATCH 9/9] fix --- src/azure-cli/azure/cli/command_modules/acs/custom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/custom.py b/src/azure-cli/azure/cli/command_modules/acs/custom.py index b91d291b297..60b68affac6 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/custom.py +++ b/src/azure-cli/azure/cli/command_modules/acs/custom.py @@ -1565,7 +1565,8 @@ def aks_browse(cmd, client, resource_group_name, name, disable_browser=False, wait_then_open_async(dashboardURL) try: try: - subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "proxy", "--address", listen_address, "--port", listen_port], stderr=subprocess.STDOUT) + subprocess.check_output(["kubectl", "--kubeconfig", browse_path, "proxy", "--address", + listen_address, "--port", listen_port], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as err: if err.output.find(b'unknown flag: --address'): if listen_address != '127.0.0.1':