Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Merge 10273f2 into f838a61
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Mar 3, 2019
2 parents f838a61 + 10273f2 commit 0607ad3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pykube/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import datetime
import json
import posixpath
import re
import shlex
import subprocess

Expand All @@ -23,10 +22,11 @@

from .exceptions import HTTPError
from .utils import jsonpath_installed, jsonpath_parse
from .config import KubeConfig

from . import __version__

_ipv4_re = re.compile(r"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")
DEFAULT_HTTP_TIMEOUT = 10 # seconds


class KubernetesHTTPAdapter(requests.adapters.HTTPAdapter):
Expand All @@ -35,7 +35,7 @@ class KubernetesHTTPAdapter(requests.adapters.HTTPAdapter):
# it can be overwritten in unit tests to mock the actual HTTP calls
_do_send = requests.adapters.HTTPAdapter.send

def __init__(self, kube_config, **kwargs):
def __init__(self, kube_config: KubeConfig, **kwargs):
self.kube_config = kube_config

super().__init__(**kwargs)
Expand Down Expand Up @@ -150,14 +150,15 @@ class HTTPClient(object):
Client for interfacing with the Kubernetes API.
"""

def __init__(self, config):
def __init__(self, config: KubeConfig, timeout: float = DEFAULT_HTTP_TIMEOUT):
"""
Creates a new instance of the HTTPClient.
:Parameters:
- `config`: The configuration instance
"""
self.config = config
self.timeout = timeout
self.url = self.config.cluster["server"]

session = requests.Session()
Expand Down Expand Up @@ -193,7 +194,7 @@ def resource_list(self, api_version):
setattr(self, cached_attr, r.json())
return getattr(self, cached_attr)

def get_kwargs(self, **kwargs):
def get_kwargs(self, **kwargs) -> dict:
"""
Creates a full URL to request based on arguments.
Expand Down Expand Up @@ -228,6 +229,9 @@ def get_kwargs(self, **kwargs):
url = url[1:]
bits.append(url)
kwargs["url"] = self.url + posixpath.join(*bits)
if 'timeout' not in kwargs:
# apply default HTTP timeout
kwargs['timeout'] = self.timeout
return kwargs

def raise_for_status(self, resp):
Expand Down

0 comments on commit 0607ad3

Please sign in to comment.