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

Commit

Permalink
KubeConfig.from_env() convenience function
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Sep 3, 2019
1 parent 9197ab6 commit 8b630b3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pykube/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ def from_file(cls, filename=None, **kwargs):
self.filename = filename
return self

@classmethod
def from_env(cls):
"""
Convenience function to create an instance of KubeConfig from the current environment.
First tries to use in-cluster ServiceAccount, then tries default ~/.kube/config (or KUBECONFIG)
"""
try:
# running in cluster
config = cls.from_service_account()
except FileNotFoundError:
# not running in cluster => load local ~/.kube/config
config = cls.from_file()
return config

@classmethod
def from_url(cls, url, **kwargs):
"""
Expand Down

0 comments on commit 8b630b3

Please sign in to comment.