annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
1 import json
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
2 import sys
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
3 import tempfile
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
4 import time
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
5 import urllib.request
10
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
6 from pathlib import Path
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
7 from typing import Dict
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
8
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
9 from invoke import task
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
10
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
11
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
12 def updateConfigmapCmd(path):
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
13 return f'kubectl create configmap victoriametrics-config --from-file {path}=config/{path} -o yaml --dry-run=client | kubectl apply -f -'
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
14
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
15
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
16 def reload(ctx, svc):
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
17 host = ctx.run(f'khost {svc}').stdout
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
18 path = {'victoriametrics': '/m', 'vmalert': '/vmalert'}[svc]
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
19 print(' -> status',
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
20 urllib.request.urlopen(f'http://{host}{path}/-/reload').status)
10
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
21 def hostsExpectedOnline(ctx):
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
22 return ctx.run(
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
23 'cd /my/serv/lanscape; pdm run python hosts_expected_online.py').stdout
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
24
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
25
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
26
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
27
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
28 @task
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
29 def sync_config(ctx):
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
30 ctx.run(updateConfigmapCmd("scrape_config.yaml"))
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
31 ctx.run(updateConfigmapCmd("scrape_ssl.yaml"))
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
32 reload(ctx, 'victoriametrics')
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
33
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
34 ctx.run(updateConfigmapCmd("rules_expected_hosts.yaml"))
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
35 ctx.run(updateConfigmapCmd("rules_expected_nodes.yaml"))
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
36 ctx.run(updateConfigmapCmd("rules_k8s.yaml"))
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
37 ctx.run(updateConfigmapCmd("rules_main.yaml"))
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
38 reload(ctx, 'vmalert')
10
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
39
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
40 @task
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
41 def build_config(ctx):
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
42 with open('rules/build/expected_hosts.yaml', 'w') as out:
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
43 out.write(hostsExpectedOnline(ctx))