#36 filter unassigned pods too
This commit is contained in:
34
app.py
34
app.py
@@ -18,14 +18,18 @@ from flask_oauthlib.client import OAuth, OAuthRemoteApp
|
||||
from urllib.parse import urljoin
|
||||
|
||||
|
||||
def get_bool(name: str):
|
||||
return os.getenv(name, '').lower() in ('1', 'true')
|
||||
|
||||
|
||||
DEFAULT_CLUSTERS = 'http://localhost:8001/'
|
||||
CREDENTIALS_DIR = os.getenv('CREDENTIALS_DIR', '')
|
||||
AUTHORIZE_URL = os.getenv('AUTHORIZE_URL')
|
||||
APP_URL = os.getenv('APP_URL')
|
||||
MOCK = os.getenv('MOCK', '').lower() == 'true'
|
||||
MOCK = get_bool('MOCK')
|
||||
|
||||
app = Flask(__name__)
|
||||
app.debug = os.getenv('DEBUG', '').lower() == 'true'
|
||||
app.debug = get_bool('DEBUG')
|
||||
app.secret_key = os.getenv('SECRET_KEY', 'development')
|
||||
|
||||
oauth = OAuth(app)
|
||||
@@ -106,9 +110,7 @@ def hash_int(x: int):
|
||||
return x
|
||||
|
||||
|
||||
def generate_mock_cluster_data(index: int):
|
||||
'''Generate deterministic (no randomness!) mock data'''
|
||||
nodes = []
|
||||
def generate_mock_pod(index, i, j):
|
||||
names = [
|
||||
'agent-cooper',
|
||||
'black-lodge',
|
||||
@@ -120,12 +122,7 @@ def generate_mock_cluster_data(index: int):
|
||||
'sheriff-truman',
|
||||
]
|
||||
pod_phases = ['Pending', 'Running', 'Running']
|
||||
for i in range(10):
|
||||
labels = {}
|
||||
if i < 2:
|
||||
labels['master'] = 'true'
|
||||
pods = []
|
||||
for j in range(hash_int((index + 1) * (i + 1)) % 32):
|
||||
phase = pod_phases[hash_int((index + 1) * (i + 1) * (j + 1)) % len(pod_phases)]
|
||||
containers = []
|
||||
for k in range(1):
|
||||
@@ -136,9 +133,22 @@ def generate_mock_cluster_data(index: int):
|
||||
status['containerStatuses'] = [{'ready': False, 'state': {'waiting': {'reason': 'CrashLoopBackOff'}}}]
|
||||
elif j % 7 == 0:
|
||||
status['containerStatuses'] = [{'ready': True, 'state': {'running': {}}, 'restartCount': 3}]
|
||||
pods.append({'name': '{}-{}'.format(names[hash_int((i + 1) * (j + 1)) % len(names)], j), 'namespace': 'kube-system' if j < 3 else 'default', 'labels': labels, 'status': status, 'containers': containers})
|
||||
pod = {'name': '{}-{}'.format(names[hash_int((i + 1) * (j + 1)) % len(names)], j), 'namespace': 'kube-system' if j < 3 else 'default', 'labels': labels, 'status': status, 'containers': containers}
|
||||
return pod
|
||||
|
||||
|
||||
def generate_mock_cluster_data(index: int):
|
||||
'''Generate deterministic (no randomness!) mock data'''
|
||||
nodes = []
|
||||
for i in range(10):
|
||||
labels = {}
|
||||
if i < 2:
|
||||
labels['master'] = 'true'
|
||||
pods = []
|
||||
for j in range(hash_int((index + 1) * (i + 1)) % 32):
|
||||
pods.append(generate_mock_pod(index, i, j))
|
||||
nodes.append({'name': 'node-{}'.format(i), 'labels': labels, 'status': {'capacity': {'cpu': '4', 'memory': '32Gi', 'pods': '110'}}, 'pods': pods})
|
||||
unassigned_pods = []
|
||||
unassigned_pods = [generate_mock_pod(index, 0, index)]
|
||||
return {
|
||||
'api_server_url': 'https://kube-{}.example.org'.format(index),
|
||||
'nodes': nodes,
|
||||
|
||||
@@ -14,6 +14,8 @@ export default class App {
|
||||
this.filterString = ''
|
||||
}
|
||||
this.seenPods = {}
|
||||
this.desaturationFilter = new PIXI.filters.ColorMatrixFilter()
|
||||
this.desaturationFilter.desaturate()
|
||||
}
|
||||
|
||||
filter() {
|
||||
@@ -24,10 +26,19 @@ export default class App {
|
||||
} else {
|
||||
document.location.hash = ''
|
||||
}
|
||||
const filter = new PIXI.filters.ColorMatrixFilter()
|
||||
filter.desaturate()
|
||||
const filter = this.desaturationFilter
|
||||
for (const cluster of this.viewContainer.children) {
|
||||
for (const node of cluster.children) {
|
||||
const name = node.pod && node.pod.name
|
||||
if (name) {
|
||||
// node is actually unassigned pod
|
||||
if (!name.includes(searchString)){
|
||||
node.filters = [filter]
|
||||
} else {
|
||||
// TODO: pod might have other filters set..
|
||||
node.filters = []
|
||||
}
|
||||
}
|
||||
for (const pod of node.children) {
|
||||
const name = pod.pod && pod.pod.name
|
||||
if (name) {
|
||||
|
||||
Reference in New Issue
Block a user