Skip to content

Commit

Permalink
Make CA certificate optional in config (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
seleznev authored and dekhtyarev committed Aug 28, 2019
1 parent 733104f commit df2667b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Configure checkout for https://github.com/2gis/k8s-handle-example.git and specif
Also you need to setup next env vars:
* K8S_NAMESPACE
* K8S_MASTER_URI
* K8S_CA_BASE64
* K8S_CA_BASE64 (optional)
* K8S_TOKEN

use image 2gis/k8s-handle:<version or latest>
Expand Down
6 changes: 4 additions & 2 deletions k8s_handle/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def k8s_namespace_default(self, kubeconfig_namespace=None):
def k8s_client_configuration(self):
for parameter, value in {
KEY_K8S_MASTER_URI: self._k8s_master_uri(),
KEY_K8S_CA_BASE64: self._k8s_ca_base64(),
KEY_K8S_TOKEN: self._k8s_token()
}.items():
if value:
Expand All @@ -59,7 +58,10 @@ def k8s_client_configuration(self):

configuration = client.Configuration()
configuration.host = self._k8s_master_uri()
configuration.ssl_ca_cert = write_file_tmp(b64decode(self._k8s_ca_base64()).encode('utf-8'))

if self._k8s_ca_base64():
configuration.ssl_ca_cert = write_file_tmp(b64decode(self._k8s_ca_base64()).encode('utf-8'))

configuration.api_key = {"authorization": "Bearer " + self._k8s_token()}
configuration.debug = self._k8s_handle_debug()
return configuration
Expand Down
6 changes: 0 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@ def test_k8s_client_configuration_missing_uri(self):
with self.assertRaises(RuntimeError):
evaluator.k8s_client_configuration()

def test_k8s_client_configuration_missing_k8s_ca(self):
evaluator = PriorityEvaluator({KEY_K8S_MASTER_URI: VALUE_CLI, KEY_K8S_TOKEN: VALUE_CLI}, {}, {})

with self.assertRaises(RuntimeError):
evaluator.k8s_client_configuration()

def test_k8s_client_configuration_missing_token(self):
evaluator = PriorityEvaluator({
KEY_K8S_MASTER_URI: VALUE_CLI,
Expand Down

0 comments on commit df2667b

Please sign in to comment.