diff tasks.py @ 20:f5777b65f035

fast update of scrape_main.yaml
author drewp@bigasterisk.com
date Sat, 24 Jun 2023 01:44:57 -0700
parents 2c37fab420da
children cd115f1ca2a8
line wrap: on
line diff
--- a/tasks.py	Sat Jun 24 01:43:55 2023 -0700
+++ b/tasks.py	Sat Jun 24 01:44:57 2023 -0700
@@ -6,12 +6,14 @@
 from pathlib import Path
 from typing import Dict
 
+import yaml
 from invoke import task
+from kubernetes import config
 
-sys.path.append('/usr/lib/python3/dist-packages/')
-import yaml
+from k8s_ops import firstPodName, replaceCmap, refreshPodCmaps
 
 _tfs = []
+config.load_kube_config()
 
 
 def saveTmp(text):
@@ -40,7 +42,6 @@
         time.sleep(0)
 
 
-
 def hostsExpectedOnline(ctx):
     return ctx.run(
         'cd /my/serv/lanscape; pdm run python hosts_expected_online.py').stdout
@@ -85,7 +86,27 @@
         # reload(ctx, 'vmalert')
         ctx.run('kubectl rollout restart deploy/vmalert')
 
+
 @task
 def build_config(ctx):
     with open('rules/build/expected_hosts.yaml', 'w') as out:
         out.write(hostsExpectedOnline(ctx))
+
+
+# --------------------------
+
+
+def scrapeConfig(ctx):
+    return yaml.load(open('config/scrape_main.yaml'), yaml.FullLoader)
+
+
+@task
+def updateScrapes(ctx):
+    configObj = scrapeConfig(ctx)
+
+    replaceCmap('victoriametrics-config', configObj)
+
+    refreshPodCmaps(firstPodName('app=victoriametrics'))
+
+    # If the VM reloader isn't fast enough, we could do this too:
+    # hup(ctx, 'deploy/victoriametrics', 'victoria-metrics-prod')