Skip to content

Commit 3879a69

Browse files
committed
fix: failed to detect kuberentes incluster
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent d96987c commit 3879a69

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

gpustack_runtime/deployer/docker.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22

3+
import contextlib
34
import json
45
import logging
6+
import os
57
import socket
68
import sys
79
from dataclasses import dataclass, field
@@ -287,10 +289,15 @@ def _get_client() -> docker.DockerClient | None:
287289
client = None
288290

289291
try:
290-
if Path("/var/run/docker.sock").exists():
291-
client = docker.DockerClient(base_url="unix://var/run/docker.sock")
292-
else:
293-
client = docker.from_env()
292+
with (
293+
Path(os.devnull).open("w") as dev_null,
294+
contextlib.redirect_stdout(dev_null),
295+
contextlib.redirect_stderr(dev_null),
296+
):
297+
if Path("/var/run/docker.sock").exists():
298+
client = docker.DockerClient(base_url="unix://var/run/docker.sock")
299+
else:
300+
client = docker.from_env()
294301
except docker.errors.DockerException:
295302
if logger.isEnabledFor(logging.DEBUG):
296303
logger.exception("Failed to get Docker client")

gpustack_runtime/deployer/kuberentes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import hashlib
55
import logging
6+
import os
67
import socket
78
from dataclasses import dataclass, field
89
from enum import Enum
@@ -300,9 +301,14 @@ def _get_client() -> kubernetes.client.ApiClient | None:
300301
client = None
301302

302303
try:
303-
kubernetes.config.load_kube_config()
304-
client = kubernetes.client.ApiClient()
305-
client.user_agent = "gpustack/runtime"
304+
with (
305+
Path(os.devnull).open("w") as dev_null,
306+
contextlib.redirect_stdout(dev_null),
307+
contextlib.redirect_stderr(dev_null),
308+
):
309+
kubernetes.config.load_config()
310+
client = kubernetes.client.ApiClient()
311+
client.user_agent = "gpustack/runtime"
306312
except kubernetes.config.config_exception.ConfigException:
307313
if logger.isEnabledFor(logging.DEBUG):
308314
logger.exception("Failed to get Kubernetes client")

gpustack_runtime/detector/pyamdsmi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pathlib import Path
99

1010
try:
11-
with contextlib.redirect_stdout(Path(os.devnull).open("w")):
11+
with Path(os.devnull).open("w") as dev_null, contextlib.redirect_stdout(dev_null):
1212
from amdsmi import *
1313
except (ImportError, KeyError, OSError):
1414

0 commit comments

Comments
 (0)