Skip to content

Commit

Permalink
moving incluster config load from start to end
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Haigh <[email protected]>
  • Loading branch information
MichaelHaigh committed Jan 29, 2024
1 parent 1d80843 commit 98de113
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions astraSDK/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,24 @@ class KubeCommon(BaseCommon):
def __init__(self, config_context=None):
super().__init__()

# First try loading from incluster (a local pod)
# Setup the config_file and context based on the config_context input
config_file, context = None, None
if config_context and ":" in config_context:
config_file, context = tuple(config_context.split(":"))
config_file = None if config_file == "None" else config_file
elif config_context:
config_file = config_context
try:
self.api_client = kubernetes.client.ApiClient(
configuration=kubernetes.config.load_incluster_config()
# Create the api_client
self.api_client = kubernetes.config.new_client_from_config(
config_file=config_file, context=context
)

# If that fails, then it's a "normal" kubeconfig+context environment
# If that fails, then try an incluster config
except kubernetes.config.config_exception.ConfigException as err:
# Setup the config_file and context based on the config_context input
config_file, context = None, None
if config_context and ":" in config_context:
config_file, context = tuple(config_context.split(":"))
config_file = None if config_file == "None" else config_file
elif config_context:
config_file = config_context
try:
# Create the api_client
self.api_client = kubernetes.config.new_client_from_config(
config_file=config_file, context=context
self.api_client = kubernetes.client.ApiClient(
configuration=kubernetes.config.load_incluster_config()
)
except kubernetes.config.config_exception.ConfigException:
self.printError(f"{err}\n")
Expand Down

0 comments on commit 98de113

Please sign in to comment.