From 19625d1cde67ff285e8647c78c222e19b9509604 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Sun, 8 Sep 2024 20:57:33 +0100 Subject: [PATCH] Added a config to create Minikube k8s, uses hostpath volumes --- Makefile | 11 +- scripts/graph-show | 2 +- scripts/graph-to-turtle | 2 +- templates/config-to-minikube-k8s.jsonnet | 128 +++++++++++++++++++++++ 4 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 templates/config-to-minikube-k8s.jsonnet diff --git a/Makefile b/Makefile index 5fd5cc9b..15cbfd08 100644 --- a/Makefile +++ b/Makefile @@ -70,9 +70,12 @@ update-templates: set-version done; \ done -config.yaml: config.json FORCE - jsonnet -J . -J templates/ templates/config-to-k8s.jsonnet | \ - python3 -c 'import sys, yaml, json; j=json.loads(sys.stdin.read()); print(yaml.safe_dump(j))' > $@ - FORCE: +IGNOREconfig.yaml: config.json FORCE + jsonnet -J . -J templates/ templates/config-to-gcp-k8s.jsonnet | \ + python3 -c 'import sys, yaml, json; j=json.loads(sys.stdin.read()); print(yaml.safe_dump(j))' > $@ + +config.yaml: config.json FORCE + jsonnet -J . -J templates/ templates/config-to-minikube-k8s.jsonnet | \ + python3 -c 'import sys, yaml, json; j=json.loads(sys.stdin.read()); print(yaml.safe_dump(j))' > $@ diff --git a/scripts/graph-show b/scripts/graph-show index 27ab98b5..63da0e19 100755 --- a/scripts/graph-show +++ b/scripts/graph-show @@ -12,7 +12,7 @@ default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://pulsar:6650') def show_graph(pulsar): - tq = TriplesQueryClient(pulsar_host="pulsar://localhost:6650") + tq = TriplesQueryClient(pulsar_host=pulsar) rows = tq.request(None, None, None, limit=10_000_000) diff --git a/scripts/graph-to-turtle b/scripts/graph-to-turtle index 26e18774..a1c0e000 100755 --- a/scripts/graph-to-turtle +++ b/scripts/graph-to-turtle @@ -15,7 +15,7 @@ default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://pulsar:6650') def show_graph(pulsar): - tq = TriplesQueryClient(pulsar_host="pulsar://localhost:6650") + tq = TriplesQueryClient(pulsar_host=pulsar) rows = tq.request(None, None, None, limit=10_000_000) diff --git a/templates/config-to-minikube-k8s.jsonnet b/templates/config-to-minikube-k8s.jsonnet new file mode 100644 index 00000000..23797f0b --- /dev/null +++ b/templates/config-to-minikube-k8s.jsonnet @@ -0,0 +1,128 @@ + +local k8sEngine = import "k8s.jsonnet"; +local decode = import "decode-config.jsonnet"; +local components = import "components.jsonnet"; + +// Import config +local config = import "config.json"; + +// Produce patterns from config +local patterns = decode(config); + +local ns = { + apiVersion: "v1", + kind: "Namespace", + metadata: { + name: "trustgraph", + }, + "spec": { + }, +}; + +local engine = k8sEngine + { + volume:: function(name) + { + local volume = self, + name: name, + with_size:: function(size) self + { size: size }, + add:: function() [ + { + apiVersion: "v1", + kind: "PersistentVolume", + metadata: { + name: volume.name, + }, + spec: { + accessModes: [ "ReadWriteOnce" ], + capacity: { + storage: volume.size, + }, + persistentVolumeReclaimPolicy: "Delete", + hostPath: { + path: "/data/pv-" + volume.name, + }, + } + }, + { + apiVersion: "v1", + kind: "PersistentVolumeClaim", + metadata: { + name: volume.name, + namespace: "trustgraph", + }, + spec: { + accessModes: [ "ReadWriteOnce" ], + resources: { + requests: { + storage: volume.size, + } + }, + } + } + ], + + volRef:: function() { + name: volume.name, + persistentVolumeClaim: { claimName: volume.name }, + } + + }, + + service:: function(containers) + { + local service = self, + name: containers.name, + ports: [], + with_port:: + function(src, dest, name) + self + { + ports: super.ports + [ + { src: src, dest: dest, name: name } + ] + }, + add:: function() [ + { + apiVersion: "v1", + kind: "Service", + metadata: { + name: service.name, + namespace: "trustgraph", + }, + spec: { + selector: { + app: service.name, + }, + type: "LoadBalancer", + ports: [ + { + port: port.src, + targetPort: port.dest, + name: port.name, + } + for port in service.ports + ], + } + } + ], + }, + +}; + +//patterns["pulsar"].create(engine) + +// Extract resources using the engine +local resources = std.flattenArrays([ + p.create(engine) for p in std.objectValues(patterns) +]); + +local resourceList = { + apiVersion: "v1", + kind: "List", + items: [ + ns, + ] + resources, +}; + + +resourceList +