Skip to content

Commit 0d1c30a

Browse files
trey-staffordmanning-ncsamfisher87benclifford
authored
Use incluster config fallback for KubernetesProvider (#3357)
The KubernetesProvider now falls back to loading config in-cluster if a kube-config file is not found. This allows in-cluster submission of parsl jobs. See kubernetes-client/python#1005 for a good description of the issue. Co-authored-by: T. Andrew Manning <[email protected]> Co-authored-by: Matt Fisher <[email protected]> Co-authored-by: Ben Clifford <[email protected]>
1 parent 22128a0 commit 0d1c30a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

parsl/providers/kubernetes/kube.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,26 @@ def __init__(self,
105105
if not _kubernetes_enabled:
106106
raise OptionalModuleMissing(['kubernetes'],
107107
"Kubernetes provider requires kubernetes module and config.")
108-
config.load_kube_config()
108+
try:
109+
config.load_kube_config()
110+
except config.config_exception.ConfigException:
111+
# `load_kube_config` assumes a local kube-config file, and fails if not
112+
# present, raising:
113+
#
114+
# kubernetes.config.config_exception.ConfigException: Invalid
115+
# kube-config file. No configuration found.
116+
#
117+
# Since running a parsl driver script on a kubernetes cluster is a common
118+
# pattern to enable worker-interchange communication, this enables an
119+
# in-cluster config to be loaded if a kube-config file isn't found.
120+
#
121+
# Based on: https://github.com/kubernetes-client/python/issues/1005
122+
try:
123+
config.load_incluster_config()
124+
except config.config_exception.ConfigException:
125+
raise config.config_exception.ConfigException(
126+
"Failed to load both kube-config file and in-cluster configuration."
127+
)
109128

110129
self.namespace = namespace
111130
self.image = image

0 commit comments

Comments
 (0)