|
|
@ -18,13 +18,15 @@ logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KubernetesClient:
|
|
|
|
class KubernetesClient:
|
|
|
|
def __init__(self, url, token):
|
|
|
|
def __init__(self, url, token, proxy=None):
|
|
|
|
self.url = url
|
|
|
|
self.url = url
|
|
|
|
self.token = token
|
|
|
|
self.token = token
|
|
|
|
|
|
|
|
self.proxy = proxy
|
|
|
|
|
|
|
|
|
|
|
|
def get_api(self):
|
|
|
|
def get_api(self):
|
|
|
|
configuration = client.Configuration()
|
|
|
|
configuration = client.Configuration()
|
|
|
|
configuration.host = self.url
|
|
|
|
configuration.host = self.url
|
|
|
|
|
|
|
|
configuration.proxy = self.proxy
|
|
|
|
configuration.verify_ssl = False
|
|
|
|
configuration.verify_ssl = False
|
|
|
|
configuration.api_key = {"authorization": "Bearer " + self.token}
|
|
|
|
configuration.api_key = {"authorization": "Bearer " + self.token}
|
|
|
|
c = api_client.ApiClient(configuration=configuration)
|
|
|
|
c = api_client.ApiClient(configuration=configuration)
|
|
|
@ -81,11 +83,23 @@ class KubernetesClient:
|
|
|
|
data[namespace] = [pod_info, ]
|
|
|
|
data[namespace] = [pod_info, ]
|
|
|
|
return data
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@classmethod
|
|
|
|
def get_kubernetes_data(app_id, username):
|
|
|
|
def get_proxy_url(cls, asset):
|
|
|
|
|
|
|
|
if not asset.domain:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gateway = asset.domain.select_gateway()
|
|
|
|
|
|
|
|
if not gateway:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return f'{gateway.address}:{gateway.port}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
|
|
def get_kubernetes_data(cls, app_id, username):
|
|
|
|
asset = get_object_or_404(Asset, id=app_id)
|
|
|
|
asset = get_object_or_404(Asset, id=app_id)
|
|
|
|
account = get_object_or_404(Account, asset=asset, username=username)
|
|
|
|
account = get_object_or_404(Account, asset=asset, username=username)
|
|
|
|
k8s = KubernetesClient(asset.address, account.secret)
|
|
|
|
k8s_url = f'{asset.address}:{asset.port}'
|
|
|
|
|
|
|
|
proxy_url = cls.get_proxy_url(asset)
|
|
|
|
|
|
|
|
k8s = cls(k8s_url, account.secret, proxy=proxy_url)
|
|
|
|
return k8s.get_pods()
|
|
|
|
return k8s.get_pods()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|