perf: k8s tree error msg (#9472)

Co-authored-by: feng <1304903146@qq.com>
pull/9473/head
fit2bot 2 years ago committed by GitHub
parent ab76d8cce0
commit e3d1474b9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from urllib3.exceptions import MaxRetryError
from urllib.parse import urlencode
from urllib3.exceptions import MaxRetryError, LocationParseError
from kubernetes import client
from kubernetes.client import api_client
@ -8,7 +8,7 @@ from kubernetes.client.api import core_v1_api
from kubernetes.client.exceptions import ApiException
from common.utils import get_logger
from common.exceptions import JMSException
from ..const import CloudTypes, Category
logger = get_logger(__file__)
@ -58,15 +58,21 @@ class KubernetesClient:
api = self.get_api()
try:
ret = api.list_pod_for_all_namespaces(watch=False, _request_timeout=(3, 3))
except LocationParseError as e:
logger.warning("Kubernetes API request url error: {}".format(e))
raise JMSException(code='k8s_tree_error', detail=e)
except MaxRetryError:
logger.warning('Kubernetes connection timed out')
return
msg = "Kubernetes API request timeout"
logger.warning(msg)
raise JMSException(code='k8s_tree_error', detail=msg)
except ApiException as e:
if e.status == 401:
logger.warning('Kubernetes User not authenticated')
msg = "Kubernetes API request unauthorized"
logger.warning(msg)
else:
logger.warning(e)
return
msg = e
logger.warning(msg)
raise JMSException(code='k8s_tree_error', detail=msg)
data = {}
for i in ret.items:
namespace = i.metadata.namespace

@ -17,7 +17,7 @@ class ConnectionTokenSerializer(OrgResourceModelSerializerMixin):
label=_("Input secret"), max_length=40960, required=False, allow_blank=True
)
from_ticket_info = serializers.SerializerMethodField(label=_("Ticket info"))
actions = ActionChoicesField()
actions = ActionChoicesField(read_only=True, label=_("Actions"))
class Meta:
model = ConnectionToken

Loading…
Cancel
Save