Generate more real data (#207)
* try to generate more real data * remove blank line
This commit is contained in:
committed by
Henning Jacobs
parent
fc8bd6b89d
commit
0c320061f8
@@ -1,4 +1,5 @@
|
|||||||
import time
|
import time
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
def hash_int(x: int):
|
def hash_int(x: int):
|
||||||
@@ -35,8 +36,19 @@ def generate_mock_pod(index: int, i: int, j: int):
|
|||||||
phase = pod_phases[hash_int((index + 1) * (i + 1) * (j + 1)) % len(pod_phases)]
|
phase = pod_phases[hash_int((index + 1) * (i + 1) * (j + 1)) % len(pod_phases)]
|
||||||
containers = []
|
containers = []
|
||||||
for k in range(1 + j % 2):
|
for k in range(1 + j % 2):
|
||||||
|
# generate "more real data"
|
||||||
|
requests_cpu = random.randint(50, 100)
|
||||||
|
requests_memory = random.randint(256, 512)
|
||||||
|
usage_cpu = requests_cpu + random.randint(-45, 50)
|
||||||
|
usage_memory = requests_memory + random.randint(-128, 128)
|
||||||
container = {
|
container = {
|
||||||
'name': 'myapp', 'image': 'foo/bar/{}'.format(j), 'resources': {'requests': {'cpu': '100m', 'memory': '100Mi'}, 'limits': {}},
|
'name': 'myapp',
|
||||||
|
'image': 'foo/bar/{}'.format(j),
|
||||||
|
'resources': {
|
||||||
|
'requests': {'cpu': f'{requests_cpu}m', 'memory': f'{requests_memory}Mi'},
|
||||||
|
'limits': {},
|
||||||
|
'usage': {'cpu': f'{usage_cpu}m', 'memory': f'{usage_memory}Mi'},
|
||||||
|
},
|
||||||
'ready': True,
|
'ready': True,
|
||||||
'state': {'running': {}}
|
'state': {'running': {}}
|
||||||
}
|
}
|
||||||
@@ -86,9 +98,26 @@ def query_mock_cluster(cluster):
|
|||||||
else:
|
else:
|
||||||
pod = generate_mock_pod(index, i, j)
|
pod = generate_mock_pod(index, i, j)
|
||||||
pods['{}/{}'.format(pod['namespace'], pod['name'])] = pod
|
pods['{}/{}'.format(pod['namespace'], pod['name'])] = pod
|
||||||
node = {'name': 'node-{}'.format(i), 'labels': labels, 'status': {
|
|
||||||
'capacity': {'cpu': '4', 'memory': '32Gi', 'pods': '110'},
|
# use data from containers (usage)
|
||||||
'allocatable': {'cpu': '3800m', 'memory': '31Gi'}}, 'pods': pods}
|
usage_cpu = 0
|
||||||
|
usage_memory = 0
|
||||||
|
for p in pods.values():
|
||||||
|
for c in p["containers"]:
|
||||||
|
usage_cpu += int(c["resources"]["usage"]["cpu"].split("m")[0])
|
||||||
|
usage_memory += int(c["resources"]["usage"]["memory"].split("Mi")[0])
|
||||||
|
|
||||||
|
node = {
|
||||||
|
'name': 'node-{}'.format(i),
|
||||||
|
'labels': labels,
|
||||||
|
'status': {
|
||||||
|
'capacity': {'cpu': '4', 'memory': '32Gi', 'pods': '110'},
|
||||||
|
'allocatable': {'cpu': '3800m', 'memory': '31Gi'}
|
||||||
|
},
|
||||||
|
'pods': pods,
|
||||||
|
# get data from containers (usage)
|
||||||
|
'usage': {'cpu': f'{usage_cpu}m', 'memory': f'{usage_memory}Mi'}
|
||||||
|
}
|
||||||
nodes[node['name']] = node
|
nodes[node['name']] = node
|
||||||
pod = generate_mock_pod(index, 11, index)
|
pod = generate_mock_pod(index, 11, index)
|
||||||
unassigned_pods = {'{}/{}'.format(pod['namespace'], pod['name']): pod}
|
unassigned_pods = {'{}/{}'.format(pod['namespace'], pod['name']): pod}
|
||||||
|
|||||||
Reference in New Issue
Block a user