Skip to content

Commit

Permalink
proxy urlparse
Browse files Browse the repository at this point in the history
  • Loading branch information
paigerube14 committed Dec 1, 2022
1 parent ffb5fc5 commit a1226d4
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions kraken/kubernetes/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import time
import urllib3
import os
from urllib.parse import urlparse

from kubernetes import client, config, utils, watch
from kubernetes.client.rest import ApiException
from kubernetes.dynamic.client import DynamicClient
from kubernetes.stream import stream

from ..kubernetes.resources import (PVC, ChaosEngine, ChaosResult, Container,
Expand All @@ -16,8 +16,6 @@

kraken_node_name = ""

urllib3.disable_warnings()


def initialize_clients(kubeconfig_path):
"""Load kubeconfig and initialize kubernetes python client"""
Expand All @@ -33,20 +31,18 @@ def initialize_clients(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

config.load_kube_config(kubeconfig_path, persist_config=True, client_configuration=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)
client_config.proxy_headers = urllib3.util.make_headers(proxy_basic_auth=auth_string)

client.Configuration.set_default(client_config)
cli = client.CoreV1Api()
Expand Down

0 comments on commit a1226d4

Please sign in to comment.