mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-19 07:00:43 -04:00
add blerplate
This commit is contained in:
parent
d51c32f029
commit
d32e821bd7
9 changed files with 323 additions and 3 deletions
75
dash_app/wrappers/k8s_wrapper.py
Normal file
75
dash_app/wrappers/k8s_wrapper.py
Normal file
|
@ -0,0 +1,75 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Wrapper for K8s API
|
||||
|
||||
import os
|
||||
|
||||
from kubernetes import client, config
|
||||
from wrappers.settings import ORG, K8S_ENV_LIST
|
||||
|
||||
|
||||
def get_pod_data(namespace):
|
||||
''' Retrieve and return data from K8s from a given namepasce.'''
|
||||
|
||||
config.load_kube_config()
|
||||
api_instance = client.CoreV1Api()
|
||||
|
||||
try:
|
||||
ret = api_instance.list_pod_for_all_namespaces(watch=False)
|
||||
|
||||
ip_list, name_list, stat_list = [], [], []
|
||||
for item in ret.items:
|
||||
if (item.metadata.namespace != namespace):
|
||||
continue
|
||||
|
||||
ip_list.append(item.status.pod_ip)
|
||||
name_list.append(item.metadata.name)
|
||||
stat_list.append(item.status.phase)
|
||||
|
||||
dtag_list, dimage_list = [], []
|
||||
for pod in name_list:
|
||||
dtag_str, dimage_str = get_pod_info(namespace, api_instance, pod)
|
||||
dtag_list.append(dtag_str)
|
||||
dimage_list.append(dimage_str)
|
||||
|
||||
|
||||
return {
|
||||
'Status': stat_list,
|
||||
'Name': name_list,
|
||||
'Pod IP': ip_list,
|
||||
'Docker Image': dimage_list,
|
||||
'Docker Tag': dtag_list
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print("Error retrieving K8s data: \n{}".format(e))
|
||||
return None
|
||||
|
||||
def generate_env_dict():
|
||||
''' Retrieve K8s namespaces from env, and return a dict of it. '''
|
||||
env_list = K8S_ENV_LIST.split(',')
|
||||
return [{'label': i.strip(), 'value': i.strip()} for i in env_list]
|
||||
|
||||
|
||||
def get_pod_info(namespace, api_instance, pod_name):
|
||||
''' Retrieve the Docker info from a given pod. '''
|
||||
api_response = api_instance.read_namespaced_pod(pod_name, namespace)
|
||||
|
||||
dtag_str, dimage_str = '', ''
|
||||
if len(api_response.spec.containers) < 2:
|
||||
dimage_str, dtag_str = api_response.spec.containers[0].image.split(':')
|
||||
else:
|
||||
for container in api_response.spec.containers:
|
||||
im, tg = container.image.split(':')
|
||||
dimage_str += '{}; '.format(im)
|
||||
dtag_str += '{}; '.format(tg)
|
||||
|
||||
|
||||
return dtag_str, dimage_str
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
test_namespace = 'staging'
|
||||
print('Printing k8s data for giving namespace')
|
||||
print(get_pod_data(test_namespace))
|
||||
|
12
dash_app/wrappers/settings.py
Normal file
12
dash_app/wrappers/settings.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Load all env variables from .env file
|
||||
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from pathlib import Path
|
||||
|
||||
env_path = Path('.') / '.env'
|
||||
load_dotenv(dotenv_path=env_path)
|
||||
|
||||
# General constants
|
||||
PORT = os.getenv('PORT')
|
45
dash_app/wrappers/style.py
Normal file
45
dash_app/wrappers/style.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
# -*- coding: utf8 -*-
|
||||
# Define dashboard styling
|
||||
|
||||
# -----------------------------
|
||||
# --- Titles and strings ------
|
||||
# -----------------------------
|
||||
title_h1 = 'Big Title'
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# --- elements ids ------------
|
||||
# -----------------------------
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# --- CSS style dictionaries --
|
||||
# -----------------------------
|
||||
|
||||
color_palette = ['#052a4e', # dark blue
|
||||
'#fd8283', # light red
|
||||
'#e4faff'] # light blue
|
||||
|
||||
style_all = {'margin':'auto',
|
||||
'padding':20,
|
||||
'width':'95%',
|
||||
'fontFamily':'helvetica',
|
||||
'fontSize':'14',
|
||||
'color':color_palette[0],
|
||||
'background':color_palette[2],
|
||||
}
|
||||
|
||||
style_title_h1 = {'textAlign':'left',
|
||||
'color':color_palette[1],
|
||||
'font-weight':'bold',
|
||||
'fontSize':'32',
|
||||
'text-transform':'uppercase',
|
||||
'padding':20,
|
||||
}
|
||||
|
||||
style_title_h2 = {'textAlign':'center',
|
||||
'font-weight':'bold',
|
||||
'text-transform':'uppercase',
|
||||
'fontSize':'20',
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue