annotate output.py @ 77:489c5d9a7dbc

spelling of alertmanager config filenames
author drewp@bigasterisk.com
date Wed, 26 Jun 2024 22:28:25 -0700
parents adde35eb4773
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
1 import json
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
2 from pathlib import Path
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
3
62
8134cd480817 make next/ a complete standalone setup dir- no deps on ./
drewp@bigasterisk.com
parents: 56
diff changeset
4 build = Path('build/k8s_config')
8134cd480817 make next/ a complete standalone setup dir- no deps on ./
drewp@bigasterisk.com
parents: 56
diff changeset
5 build.mkdir(parents=True, exist_ok=True)
56
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
6
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
7
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
8 def toJson(d):
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
9 return json.dumps(d, sort_keys=True, indent=2)
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
10
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
11
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
12 def createSvc(filename, name, ports):
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
13 (build / f'{filename}_svc.yaml').write_text(toJson({
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
14 "apiVersion": "v1",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
15 "kind": "Service",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
16 "metadata": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
17 "name": name
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
18 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
19 "spec": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
20 "ports": ports,
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
21 "selector": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
22 "app": name
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
23 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
24 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
25 }))
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
26
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
27
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
28 def createIngress(filename, objName, policy, ingressPaths, host):
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
29
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
30 (build / filename).write_text(
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
31 toJson({
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
32 "apiVersion": "networking.k8s.io/v1",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
33 "kind": "Ingress",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
34 "metadata": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
35 "name": objName,
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
36 "annotations": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
37 "cert-manager.io/cluster-issuer": "letsencrypt-prod",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
38 "ingress.pomerium.io/allow_public_unauthenticated_access": "false",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
39 "ingress.pomerium.io/pass_identity_headers": "true",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
40 "ingress.pomerium.io/preserve_host_header": "true",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
41 "ingress.pomerium.io/policy": policy,
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
42 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
43 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
44 "spec": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
45 "ingressClassName": "pomerium",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
46 "rules": [{
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
47 "host": host,
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
48 "http": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
49 "paths": ingressPaths
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
50 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
51 },],
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
52 "tls": [{
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
53 "hosts": [host],
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
54 "secretName": f"{host}-tls"
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
55 }]
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
56 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
57 }))
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
58
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
59
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
60 def createPv(storageFileName, volName, request):
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
61 (build / f'{storageFileName}_0pv.yaml').write_text(
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
62 toJson({
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
63 "apiVersion": "v1",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
64 "kind": "PersistentVolume",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
65 "metadata": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
66 "name": volName,
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
67 "labels": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
68 "type": "local"
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
69 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
70 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
71 "spec": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
72 "storageClassName": "manual",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
73 "hostPath": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
74 "path": f"/opt/{volName}"
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
75 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
76 "capacity": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
77 "storage": request
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
78 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
79 "accessModes": ["ReadWriteMany"],
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
80 "persistentVolumeReclaimPolicy": "Retain",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
81 "claimRef": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
82 "namespace": "default",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
83 "name": volName
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
84 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
85 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
86 }))
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
87
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
88
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
89 def createPvc(storageFileName, volName, request):
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
90 (build / f'{storageFileName}_1pvc.yaml').write_text(toJson({
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
91 "apiVersion": "v1",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
92 "kind": "PersistentVolumeClaim",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
93 "metadata": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
94 "name": volName,
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
95 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
96 "spec": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
97 "storageClassName": "",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
98 "volumeName": volName,
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
99 "accessModes": ["ReadWriteMany"],
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
100 "resources": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
101 "requests": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
102 "storage": request
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
103 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
104 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
105 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
106 }))
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
107
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
108
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
109 def affinityToNode(node):
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
110 return {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
111 "nodeAffinity": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
112 "requiredDuringSchedulingIgnoredDuringExecution": {
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
113 "nodeSelectorTerms": [{
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
114 "matchExpressions": [{
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
115 "key": "kubernetes.io/hostname",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
116 "operator": "In",
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
117 "values": [node],
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
118 }],
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
119 }],
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
120 },
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
121 }
a72c47973aa4 parameterize the python version
drewp@bigasterisk.com
parents:
diff changeset
122 }