Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit 8b630b3

Browse files
committed
KubeConfig.from_env() convenience function
1 parent 9197ab6 commit 8b630b3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pykube/config.py

+15
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ def from_file(cls, filename=None, **kwargs):
8181
self.filename = filename
8282
return self
8383

84+
@classmethod
85+
def from_env(cls):
86+
"""
87+
Convenience function to create an instance of KubeConfig from the current environment.
88+
89+
First tries to use in-cluster ServiceAccount, then tries default ~/.kube/config (or KUBECONFIG)
90+
"""
91+
try:
92+
# running in cluster
93+
config = cls.from_service_account()
94+
except FileNotFoundError:
95+
# not running in cluster => load local ~/.kube/config
96+
config = cls.from_file()
97+
return config
98+
8499
@classmethod
85100
def from_url(cls, url, **kwargs):
86101
"""

0 commit comments

Comments
 (0)