From 92c1d7da960f301a85d04d86e79663fca3f05670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 7 Nov 2021 12:47:05 +0100 Subject: [PATCH] Load in-cluster config is KUBECONFIG is not set --- README.md | 7 ++++--- src/runboat/k8s.py | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9523f97..9a0d335 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,10 @@ For running the controller (runboat itself): - Python 3.10 - `kubectl` -- A `KUBECONFIG` that provides access to the namespace where the builds are deployed, - with permissions to create and delete Service, Job, Deployment, Ingress, Secret and - ConfigMap resources. +- A `KUBECONFIG` or an in-cluster service account that provides access to the namespace + where the builds are deployed, with permissions to create and delete Service, Job, + Deployment, Ingress, Secret and ConfigMap resources as well as read and watch + Deployments and Jobs. - Some sort of reverse proxy to expose the REST API. The controller can be run outside the kubernetes cluster or deployed inside it, or even diff --git a/src/runboat/k8s.py b/src/runboat/k8s.py index 8fdaba3..35abbaa 100644 --- a/src/runboat/k8s.py +++ b/src/runboat/k8s.py @@ -1,5 +1,6 @@ import asyncio import logging +import os import shutil import subprocess import tempfile @@ -31,7 +32,10 @@ def _split_image_name_tag(img: str) -> tuple[str, str]: @sync_to_async def load_kube_config() -> None: - config.load_kube_config() + if "KUBECONFIG" in os.environ: + config.load_kube_config() + else: + config.load_incluster_config() @sync_to_async