Skip to content

Commit

Permalink
start proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
paigerube14 committed Nov 9, 2022
1 parent ff031da commit 1e68b13
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions arcaflow_plugin_kill_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,20 +16,39 @@
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:
raise Exception(
"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)


Expand Down

0 comments on commit 1e68b13

Please sign in to comment.