-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
57 lines (41 loc) · 1.93 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sys
import time
from os import getenv
from k8s_pod_killer.k8s_api_client import _k8s_client
from k8s_pod_killer.k8s_logging import _logging
from k8s_pod_killer.k8s_pods_terminator import _kill_selected_pods
from k8s_pod_killer.k8s_pod_utility import _config_load, _interval_calc
from prometheus_client import start_http_server
#invoke logger
logger = _logging()
def main():
logger.debug('DEBUG mode enabled - actions will be printed to log')
logger.debug('Starting prometheus server on port 9000')
# start prom server
start_http_server(9000)
cfg_file = getenv('CONFIG_FILE', 'config.yaml')
config = _config_load(cfg_file)
logger.debug('Config initialised with the following values:')
logger.debug(f' Dry Run: {config.dryRun}')
logger.debug(f' Update Frequency: {config.updateFrequency}')
logger.debug(f' Grace Period: {config.gracePeriod}')
logger.debug(f' Randomised Frequency: {config.randomiseFrequency}')
logger.debug(f' Included Namespaces: {config.includedNamespaces}')
logger.debug(f' Excluded Namespaces: {config.excludedNamespaces}')
logger.debug(f' Pods Annotation: {config.podAnnotation}')
logger.debug(f' Pods To Delete: {config.numPodsToDelete}')
_k8s_client()
while True:
_kill_selected_pods(num_pods=config.numPodsToDelete,
dry_run=config.dryRun,
grace=config.gracePeriod,
inclusions=config.includedNamespaces,
exclusions=config.excludedNamespaces,
podannotations=config.podAnnotation)
interval = _interval_calc(frequency=config.updateFrequency, randomise=config.randomiseFrequency)
logger.debug(f'Sleeping for {interval}')
time.sleep(interval)
def init():
if __name__ == '__main__':
sys.exit(main())
init()