Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update k8s tools to auto-detect API and namespace for deployed instances #143

Draft
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions chat_server/server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ def k8s_default_namespace(self) -> str:
def k8s_api(self):
if not self._k8s_api:
if _k8s_config_path := self.k8s_config.get("K8S_CONFIG_PATH"):
# Configured path may be used for local deployments
config.load_kube_config(_k8s_config_path)
self._k8s_api = client.AppsV1Api()
raise MalformedConfigurationException(
message="'K8S_CONFIG_PATH' property is missing in 'K8S_CONFIG'"
)
else:
# Deployed instances should discover/authenticate automatically
config.load_kube_config()
self._k8s_api = client.AppsV1Api()
return self._k8s_api

@property
Expand Down
10 changes: 8 additions & 2 deletions chat_server/server_utils/k8s_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ def restart_deployment(deployment_name: str, namespace: str = None):
:param namespace: name of the namespace
"""
if not namespace:
namespace = server_config.k8s_default_namespace
now = datetime.datetime.utcnow()
try:
with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace",
"r") as f:
namespace = f.read()
except Exception as e:
LOG.info(e)
namespace = server_config.k8s_default_namespace
now = datetime.datetime.now(datetime.timezone.utc)
now = str(now.isoformat() + "Z")
body = {
"spec": {
Expand Down
Loading