From 1e68b13ee0014adf39f04307dde6fd32ccd5c5df Mon Sep 17 00:00:00 2001 From: Paige Rubendall Date: Thu, 3 Nov 2022 10:32:16 -0400 Subject: [PATCH 1/3] start proxy --- arcaflow_plugin_kill_pod.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/arcaflow_plugin_kill_pod.py b/arcaflow_plugin_kill_pod.py index 664ddbf..83b4774 100755 --- a/arcaflow_plugin_kill_pod.py +++ b/arcaflow_plugin_kill_pod.py @@ -4,6 +4,9 @@ import sys import time import typing +import os +import urllib3 + from dataclasses import dataclass, field from datetime import datetime from traceback import format_exc @@ -13,9 +16,23 @@ from kubernetes.client import ApiException, V1DeleteOptions, V1Pod, V1PodList +urllib3.disable_warnings() + + def setup_kubernetes(kubeconfig_path): if kubeconfig_path is None: kubeconfig_path = config.KUBE_CONFIG_DEFAULT_LOCATION + """Initialize object and create clients from specified kubeconfig""" + client_config = client.Configuration() + http_proxy = os.getenv("http_proxy", None) + """Proxy has auth header""" + if http_proxy and "@" in http_proxy: + proxy_auth = http_proxy.split("@")[0].split("//")[1] + user_pass = proxy_auth.split(":")[0] + client_config.username = user_pass[0] + client_config.password = user_pass[1] + client_config.ssl_ca_cert = False + client_config.verify_ssl = False kubeconfig = config.kube_config.KubeConfigMerger(kubeconfig_path) if kubeconfig.config is None: @@ -23,10 +40,15 @@ def setup_kubernetes(kubeconfig_path): "Invalid kube-config file: %s. " "No configuration found." % kubeconfig_path ) loader = config.kube_config.KubeConfigLoader( - config_dict=kubeconfig.config, + config_dict=kubeconfig.config, config_persister=True ) - client_config = client.Configuration() loader.load_and_set(client_config) + proxy_url = http_proxy + if proxy_url: + client_config.proxy = proxy_url + if proxy_auth: + client_config.proxy_headers = urllib3.util.make_headers(proxy_basic_auth=proxy_auth) + return client.ApiClient(configuration=client_config) From 606289c6a182e63cb523175bc8fed49321c6ba83 Mon Sep 17 00:00:00 2001 From: Paige Rubendall Date: Tue, 15 Nov 2022 16:01:11 -0500 Subject: [PATCH 2/3] updating cofiguration for proxy --- arcaflow_plugin_kill_pod.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/arcaflow_plugin_kill_pod.py b/arcaflow_plugin_kill_pod.py index 83b4774..d1eab0f 100755 --- a/arcaflow_plugin_kill_pod.py +++ b/arcaflow_plugin_kill_pod.py @@ -6,6 +6,7 @@ import typing import os import urllib3 +from urllib.parse import urlparse from dataclasses import dataclass, field from datetime import datetime @@ -16,8 +17,6 @@ from kubernetes.client import ApiException, V1DeleteOptions, V1Pod, V1PodList -urllib3.disable_warnings() - def setup_kubernetes(kubeconfig_path): if kubeconfig_path is None: @@ -27,12 +26,12 @@ def setup_kubernetes(kubeconfig_path): http_proxy = os.getenv("http_proxy", None) """Proxy has auth header""" if http_proxy and "@" in http_proxy: - proxy_auth = http_proxy.split("@")[0].split("//")[1] - user_pass = proxy_auth.split(":")[0] - client_config.username = user_pass[0] - client_config.password = user_pass[1] - client_config.ssl_ca_cert = False - client_config.verify_ssl = False + proxy_auth = urlparse(http_proxy) + auth_string = proxy_auth.username + ":" + proxy_auth.password + client_config.username = proxy_auth.username + client_config.password = proxy_auth.password + + kubeconfig = config.kube_config.KubeConfigMerger(kubeconfig_path) if kubeconfig.config is None: @@ -47,7 +46,7 @@ def setup_kubernetes(kubeconfig_path): if proxy_url: client_config.proxy = proxy_url if proxy_auth: - client_config.proxy_headers = urllib3.util.make_headers(proxy_basic_auth=proxy_auth) + client_config.proxy_headers = urllib3.util.make_headers(proxy_basic_auth=auth_string) return client.ApiClient(configuration=client_config) From a4e5df4b807137aebaf84e1f637b296836c9c500 Mon Sep 17 00:00:00 2001 From: Paige Rubendall Date: Tue, 15 Nov 2022 16:05:25 -0500 Subject: [PATCH 3/3] spacing and carpenter fixes --- arcaflow_plugin_kill_pod.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arcaflow_plugin_kill_pod.py b/arcaflow_plugin_kill_pod.py index d1eab0f..dfe32f9 100755 --- a/arcaflow_plugin_kill_pod.py +++ b/arcaflow_plugin_kill_pod.py @@ -17,7 +17,6 @@ from kubernetes.client import ApiException, V1DeleteOptions, V1Pod, V1PodList - def setup_kubernetes(kubeconfig_path): if kubeconfig_path is None: kubeconfig_path = config.KUBE_CONFIG_DEFAULT_LOCATION @@ -27,11 +26,10 @@ def setup_kubernetes(kubeconfig_path): """Proxy has auth header""" if http_proxy and "@" in http_proxy: proxy_auth = urlparse(http_proxy) - auth_string = proxy_auth.username + ":" + proxy_auth.password + auth_string = proxy_auth.username + ":" + proxy_auth.password client_config.username = proxy_auth.username client_config.password = proxy_auth.password - kubeconfig = config.kube_config.KubeConfigMerger(kubeconfig_path) if kubeconfig.config is None: