Skip to content

Commit

Permalink
Fix kubeconfig parameter when multiple config files are provided (#468)
Browse files Browse the repository at this point in the history
Fix kubeconfig parameter when multiple config files are provided

SUMMARY

#435

ISSUE TYPE


Bugfix Pull Request

Reviewed-by: Mike Graves <[email protected]>
  • Loading branch information
abikouo authored May 25, 2022
1 parent 3729b8b commit 193a0cb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fix kubeconfig parameter when multiple config files are provided (https://github.com/ansible-collections/kubernetes.core/issues/435).
18 changes: 13 additions & 5 deletions plugins/action/k8s_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import traceback
import os
from contextlib import contextmanager
import platform

from ansible.config.manager import ensure_type
from ansible.errors import (
Expand Down Expand Up @@ -50,6 +51,9 @@ def output(self):
return [self.remove_omit(d) for d in self.data]


ENV_KUBECONFIG_PATH_SEPARATOR = ";" if platform.system() == "Windows" else ":"


class ActionModule(ActionBase):

TRANSFERS_FILES = True
Expand Down Expand Up @@ -308,11 +312,15 @@ def get_kubeconfig(self, kubeconfig, remote_transport, new_module_args):
if not remote_transport:
# kubeconfig is local
# find in expected paths
kubeconfig = self._find_needle("files", kubeconfig)

# decrypt kubeconfig found
actual_file = self._loader.get_real_file(kubeconfig, decrypt=True)
new_module_args["kubeconfig"] = actual_file
configs = []
for config in kubeconfig.split(ENV_KUBECONFIG_PATH_SEPARATOR):
config = self._find_needle("files", config)

# decrypt kubeconfig found
configs.append(self._loader.get_real_file(config, decrypt=True))
new_module_args["kubeconfig"] = ENV_KUBECONFIG_PATH_SEPARATOR.join(
configs
)

elif isinstance(kubeconfig, dict):
new_module_args["kubeconfig"] = kubeconfig
Expand Down
1 change: 1 addition & 0 deletions plugins/doc_fragments/k8s_auth_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ModuleDocFragment(object):
options are provided, the Kubernetes client will attempt to load the default
configuration file from I(~/.kube/config). Can also be specified via K8S_AUTH_KUBECONFIG environment
variable.
- Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.
- The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.
type: raw
context:
Expand Down

0 comments on commit 193a0cb

Please sign in to comment.