diff --git a/apps/assets/utils/k8s.py b/apps/assets/utils/k8s.py index 0ed17835f..8e12e8de8 100644 --- a/apps/assets/utils/k8s.py +++ b/apps/assets/utils/k8s.py @@ -4,6 +4,7 @@ from urllib.parse import urlencode from kubernetes import client from kubernetes.client import api_client from kubernetes.client.api import core_v1_api +from kubernetes.client.exceptions import ApiException from common.utils import get_logger from ..const import CloudTypes, Category @@ -65,9 +66,13 @@ class KubernetesClient: proxy_url = cls.get_proxy_url(asset) k8s = cls(k8s_url, secret, proxy=proxy_url) func_name = f'get_{tp}s' + data = [] if hasattr(k8s, func_name): - return getattr(k8s, func_name)(*args) - return [] + try: + data = getattr(k8s, func_name)(*args) + except ApiException as e: + logger.error(e.reason) + return data class KubernetesTree: