comparison tasks.py @ 10:2023a6ce7bc0

some of the config-rebuild code
author drewp@bigasterisk.com
date Sun, 04 Dec 2022 02:09:40 -0800
parents 1eb6e6a2b9b6
children b6720e379d5b
comparison
equal deleted inserted replaced
9:17db5e8e7a2f 10:2023a6ce7bc0
1 import json
2 import sys
3 import tempfile
4 import time
1 import urllib.request 5 import urllib.request
6 from pathlib import Path
7 from typing import Dict
8
2 from invoke import task 9 from invoke import task
3 10
4 11
5 def updateConfigmapCmd(path): 12 def updateConfigmapCmd(path):
6 return f'kubectl create configmap victoriametrics-config --from-file {path}=config/{path} -o yaml --dry-run=client | kubectl apply -f -' 13 return f'kubectl create configmap victoriametrics-config --from-file {path}=config/{path} -o yaml --dry-run=client | kubectl apply -f -'
9 def reload(ctx, svc): 16 def reload(ctx, svc):
10 host = ctx.run(f'khost {svc}').stdout 17 host = ctx.run(f'khost {svc}').stdout
11 path = {'victoriametrics': '/m', 'vmalert': '/vmalert'}[svc] 18 path = {'victoriametrics': '/m', 'vmalert': '/vmalert'}[svc]
12 print(' -> status', 19 print(' -> status',
13 urllib.request.urlopen(f'http://{host}{path}/-/reload').status) 20 urllib.request.urlopen(f'http://{host}{path}/-/reload').status)
21 def hostsExpectedOnline(ctx):
22 return ctx.run(
23 'cd /my/serv/lanscape; pdm run python hosts_expected_online.py').stdout
24
25
14 26
15 27
16 @task 28 @task
17 def sync_config(ctx): 29 def sync_config(ctx):
18 ctx.run(updateConfigmapCmd("scrape_config.yaml")) 30 ctx.run(updateConfigmapCmd("scrape_config.yaml"))
22 ctx.run(updateConfigmapCmd("rules_expected_hosts.yaml")) 34 ctx.run(updateConfigmapCmd("rules_expected_hosts.yaml"))
23 ctx.run(updateConfigmapCmd("rules_expected_nodes.yaml")) 35 ctx.run(updateConfigmapCmd("rules_expected_nodes.yaml"))
24 ctx.run(updateConfigmapCmd("rules_k8s.yaml")) 36 ctx.run(updateConfigmapCmd("rules_k8s.yaml"))
25 ctx.run(updateConfigmapCmd("rules_main.yaml")) 37 ctx.run(updateConfigmapCmd("rules_main.yaml"))
26 reload(ctx, 'vmalert') 38 reload(ctx, 'vmalert')
39
40 @task
41 def build_config(ctx):
42 with open('rules/build/expected_hosts.yaml', 'w') as out:
43 out.write(hostsExpectedOnline(ctx))