Skip to content

Commit

Permalink
Merge pull request #123 from sebastienc/work
Browse files Browse the repository at this point in the history
Fixing in-cluster setup.
  • Loading branch information
sebastienc committed Jun 6, 2018
2 parents c7059aa + d9f2577 commit accbe52
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions kubernetes/K8sConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import re
from os.path import expanduser, isfile
import logging
import os

import yaml
Expand Down Expand Up @@ -70,13 +71,16 @@ def __init__(self, kubeconfig=None, api_host=None, auth=None, cert=None,

# Default fallback host.
if self.api_host is None:
logging.debug('Overriding api host with: [ {0} ]'.format(DEFAULT_API_HOST))
self.api_host = DEFAULT_API_HOST

# Set defaults if not caught in kubeconfig file or environments.
if self.namespace is None:
logging.debug('Overriding namespace with: [ {0} ]'.format(DEFAULT_NAMESPACE))
self.namespace = DEFAULT_NAMESPACE

if self.version is None:
logging.debug('Overriding api version with: [ {0} ]'.format(DEFAULT_API_VERSION))
self.version = DEFAULT_API_VERSION

# Process overrides from arguments
Expand All @@ -85,7 +89,13 @@ def __init__(self, kubeconfig=None, api_host=None, auth=None, cert=None,
raise SyntaxError('K8sConfig: host: [ {0} ] is invalid.'.format(api_host))
schema_re = re.compile(r"^http[s]*")
if not schema_re.search(api_host):
api_host = "http://{0}".format(api_host)
https_port_re = re.compile(r"\:443$")
if not https_port_re:
logging.debug('Pre-pending http to api host [ {0} ] since port is not 443.'.format(self.api_host))
api_host = 'http://{0}'.format(api_host)
else:
logging.debug('Pre-pending https to api host [ {0} ] since port is 443.'.format(self.api_host))
api_host = 'https://{0}'.format(api_host)
self.api_host = api_host

if auth is not None:
Expand Down Expand Up @@ -148,7 +158,7 @@ def _from_cluster(self):
# Initialize the API server host
host = os.getenv(ENV_SERVICE_HOST, None)
port = os.getenv(ENV_SERVICE_PORT, None)
self.api_host = '{0}:{1}'.format(host, port)
self.api_host = 'https://{0}:{1}'.format(host, port)
# Initialize the token
if not isfile(SERVICE_ACCOUNT_TOKEN):
raise IOError('K8sConfig: Cannot find in-cluster token file [ {1} ]'.format(SERVICE_ACCOUNT_TOKEN))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def version():
with open(os.path.abspath(__file__).replace('setup.py', 'version.meta'), 'r') as v:
return v.read()
return v.read().replace('\n', '')


setup(
Expand Down
2 changes: 1 addition & 1 deletion version.meta
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.6.32
1.5.6.33

0 comments on commit accbe52

Please sign in to comment.