From be5b7889f954a101a9f62b6971329fffd0cb9ad2 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Fri, 11 Jan 2019 12:26:53 -0500 Subject: [PATCH] Do not load user kube config if path specified (#49952) --- .../49952-avoid-loading-kube-config-when-auth-given.yml | 2 ++ lib/ansible/plugins/inventory/k8s.py | 2 +- lib/ansible/plugins/inventory/openshift.py | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/49952-avoid-loading-kube-config-when-auth-given.yml diff --git a/changelogs/fragments/49952-avoid-loading-kube-config-when-auth-given.yml b/changelogs/fragments/49952-avoid-loading-kube-config-when-auth-given.yml new file mode 100644 index 00000000000..ce923206690 --- /dev/null +++ b/changelogs/fragments/49952-avoid-loading-kube-config-when-auth-given.yml @@ -0,0 +1,2 @@ +bugfixes: + - openshift inventory plugin - do not default create client if auth parameters were given. diff --git a/lib/ansible/plugins/inventory/k8s.py b/lib/ansible/plugins/inventory/k8s.py index b57adee2df6..d2a7b60badc 100644 --- a/lib/ansible/plugins/inventory/k8s.py +++ b/lib/ansible/plugins/inventory/k8s.py @@ -165,7 +165,6 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable, K8sAnsibleM self.fetch_objects(connections) def fetch_objects(self, connections): - client = self.get_api_client() if connections: if not isinstance(connections, list): @@ -184,6 +183,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable, K8sAnsibleM self.get_pods_for_namespace(client, name, namespace) self.get_services_for_namespace(client, name, namespace) else: + client = self.get_api_client() name = self.get_default_host_name(client.configuration.host) namespaces = self.get_available_namespaces(client) for namespace in namespaces: diff --git a/lib/ansible/plugins/inventory/openshift.py b/lib/ansible/plugins/inventory/openshift.py index 53d6b19bf90..6f5b170ff9c 100644 --- a/lib/ansible/plugins/inventory/openshift.py +++ b/lib/ansible/plugins/inventory/openshift.py @@ -123,9 +123,11 @@ class InventoryModule(K8sInventoryModule): def fetch_objects(self, connections): super(InventoryModule, self).fetch_objects(connections) - client = self.get_api_client() if connections: + if not isinstance(connections, list): + raise K8sInventoryException("Expecting connections to be a list.") + for connection in connections: client = self.get_api_client(**connection) name = connection.get('name', self.get_default_host_name(client.configuration.host)) @@ -136,6 +138,7 @@ class InventoryModule(K8sInventoryModule): for namespace in namespaces: self.get_routes_for_namespace(client, name, namespace) else: + client = self.get_api_client() name = self.get_default_host_name(client.configuration.host) namespaces = self.get_available_namespaces(client) for namespace in namespaces: