6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-12-04 19:03:39 +00:00

Merge remote-tracking branch 'origin/master' into nightly

This commit is contained in:
Overhang.IO 2023-06-01 14:10:29 +00:00
commit e73e13a6e9
2 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1 @@
- [Feature] Add support for loading in-cluster config when running inside a pod. In certain scenarios, Tutor may operate within a pod that has access to a cluster through role binding and a service account. In these instances, the ./kube/config file may not be present, but kubectl commands can still execute without any problems. (by @CodeWithEmad)

View File

@ -1,3 +1,4 @@
import os
from datetime import datetime
from time import sleep
from typing import Any, Iterable, List, Optional, Type
@ -26,7 +27,20 @@ class K8sClients:
# pylint: disable=import-outside-toplevel
from kubernetes import client, config
config.load_kube_config()
if os.path.exists(config.kube_config.KUBE_CONFIG_DEFAULT_LOCATION):
# found the kubeconfig file, let's load it!
config.load_kube_config()
elif (
config.incluster_config.SERVICE_HOST_ENV_NAME in os.environ
and config.incluster_config.SERVICE_PORT_ENV_NAME in os.environ
):
# We are running inside a cluster, let's load the in-cluster configuration.
config.load_incluster_config()
else:
raise exceptions.TutorError(
f"there is no Kubernetes configuration file located in {config.kube_config.KUBE_CONFIG_DEFAULT_LOCATION}, and the service environment variables {config.incluster_config.SERVICE_HOST_ENV_NAME} and {config.incluster_config.SERVICE_PORT_ENV_NAME} have not been defined. To connect to a cluster, please configure your host appropriately."
)
self._batch_api = None
self._core_api = None
self._client = client