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