From 13d5d86ca89035b9f596032e7a34f3cc33bf8f18 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Wed, 16 Aug 2017 15:48:32 +0200 Subject: [PATCH] Don't require a config file for k8s/openshift It's possible to interact with the Kubernetes/OpenShift API without auth or even without a configuration file. This patch allows for creating an ApiClient instance without loading it from a configuration file if it is not set. --- openshift/helper/kubernetes.py | 3 +++ openshift/helper/openshift.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/openshift/helper/kubernetes.py b/openshift/helper/kubernetes.py index 50727296..531bf466 100644 --- a/openshift/helper/kubernetes.py +++ b/openshift/helper/kubernetes.py @@ -4,6 +4,7 @@ from kubernetes import config from kubernetes.client import models as k8s_models from kubernetes.client import apis as k8s_apis +from kubernetes.client import ApiClient, ConfigurationObject from . import VERSION_RX from .base import BaseObjectHelper @@ -13,6 +14,8 @@ class KubernetesObjectHelper(BaseObjectHelper): @staticmethod def client_from_config(config_file, context): + if not config_file: + return ApiClient(config=ConfigurationObject()) return config.new_client_from_config(config_file, context) @classmethod diff --git a/openshift/helper/openshift.py b/openshift/helper/openshift.py index 5b09fd07..b1a91103 100644 --- a/openshift/helper/openshift.py +++ b/openshift/helper/openshift.py @@ -12,6 +12,7 @@ from .. import config from ..client import models as openshift_models from ..client import apis as openshift_apis +from ..client import ApiClient, ConfigurationObject from .base import BaseObjectHelper from .exceptions import OpenShiftException @@ -19,6 +20,8 @@ class OpenShiftObjectHelper(BaseObjectHelper): @staticmethod def client_from_config(config_file, context): + if not config_file: + return ApiClient(config=ConfigurationObject()) return config.new_client_from_config(config_file, context) @classmethod