From 5bb3e90b38ac67e25c2e9ab98f7ab006504452a9 Mon Sep 17 00:00:00 2001 From: Gary Larizza Date: Tue, 7 Jan 2025 14:16:57 -0800 Subject: [PATCH 1/2] Install raw-loader module We use this module within our markdown tutorials (like the Helm Values tutorial) to load in files generated by testscript. --- doc/website/package-lock.json | 39 +++++++++++++++++++++++++++++++++++ doc/website/package.json | 1 + 2 files changed, 40 insertions(+) diff --git a/doc/website/package-lock.json b/doc/website/package-lock.json index 63e7cf0e..9d63ef25 100644 --- a/doc/website/package-lock.json +++ b/doc/website/package-lock.json @@ -15,6 +15,7 @@ "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", "prism-react-renderer": "^2.3.0", + "raw-loader": "^4.0.2", "react": "^18.0.0", "react-dom": "^18.0.0" }, @@ -14477,6 +14478,44 @@ "node": ">= 0.8" } }, + "node_modules/raw-loader": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-4.0.2.tgz", + "integrity": "sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA==", + "license": "MIT", + "dependencies": { + "loader-utils": "^2.0.0", + "schema-utils": "^3.0.0" + }, + "engines": { + "node": ">= 10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^4.0.0 || ^5.0.0" + } + }, + "node_modules/raw-loader/node_modules/schema-utils": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", + "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", + "license": "MIT", + "dependencies": { + "@types/json-schema": "^7.0.8", + "ajv": "^6.12.5", + "ajv-keywords": "^3.5.2" + }, + "engines": { + "node": ">= 10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + } + }, "node_modules/rc": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", diff --git a/doc/website/package.json b/doc/website/package.json index d27d9c75..383962a8 100644 --- a/doc/website/package.json +++ b/doc/website/package.json @@ -22,6 +22,7 @@ "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", "prism-react-renderer": "^2.3.0", + "raw-loader": "^4.0.2", "react": "^18.0.0", "react-dom": "^18.0.0" }, From b28c110694fa1b04d73d45c165253747a378ab07 Mon Sep 17 00:00:00 2001 From: Gary Larizza Date: Tue, 7 Jan 2025 16:01:09 -0800 Subject: [PATCH 2/2] Update Helm Values tutorial to use testscript PROBLEM: The Helm Values tutorial contains a fair bit of code/scripts, and we need a way to test the steps we recommend to make sure nothing breaks or slips out of date. SOLUTION: * Use `testscript` as a way to automate the execution of the steps in the doc and verify that none of the steps produce errors. * Update the MDX file to directly reference the files embedded into the testscript. OUTCOME: * We have an automated way to perform the steps in the Helm Values document. * We have unit tests that will fail should any of the commands being executed in the doc fail. * The doc's MDX file directly references the files within the testscript, so we only need to modify the MDX file to update wording. --- .../examples/01-holos-version.txt | 7 + .../examples/02-helm-values.txt | 357 ++++++++++++++++ .../script-01-holos-version/command.sh | 1 + .../script-01-holos-version/output.txt | 1 + .../blackbox.common.config.body.cue | 15 + .../blackbox.common.config.git.commit.sh | 1 + .../blackbox.common.config.git.output.txt | 3 + .../blackbox.common.config.header.sh | 1 + .../blackbox.component.body.cue | 15 + .../blackbox.component.header.sh | 1 + .../common.config.git.output.txt | 2 + .../common.config.git.sh | 1 + .../common.config.patch.sh | 1 + .../common.config.patch.txt | 2 + .../script-02-helm-values/common.config.rm.sh | 1 + .../script-02-helm-values/eof.trailer.sh | 1 + .../script-02-helm-values/git.diff | 64 +++ .../script-02-helm-values/git.diff.sh | 1 + .../script-02-helm-values/git.init.sh | 1 + .../import.blackbox.values.sh | 5 + .../import.prometheus.values.sh | 5 + .../import.values.git.commit.sh | 1 + .../import.values.git.output.txt | 4 + .../import.values.render.output.txt | 3 + .../script-02-helm-values/mkdir.and.init.sh | 3 + .../script-02-helm-values/mkdir.components.sh | 1 + .../prometheus.component.body.cue | 15 + .../prometheus.component.header.sh | 1 + .../register.components.body.cue | 12 + .../register.components.git.commit.output.txt | 7 + .../register.components.git.commit.sh | 1 + .../register.components.header.sh | 1 + .../register.components.output.txt | 5 + .../script-02-helm-values/render.sh | 1 + .../reviewing.changes.git.commit.sh | 1 + .../reviewing.changes.git.output.txt | 2 + .../reviewing.changes.render.output.txt | 3 + .../script-02-helm-values/update.sh | 4 + .../script-02-helm-values/values.patch | 31 ++ doc/md/markdown_test.go | 87 ++++ doc/md/tutorial/helm-values.mdx | 397 +++++------------- 41 files changed, 769 insertions(+), 297 deletions(-) create mode 100644 doc/md/_markdown-tests/examples/01-holos-version.txt create mode 100644 doc/md/_markdown-tests/examples/02-helm-values.txt create mode 100644 doc/md/_markdown-tests/script-01-holos-version/command.sh create mode 100644 doc/md/_markdown-tests/script-01-holos-version/output.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.body.cue create mode 100644 doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.git.commit.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.git.output.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.header.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/blackbox.component.body.cue create mode 100644 doc/md/_markdown-tests/script-02-helm-values/blackbox.component.header.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/common.config.git.output.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/common.config.git.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/common.config.patch.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/common.config.patch.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/common.config.rm.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/eof.trailer.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/git.diff create mode 100644 doc/md/_markdown-tests/script-02-helm-values/git.diff.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/git.init.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/import.blackbox.values.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/import.prometheus.values.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/import.values.git.commit.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/import.values.git.output.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/import.values.render.output.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/mkdir.and.init.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/mkdir.components.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/prometheus.component.body.cue create mode 100644 doc/md/_markdown-tests/script-02-helm-values/prometheus.component.header.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/register.components.body.cue create mode 100644 doc/md/_markdown-tests/script-02-helm-values/register.components.git.commit.output.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/register.components.git.commit.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/register.components.header.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/register.components.output.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/render.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.git.commit.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.git.output.txt create mode 100644 doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.render.output.txt create mode 100755 doc/md/_markdown-tests/script-02-helm-values/update.sh create mode 100644 doc/md/_markdown-tests/script-02-helm-values/values.patch create mode 100644 doc/md/markdown_test.go diff --git a/doc/md/_markdown-tests/examples/01-holos-version.txt b/doc/md/_markdown-tests/examples/01-holos-version.txt new file mode 100644 index 00000000..0cd5b8ce --- /dev/null +++ b/doc/md/_markdown-tests/examples/01-holos-version.txt @@ -0,0 +1,7 @@ +exec bash -c 'bash -euo pipefail $WORK/command.sh 2>&1' +cmp stdout $WORK/output.txt + +-- command.sh -- +holos --version +-- output.txt -- +0.102.4 \ No newline at end of file diff --git a/doc/md/_markdown-tests/examples/02-helm-values.txt b/doc/md/_markdown-tests/examples/02-helm-values.txt new file mode 100644 index 00000000..8d31857c --- /dev/null +++ b/doc/md/_markdown-tests/examples/02-helm-values.txt @@ -0,0 +1,357 @@ +# Set $HOME because: +# - Helm uses it for temporary files +# - Git requires it for setting author name/email globally +env HOME=$WORK/.tmp +chmod 0755 $WORK/update.sh + +# Configure git author for testscript execution +exec git config --global user.name 'Holos Docs' +exec git config --global user.email 'hello@holos.run' +exec git config --global init.defaultBranch main + +# Remove the tutorial directory if it already exists +exec rm -rf holos-helm-values-tutorial + +# Create and change to the tutorial directory, and then initialize the Holos platform +exec bash -c 'bash -euo pipefail mkdir.and.init.sh' +cd holos-helm-values-tutorial + +# Git init and create the component directories +exec bash -c 'bash -euo pipefail $WORK/git.init.sh' +exec bash -c 'bash -euo pipefail $WORK/mkdir.components.sh' + +# Combine and execute the multiline prometheus/blackbox component header/body/trailer files +exec cat $WORK/prometheus.component.header.sh ../prometheus.component.body.cue ../eof.trailer.sh +stdin stdout +exec bash -xeuo pipefail +exec cat $WORK/blackbox.component.header.sh ../blackbox.component.body.cue ../eof.trailer.sh +stdin stdout +exec bash -xeuo pipefail + +# Combine and execute the multiline platform registration header/body/trailer files. +exec cat $WORK/register.components.header.sh ../register.components.body.cue ../eof.trailer.sh +stdin stdout +exec bash -xeuo pipefail + +# Render the platform, capture stdout, and use update.sh to gate whether the +# output file should be updated. +# +# NOTE: The [net] condition will test whether external network access is available +[net] exec bash -c 'bash -euo pipefail $WORK/render.sh 2>&1' +[net] stdin stdout +exec $WORK/update.sh $WORK/register.components.output.txt + +# Commit and conditionally update the output file +exec bash -c 'bash -euo pipefail $WORK/register.components.git.commit.sh' +stdin stdout +exec $WORK/update.sh $WORK/register.components.git.commit.output.txt + +# Import values +exec bash -c 'bash -euo pipefail $WORK/import.prometheus.values.sh' +exec bash -c 'bash -euo pipefail $WORK/import.blackbox.values.sh' + +# Render, update the output file, commit, and update the commit output file. +[net] exec bash -c 'bash -euo pipefail $WORK/render.sh 2>&1' +[net] stdin stdout +exec $WORK/update.sh $WORK/import.values.render.output.txt +exec bash -c 'bash -euo pipefail $WORK/import.values.git.commit.sh' +stdin stdout +exec $WORK/update.sh $WORK/import.values.git.output.txt + +# Combine and execute the common configuration header/body/trailer to write the cue file. +exec cat $WORK/blackbox.common.config.header.sh ../blackbox.common.config.body.cue ../eof.trailer.sh +stdin stdout +exec bash -xeuo pipefail + +# Git commit blackbox common config +exec bash -c 'bash -euo pipefail $WORK/blackbox.common.config.git.commit.sh' +stdin stdout +exec $WORK/update.sh $WORK/blackbox.common.config.git.output.txt + +# Patch the common config values file and write to output file. +# +# NOTE: Using a symlink here because the patch script references values.patch +# within the same directory, but it actually lives one directory up in the +# testscript $WORK dir. +exec ln -s $WORK/values.patch values.patch +exec bash -c 'bash -euo pipefail $WORK/common.config.patch.sh' +stdin stdout +exec $WORK/update.sh $WORK/common.config.patch.txt + +# Remove patch and commit changes +exec bash -c 'bash -euo pipefail $WORK/common.config.rm.sh' +exec bash -c 'bash -euo pipefail $WORK/common.config.git.sh' +stdin stdout +exec $WORK/update.sh $WORK/common.config.git.output.txt + +# Final render and update of output file. +[net] exec bash -c 'bash -euo pipefail $WORK/render.sh 2>&1' +[net] stdin stdout +exec $WORK/update.sh $WORK/reviewing.changes.git.output.txt + +# Git diff and write to output file. +exec bash -c 'bash -euo pipefail $WORK/git.diff.sh' +stdin stdout +exec $WORK/update.sh $WORK/git.diff + +# Final commit and write to output file +exec bash -c 'bash -euo pipefail $WORK/reviewing.changes.git.commit.sh' +stdin stdout +exec $WORK/update.sh $WORK/reviewing.changes.git.output.txt + +# Clean up the tutorial directory and tmp $HOME directory +cd $WORK +exec rm -rf holos-helm-values-tutorial +exec rm -rf $HOME + +-- update.sh -- +#! /bin/bash +set -euo pipefail +[[ -s "$1" ]] && [[ -z "${HOLOS_UPDATE_SCRIPTS:-}" ]] && exit 0 +cat > "$1" +-- mkdir.and.init.sh -- +mkdir holos-helm-values-tutorial +cd holos-helm-values-tutorial +holos init platform v1alpha5 +-- git.init.sh -- +git init . && git add . && git commit -m "initial commit" +-- mkdir.components.sh -- +mkdir -p components/prometheus components/blackbox +-- prometheus.component.header.sh -- +cat < components/prometheus/prometheus.cue +-- prometheus.component.body.cue -- +package holos + +// Produce a helm chart build plan. +holos: Helm.BuildPlan + +Helm: #Helm & { + Chart: { + name: "prometheus" + version: "25.27.0" + repository: { + name: "prometheus-community" + url: "https://prometheus-community.github.io/helm-charts" + } + } +} +-- eof.trailer.sh -- +EOF +-- blackbox.component.header.sh -- +cat < components/blackbox/blackbox.cue +-- blackbox.component.body.cue -- +package holos + +// Produce a helm chart build plan. +holos: Helm.BuildPlan + +Helm: #Helm & { + Chart: { + name: "prometheus-blackbox-exporter" + version: "9.0.1" + repository: { + name: "prometheus-community" + url: "https://prometheus-community.github.io/helm-charts" + } + } +} +-- register.components.header.sh -- +cat < platform/prometheus.cue +-- register.components.body.cue -- +package holos + +Platform: Components: { + prometheus: { + name: "prometheus" + path: "components/prometheus" + } + blackbox: { + name: "blackbox" + path: "components/blackbox" + } +} +-- render.sh -- +holos render platform +-- register.components.output.txt -- +cached prometheus-blackbox-exporter 9.0.1 +rendered blackbox in 3.825430417s +cached prometheus 25.27.0 +rendered prometheus in 4.840089667s +rendered platform in 4.840137792s +-- register.components.git.commit.sh -- +git add . && git commit -m 'add blackbox and prometheus' +-- register.components.git.commit.output.txt -- +[main b5df111] add blackbox and prometheus + 5 files changed, 1550 insertions(+) + create mode 100644 components/blackbox/blackbox.cue + create mode 100644 components/prometheus/prometheus.cue + create mode 100644 deploy/components/blackbox/blackbox.gen.yaml + create mode 100644 deploy/components/prometheus/prometheus.gen.yaml + create mode 100644 platform/prometheus.cue +-- import.prometheus.values.sh -- +holos cue import \ + --package holos \ + --path 'Helm: Values:' \ + --outfile components/prometheus/values.cue \ + components/prometheus/vendor/25.27.0/prometheus/values.yaml +-- import.blackbox.values.sh -- +holos cue import \ + --package holos \ + --path 'Helm: Values:' \ + --outfile components/blackbox/values.cue \ + components/blackbox/vendor/9.0.1/prometheus-blackbox-exporter/values.yaml +-- import.values.render.output.txt -- +rendered blackbox in 365.936792ms +rendered prometheus in 371.855875ms +rendered platform in 372.109916ms +-- import.values.git.commit.sh -- +git add . && git commit -m 'import values' +-- import.values.git.output.txt -- +[main 52e90ea] import values + 2 files changed, 1815 insertions(+) + create mode 100644 components/blackbox/values.cue + create mode 100644 components/prometheus/values.cue +-- blackbox.common.config.header.sh -- +cat < components/blackbox.cue +-- blackbox.common.config.body.cue -- +package holos + +// Schema Definition +#Blackbox: { + // host constrained to a lower case dns label + host: string & =~"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$" + // port constrained to a valid range + port: int & >0 & <=65535 +} + +// Concrete values must validate against the schema. +Blackbox: #Blackbox & { + host: "blackbox" + port: 9115 +} +-- blackbox.common.config.git.commit.sh -- +git add . && git commit -m 'add blackbox configuration' +-- blackbox.common.config.git.output.txt -- +[main 1adcd08] add blackbox configuration + 1 file changed, 15 insertions(+) + create mode 100644 components/blackbox.cue +-- common.config.patch.sh -- +patch -p1 < values.patch +-- values.patch -- +--- a/components/blackbox/values.cue ++++ b/components/blackbox/values.cue +@@ -1,6 +1,8 @@ + package holos + + Helm: Values: { ++ fullnameOverride: Blackbox.host ++ + global: { + //# Global image registry to use if it needs to be overriden for some specific use cases (e.g local registries, custom images, ...) + //# +@@ -192,7 +194,7 @@ Helm: Values: { + annotations: {} + labels: {} + type: "ClusterIP" +- port: 9115 ++ port: Blackbox.port + ipDualStack: { + enabled: false + ipFamilies: ["IPv6", "IPv4"] +--- a/components/prometheus/values.cue ++++ b/components/prometheus/values.cue +@@ -1083,7 +1083,7 @@ Helm: Values: { + target_label: "__param_target" + }, { + target_label: "__address__" +- replacement: "blackbox" ++ replacement: "\(Blackbox.host):\(Blackbox.port)" + }, { + source_labels: ["__param_target"] + target_label: "instance" +-- common.config.patch.txt -- +patching file 'components/blackbox/values.cue' +patching file 'components/prometheus/values.cue' +-- common.config.rm.sh -- +rm values.patch +-- common.config.git.sh -- +git add . && git commit -m 'integrate blackbox and prometheus together' +-- common.config.git.output.txt -- +[main 4221803] integrate blackbox and prometheus together + 2 files changed, 4 insertions(+), 2 deletions(-) +-- reviewing.changes.render.output.txt -- +rendered blackbox in 374.810666ms +rendered prometheus in 382.899334ms +rendered platform in 383.270625ms +-- git.diff.sh -- +git diff +-- git.diff -- +diff --git a/deploy/components/blackbox/blackbox.gen.yaml b/deploy/components/blackbox/blackbox.gen.yaml +index 3db20cd..5336f44 100644 +--- a/deploy/components/blackbox/blackbox.gen.yaml ++++ b/deploy/components/blackbox/blackbox.gen.yaml +@@ -7,7 +7,7 @@ metadata: + app.kubernetes.io/name: prometheus-blackbox-exporter + app.kubernetes.io/version: v0.25.0 + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 +- name: prometheus-blackbox-exporter ++ name: blackbox + namespace: default + --- + apiVersion: v1 +@@ -31,7 +31,7 @@ metadata: + app.kubernetes.io/name: prometheus-blackbox-exporter + app.kubernetes.io/version: v0.25.0 + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 +- name: prometheus-blackbox-exporter ++ name: blackbox + namespace: default + --- + apiVersion: v1 +@@ -43,7 +43,7 @@ metadata: + app.kubernetes.io/name: prometheus-blackbox-exporter + app.kubernetes.io/version: v0.25.0 + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 +- name: prometheus-blackbox-exporter ++ name: blackbox + namespace: default + spec: + ports: +@@ -65,7 +65,7 @@ metadata: + app.kubernetes.io/name: prometheus-blackbox-exporter + app.kubernetes.io/version: v0.25.0 + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 +- name: prometheus-blackbox-exporter ++ name: blackbox + namespace: default + spec: + replicas: 1 +@@ -119,8 +119,8 @@ spec: + name: config + hostNetwork: false + restartPolicy: Always +- serviceAccountName: prometheus-blackbox-exporter ++ serviceAccountName: blackbox + volumes: + - configMap: +- name: prometheus-blackbox-exporter ++ name: blackbox + name: config +diff --git a/deploy/components/prometheus/prometheus.gen.yaml b/deploy/components/prometheus/prometheus.gen.yaml +index 9e02bce..ab638f0 100644 +--- a/deploy/components/prometheus/prometheus.gen.yaml ++++ b/deploy/components/prometheus/prometheus.gen.yaml +@@ -589,7 +589,7 @@ data: + - source_labels: + - __address__ + target_label: __param_target +- - replacement: blackbox ++ - replacement: blackbox:9115 + target_label: __address__ + - source_labels: + - __param_target +-- reviewing.changes.git.commit.sh -- +git add . && git commit -m 'render integrated blackbox and prometheus manifests' +-- reviewing.changes.git.output.txt -- +[main 67efe0d] render integrated blackbox and prometheus manifests + 2 files changed, 7 insertions(+), 7 deletions(-) \ No newline at end of file diff --git a/doc/md/_markdown-tests/script-01-holos-version/command.sh b/doc/md/_markdown-tests/script-01-holos-version/command.sh new file mode 100644 index 00000000..10507251 --- /dev/null +++ b/doc/md/_markdown-tests/script-01-holos-version/command.sh @@ -0,0 +1 @@ +holos --version diff --git a/doc/md/_markdown-tests/script-01-holos-version/output.txt b/doc/md/_markdown-tests/script-01-holos-version/output.txt new file mode 100644 index 00000000..d88fa7ff --- /dev/null +++ b/doc/md/_markdown-tests/script-01-holos-version/output.txt @@ -0,0 +1 @@ +0.102.4 diff --git a/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.body.cue b/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.body.cue new file mode 100644 index 00000000..a1c6f7a3 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.body.cue @@ -0,0 +1,15 @@ +package holos + +// Schema Definition +#Blackbox: { + // host constrained to a lower case dns label + host: string & =~"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$" + // port constrained to a valid range + port: int & >0 & <=65535 +} + +// Concrete values must validate against the schema. +Blackbox: #Blackbox & { + host: "blackbox" + port: 9115 +} diff --git a/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.git.commit.sh b/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.git.commit.sh new file mode 100644 index 00000000..f24f377e --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.git.commit.sh @@ -0,0 +1 @@ +git add . && git commit -m 'add blackbox configuration' diff --git a/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.git.output.txt b/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.git.output.txt new file mode 100644 index 00000000..5bd28f65 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.git.output.txt @@ -0,0 +1,3 @@ +[main 1adcd08] add blackbox configuration + 1 file changed, 15 insertions(+) + create mode 100644 components/blackbox.cue diff --git a/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.header.sh b/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.header.sh new file mode 100644 index 00000000..6e14b326 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/blackbox.common.config.header.sh @@ -0,0 +1 @@ +cat < components/blackbox.cue diff --git a/doc/md/_markdown-tests/script-02-helm-values/blackbox.component.body.cue b/doc/md/_markdown-tests/script-02-helm-values/blackbox.component.body.cue new file mode 100644 index 00000000..a0de9aaa --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/blackbox.component.body.cue @@ -0,0 +1,15 @@ +package holos + +// Produce a helm chart build plan. +holos: Helm.BuildPlan + +Helm: #Helm & { + Chart: { + name: "prometheus-blackbox-exporter" + version: "9.0.1" + repository: { + name: "prometheus-community" + url: "https://prometheus-community.github.io/helm-charts" + } + } +} diff --git a/doc/md/_markdown-tests/script-02-helm-values/blackbox.component.header.sh b/doc/md/_markdown-tests/script-02-helm-values/blackbox.component.header.sh new file mode 100644 index 00000000..10999649 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/blackbox.component.header.sh @@ -0,0 +1 @@ +cat < components/blackbox/blackbox.cue diff --git a/doc/md/_markdown-tests/script-02-helm-values/common.config.git.output.txt b/doc/md/_markdown-tests/script-02-helm-values/common.config.git.output.txt new file mode 100644 index 00000000..289aabf6 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/common.config.git.output.txt @@ -0,0 +1,2 @@ +[main 4221803] integrate blackbox and prometheus together + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/md/_markdown-tests/script-02-helm-values/common.config.git.sh b/doc/md/_markdown-tests/script-02-helm-values/common.config.git.sh new file mode 100644 index 00000000..e6726817 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/common.config.git.sh @@ -0,0 +1 @@ +git add . && git commit -m 'integrate blackbox and prometheus together' diff --git a/doc/md/_markdown-tests/script-02-helm-values/common.config.patch.sh b/doc/md/_markdown-tests/script-02-helm-values/common.config.patch.sh new file mode 100644 index 00000000..83872faf --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/common.config.patch.sh @@ -0,0 +1 @@ +patch -p1 < values.patch diff --git a/doc/md/_markdown-tests/script-02-helm-values/common.config.patch.txt b/doc/md/_markdown-tests/script-02-helm-values/common.config.patch.txt new file mode 100644 index 00000000..7e73a29f --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/common.config.patch.txt @@ -0,0 +1,2 @@ +patching file 'components/blackbox/values.cue' +patching file 'components/prometheus/values.cue' diff --git a/doc/md/_markdown-tests/script-02-helm-values/common.config.rm.sh b/doc/md/_markdown-tests/script-02-helm-values/common.config.rm.sh new file mode 100644 index 00000000..1220bd4e --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/common.config.rm.sh @@ -0,0 +1 @@ +rm values.patch diff --git a/doc/md/_markdown-tests/script-02-helm-values/eof.trailer.sh b/doc/md/_markdown-tests/script-02-helm-values/eof.trailer.sh new file mode 100644 index 00000000..1a2b1dc1 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/eof.trailer.sh @@ -0,0 +1 @@ +EOF diff --git a/doc/md/_markdown-tests/script-02-helm-values/git.diff b/doc/md/_markdown-tests/script-02-helm-values/git.diff new file mode 100644 index 00000000..5054da9d --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/git.diff @@ -0,0 +1,64 @@ +diff --git a/deploy/components/blackbox/blackbox.gen.yaml b/deploy/components/blackbox/blackbox.gen.yaml +index 3db20cd..5336f44 100644 +--- a/deploy/components/blackbox/blackbox.gen.yaml ++++ b/deploy/components/blackbox/blackbox.gen.yaml +@@ -7,7 +7,7 @@ metadata: + app.kubernetes.io/name: prometheus-blackbox-exporter + app.kubernetes.io/version: v0.25.0 + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 +- name: prometheus-blackbox-exporter ++ name: blackbox + namespace: default + --- + apiVersion: v1 +@@ -31,7 +31,7 @@ metadata: + app.kubernetes.io/name: prometheus-blackbox-exporter + app.kubernetes.io/version: v0.25.0 + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 +- name: prometheus-blackbox-exporter ++ name: blackbox + namespace: default + --- + apiVersion: v1 +@@ -43,7 +43,7 @@ metadata: + app.kubernetes.io/name: prometheus-blackbox-exporter + app.kubernetes.io/version: v0.25.0 + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 +- name: prometheus-blackbox-exporter ++ name: blackbox + namespace: default + spec: + ports: +@@ -65,7 +65,7 @@ metadata: + app.kubernetes.io/name: prometheus-blackbox-exporter + app.kubernetes.io/version: v0.25.0 + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 +- name: prometheus-blackbox-exporter ++ name: blackbox + namespace: default + spec: + replicas: 1 +@@ -119,8 +119,8 @@ spec: + name: config + hostNetwork: false + restartPolicy: Always +- serviceAccountName: prometheus-blackbox-exporter ++ serviceAccountName: blackbox + volumes: + - configMap: +- name: prometheus-blackbox-exporter ++ name: blackbox + name: config +diff --git a/deploy/components/prometheus/prometheus.gen.yaml b/deploy/components/prometheus/prometheus.gen.yaml +index 9e02bce..ab638f0 100644 +--- a/deploy/components/prometheus/prometheus.gen.yaml ++++ b/deploy/components/prometheus/prometheus.gen.yaml +@@ -589,7 +589,7 @@ data: + - source_labels: + - __address__ + target_label: __param_target +- - replacement: blackbox ++ - replacement: blackbox:9115 + target_label: __address__ + - source_labels: + - __param_target diff --git a/doc/md/_markdown-tests/script-02-helm-values/git.diff.sh b/doc/md/_markdown-tests/script-02-helm-values/git.diff.sh new file mode 100644 index 00000000..4f59c73d --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/git.diff.sh @@ -0,0 +1 @@ +git diff diff --git a/doc/md/_markdown-tests/script-02-helm-values/git.init.sh b/doc/md/_markdown-tests/script-02-helm-values/git.init.sh new file mode 100644 index 00000000..fc3f05af --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/git.init.sh @@ -0,0 +1 @@ +git init . && git add . && git commit -m "initial commit" diff --git a/doc/md/_markdown-tests/script-02-helm-values/import.blackbox.values.sh b/doc/md/_markdown-tests/script-02-helm-values/import.blackbox.values.sh new file mode 100644 index 00000000..2a951bf6 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/import.blackbox.values.sh @@ -0,0 +1,5 @@ +holos cue import \ + --package holos \ + --path 'Helm: Values:' \ + --outfile components/blackbox/values.cue \ + components/blackbox/vendor/9.0.1/prometheus-blackbox-exporter/values.yaml diff --git a/doc/md/_markdown-tests/script-02-helm-values/import.prometheus.values.sh b/doc/md/_markdown-tests/script-02-helm-values/import.prometheus.values.sh new file mode 100644 index 00000000..c1d3238a --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/import.prometheus.values.sh @@ -0,0 +1,5 @@ +holos cue import \ + --package holos \ + --path 'Helm: Values:' \ + --outfile components/prometheus/values.cue \ + components/prometheus/vendor/25.27.0/prometheus/values.yaml diff --git a/doc/md/_markdown-tests/script-02-helm-values/import.values.git.commit.sh b/doc/md/_markdown-tests/script-02-helm-values/import.values.git.commit.sh new file mode 100644 index 00000000..12c757a4 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/import.values.git.commit.sh @@ -0,0 +1 @@ +git add . && git commit -m 'import values' diff --git a/doc/md/_markdown-tests/script-02-helm-values/import.values.git.output.txt b/doc/md/_markdown-tests/script-02-helm-values/import.values.git.output.txt new file mode 100644 index 00000000..1f5e148b --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/import.values.git.output.txt @@ -0,0 +1,4 @@ +[main 52e90ea] import values + 2 files changed, 1815 insertions(+) + create mode 100644 components/blackbox/values.cue + create mode 100644 components/prometheus/values.cue diff --git a/doc/md/_markdown-tests/script-02-helm-values/import.values.render.output.txt b/doc/md/_markdown-tests/script-02-helm-values/import.values.render.output.txt new file mode 100644 index 00000000..9226533d --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/import.values.render.output.txt @@ -0,0 +1,3 @@ +rendered blackbox in 365.936792ms +rendered prometheus in 371.855875ms +rendered platform in 372.109916ms diff --git a/doc/md/_markdown-tests/script-02-helm-values/mkdir.and.init.sh b/doc/md/_markdown-tests/script-02-helm-values/mkdir.and.init.sh new file mode 100644 index 00000000..525db13c --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/mkdir.and.init.sh @@ -0,0 +1,3 @@ +mkdir holos-helm-values-tutorial +cd holos-helm-values-tutorial +holos init platform v1alpha5 diff --git a/doc/md/_markdown-tests/script-02-helm-values/mkdir.components.sh b/doc/md/_markdown-tests/script-02-helm-values/mkdir.components.sh new file mode 100644 index 00000000..d948970b --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/mkdir.components.sh @@ -0,0 +1 @@ +mkdir -p components/prometheus components/blackbox diff --git a/doc/md/_markdown-tests/script-02-helm-values/prometheus.component.body.cue b/doc/md/_markdown-tests/script-02-helm-values/prometheus.component.body.cue new file mode 100644 index 00000000..f2cfc782 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/prometheus.component.body.cue @@ -0,0 +1,15 @@ +package holos + +// Produce a helm chart build plan. +holos: Helm.BuildPlan + +Helm: #Helm & { + Chart: { + name: "prometheus" + version: "25.27.0" + repository: { + name: "prometheus-community" + url: "https://prometheus-community.github.io/helm-charts" + } + } +} diff --git a/doc/md/_markdown-tests/script-02-helm-values/prometheus.component.header.sh b/doc/md/_markdown-tests/script-02-helm-values/prometheus.component.header.sh new file mode 100644 index 00000000..ee44a89a --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/prometheus.component.header.sh @@ -0,0 +1 @@ +cat < components/prometheus/prometheus.cue diff --git a/doc/md/_markdown-tests/script-02-helm-values/register.components.body.cue b/doc/md/_markdown-tests/script-02-helm-values/register.components.body.cue new file mode 100644 index 00000000..46181187 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/register.components.body.cue @@ -0,0 +1,12 @@ +package holos + +Platform: Components: { + prometheus: { + name: "prometheus" + path: "components/prometheus" + } + blackbox: { + name: "blackbox" + path: "components/blackbox" + } +} diff --git a/doc/md/_markdown-tests/script-02-helm-values/register.components.git.commit.output.txt b/doc/md/_markdown-tests/script-02-helm-values/register.components.git.commit.output.txt new file mode 100644 index 00000000..7dd8cc89 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/register.components.git.commit.output.txt @@ -0,0 +1,7 @@ +[main b5df111] add blackbox and prometheus + 5 files changed, 1550 insertions(+) + create mode 100644 components/blackbox/blackbox.cue + create mode 100644 components/prometheus/prometheus.cue + create mode 100644 deploy/components/blackbox/blackbox.gen.yaml + create mode 100644 deploy/components/prometheus/prometheus.gen.yaml + create mode 100644 platform/prometheus.cue diff --git a/doc/md/_markdown-tests/script-02-helm-values/register.components.git.commit.sh b/doc/md/_markdown-tests/script-02-helm-values/register.components.git.commit.sh new file mode 100644 index 00000000..eaf938ce --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/register.components.git.commit.sh @@ -0,0 +1 @@ +git add . && git commit -m 'add blackbox and prometheus' diff --git a/doc/md/_markdown-tests/script-02-helm-values/register.components.header.sh b/doc/md/_markdown-tests/script-02-helm-values/register.components.header.sh new file mode 100644 index 00000000..0359b770 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/register.components.header.sh @@ -0,0 +1 @@ +cat < platform/prometheus.cue diff --git a/doc/md/_markdown-tests/script-02-helm-values/register.components.output.txt b/doc/md/_markdown-tests/script-02-helm-values/register.components.output.txt new file mode 100644 index 00000000..3f906f32 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/register.components.output.txt @@ -0,0 +1,5 @@ +cached prometheus-blackbox-exporter 9.0.1 +rendered blackbox in 3.825430417s +cached prometheus 25.27.0 +rendered prometheus in 4.840089667s +rendered platform in 4.840137792s diff --git a/doc/md/_markdown-tests/script-02-helm-values/render.sh b/doc/md/_markdown-tests/script-02-helm-values/render.sh new file mode 100644 index 00000000..4fd3201e --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/render.sh @@ -0,0 +1 @@ +holos render platform diff --git a/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.git.commit.sh b/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.git.commit.sh new file mode 100644 index 00000000..3d0906d6 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.git.commit.sh @@ -0,0 +1 @@ +git add . && git commit -m 'render integrated blackbox and prometheus manifests' diff --git a/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.git.output.txt b/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.git.output.txt new file mode 100644 index 00000000..c26c94e7 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.git.output.txt @@ -0,0 +1,2 @@ +[main 67efe0d] render integrated blackbox and prometheus manifests + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.render.output.txt b/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.render.output.txt new file mode 100644 index 00000000..5c446b02 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/reviewing.changes.render.output.txt @@ -0,0 +1,3 @@ +rendered blackbox in 374.810666ms +rendered prometheus in 382.899334ms +rendered platform in 383.270625ms diff --git a/doc/md/_markdown-tests/script-02-helm-values/update.sh b/doc/md/_markdown-tests/script-02-helm-values/update.sh new file mode 100755 index 00000000..83e3a56f --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/update.sh @@ -0,0 +1,4 @@ +#! /bin/bash +set -euo pipefail +[[ -s "$1" ]] && [[ -z "${HOLOS_UPDATE_SCRIPTS:-}" ]] && exit 0 +cat > "$1" diff --git a/doc/md/_markdown-tests/script-02-helm-values/values.patch b/doc/md/_markdown-tests/script-02-helm-values/values.patch new file mode 100644 index 00000000..49fa4ce1 --- /dev/null +++ b/doc/md/_markdown-tests/script-02-helm-values/values.patch @@ -0,0 +1,31 @@ +--- a/components/blackbox/values.cue ++++ b/components/blackbox/values.cue +@@ -1,6 +1,8 @@ + package holos + + Helm: Values: { ++ fullnameOverride: Blackbox.host ++ + global: { + //# Global image registry to use if it needs to be overriden for some specific use cases (e.g local registries, custom images, ...) + //# +@@ -192,7 +194,7 @@ Helm: Values: { + annotations: {} + labels: {} + type: "ClusterIP" +- port: 9115 ++ port: Blackbox.port + ipDualStack: { + enabled: false + ipFamilies: ["IPv6", "IPv4"] +--- a/components/prometheus/values.cue ++++ b/components/prometheus/values.cue +@@ -1083,7 +1083,7 @@ Helm: Values: { + target_label: "__param_target" + }, { + target_label: "__address__" +- replacement: "blackbox" ++ replacement: "\(Blackbox.host):\(Blackbox.port)" + }, { + source_labels: ["__param_target"] + target_label: "instance" diff --git a/doc/md/markdown_test.go b/doc/md/markdown_test.go new file mode 100644 index 00000000..4f325f1f --- /dev/null +++ b/doc/md/markdown_test.go @@ -0,0 +1,87 @@ +package main + +import ( + "os" + "path/filepath" + "runtime" + "slices" + "strings" + "testing" + + "github.com/holos-run/holos/cmd" + "github.com/rogpeppe/go-internal/testscript" + + cue "cuelang.org/go/cmd/cue/cmd" +) + +func TestMain(m *testing.M) { + os.Exit(testscript.RunMain(m, map[string]func() int{ + "holos": cmd.MakeMain(), + "cue": cue.Main, + })) +} + +// Run these with go test -v to see the verbose names +func TestMarkdown(t *testing.T) { + t.Run("AddOnPromoter", func(t *testing.T) { + // Get an ordered list of test script files. + dir := "_markdown-tests" + for _, file := range sortedTestScripts(t, filepath.Join(dir, "examples")) { + t.Run("examples", func(t *testing.T) { + runOneScript(t, dir, file) + }) + } + }) +} + +func runOneScript(t *testing.T, dir string, file string) { + params := testscript.Params{ + Dir: "", + Files: []string{file}, + RequireExplicitExec: true, + RequireUniqueNames: false, + WorkdirRoot: filepath.Join(testDir(t), dir), + UpdateScripts: os.Getenv("HOLOS_UPDATE_SCRIPTS") != "", + Setup: func(env *testscript.Env) error { + // Needed for update.sh to determine if we need to update output files. + env.Setenv("HOLOS_UPDATE_SCRIPTS", os.Getenv("HOLOS_UPDATE_SCRIPTS")) + // Just like cmd/cue/cmd.TestScript, set up separate cache and config dirs per test. + env.Setenv("CUE_CACHE_DIR", filepath.Join(env.WorkDir, "tmp/cachedir")) + configDir := filepath.Join(env.WorkDir, "tmp/configdir") + env.Setenv("CUE_CONFIG_DIR", configDir) + return nil + }, + } + + testscript.Run(t, params) +} + +// testDir returns the path of the directory containing the go source file of +// the caller. +func testDir(t *testing.T) string { + _, file, _, ok := runtime.Caller(0) + if !ok { + t.Fatal("could not get runtime caller") + } + return filepath.Dir(file) +} + +func sortedTestScripts(t *testing.T, dir string) (files []string) { + entries, err := os.ReadDir(dir) + if os.IsNotExist(err) { + // Continue to helpful error on len(files) == 0 below. + } else if err != nil { + t.Fatal(err) + } + for _, entry := range entries { + name := entry.Name() + if strings.HasSuffix(name, ".txtar") || strings.HasSuffix(name, ".txt") { + files = append(files, filepath.Join(dir, name)) + } + } + if len(files) == 0 { + t.Fatalf("no txtar nor txt scripts found in dir %s", dir) + } + slices.Sort(files) + return files +} diff --git a/doc/md/tutorial/helm-values.mdx b/doc/md/tutorial/helm-values.mdx index 1c03bea2..9e7e5577 100644 --- a/doc/md/tutorial/helm-values.mdx +++ b/doc/md/tutorial/helm-values.mdx @@ -8,6 +8,7 @@ sidebar_position: 40 import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import YouTube from '@site/src/components/YouTube'; +import CodeBlock from '@theme/CodeBlock'; @@ -41,82 +42,57 @@ resource. ## The Code +### Holos Version + +Ensure you have a current version of `holos` installed. This document was +tested with the following version. + +import HolosVersionCommand from '!!raw-loader!../_markdown-tests/script-01-holos-version/command.sh'; +import HolosVersionOutput from '!!raw-loader!../_markdown-tests/script-01-holos-version/output.txt'; + +{HolosVersionCommand} +{HolosVersionOutput} + ### Generating the structure Use `holos` to generate a minimal platform directory structure. First, create and navigate into a blank directory, then use the `holos init platform` command: -```shell -mkdir holos-helm-values-tutorial -cd holos-helm-values-tutorial -holos init platform v1alpha5 -``` +import MkdirAndInit from '!!raw-loader!../_markdown-tests/script-02-helm-values/mkdir.and.init.sh'; + +{MkdirAndInit} Make an initial commit to track changes: -```bash -git init . && git add . && git commit -m "initial commit" -``` +import GitInit from '!!raw-loader!../_markdown-tests/script-02-helm-values/git.init.sh'; + +{GitInit} ### Managing the Components Create the `prometheus` and `blackbox` component directories, then add each of the following file contents. -```bash -mkdir -p components/prometheus components/blackbox -``` +import MkdirComponents from '!!raw-loader!../_markdown-tests/script-02-helm-values/mkdir.components.sh'; +import PrometheusComponentHeader from '!!raw-loader!../_markdown-tests/script-02-helm-values/prometheus.component.header.sh'; +import PrometheusComponentBody from '!!raw-loader!../_markdown-tests/script-02-helm-values/prometheus.component.body.cue'; +import BlackboxComponentHeader from '!!raw-loader!../_markdown-tests/script-02-helm-values/blackbox.component.header.sh'; +import BlackboxComponentBody from '!!raw-loader!../_markdown-tests/script-02-helm-values/blackbox.component.body.cue'; +import EofTrailer from '!!raw-loader!../_markdown-tests/script-02-helm-values/eof.trailer.sh'; + + +{MkdirComponents} -```bash -cat < components/prometheus/prometheus.cue -``` -```cue showLineNumbers -package holos - -// Produce a helm chart build plan. -holos: Helm.BuildPlan - -Helm: #Helm & { - Chart: { - name: "prometheus" - version: "25.27.0" - repository: { - name: "prometheus-community" - url: "https://prometheus-community.github.io/helm-charts" - } - } -} -``` -```bash -EOF -``` + {PrometheusComponentHeader} + {PrometheusComponentBody} + {EofTrailer} -```bash -cat < components/blackbox/blackbox.cue -``` -```cue showLineNumbers -package holos - -// Produce a helm chart build plan. -holos: Helm.BuildPlan - -Helm: #Helm & { - Chart: { - name: "prometheus-blackbox-exporter" - version: "9.0.1" - repository: { - name: "prometheus-community" - url: "https://prometheus-community.github.io/helm-charts" - } - } -} -``` -```bash -EOF -``` + {BlackboxComponentHeader} + {BlackboxComponentBody} + {EofTrailer} @@ -124,64 +100,38 @@ EOF Register the components with the platform by adding the following file to the platform directory. -```bash -cat < platform/prometheus.cue -``` -```cue showLineNumbers -package holos - -Platform: Components: { - prometheus: { - name: "prometheus" - path: "components/prometheus" - } - blackbox: { - name: "blackbox" - path: "components/blackbox" - } -} -``` -```bash -EOF -``` +import RegisterComponentsHeader from '!!raw-loader!../_markdown-tests/script-02-helm-values/register.components.header.sh'; +import RegisterComponentsBody from '!!raw-loader!../_markdown-tests/script-02-helm-values/register.components.body.cue'; + +{RegisterComponentsHeader} +{RegisterComponentsBody} +{EofTrailer} Render the platform. +import RenderCommand from '!!raw-loader!../_markdown-tests/script-02-helm-values/render.sh'; +import RegisterComponentsRenderOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/register.components.output.txt'; + -```bash -holos render platform -``` + {RenderCommand} -```txt -cached prometheus-blackbox-exporter 9.0.1 -rendered blackbox in 3.825430417s -cached prometheus 25.27.0 -rendered prometheus in 4.840089667s -rendered platform in 4.840137792s -``` + {RegisterComponentsRenderOutput} Commit the results. +import GitCommitRegisterComponents from '!!raw-loader!../_markdown-tests/script-02-helm-values/register.components.git.commit.sh'; +import RegisterComponentsGitOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/register.components.git.commit.output.txt'; + -```bash -git add . && git commit -m 'add blackbox and prometheus' -``` + {GitCommitRegisterComponents} -```txt -[main b5df111] add blackbox and prometheus - 5 files changed, 1550 insertions(+) - create mode 100644 components/blackbox/blackbox.cue - create mode 100644 components/prometheus/prometheus.cue - create mode 100644 deploy/components/blackbox/blackbox.gen.yaml - create mode 100644 deploy/components/prometheus/prometheus.gen.yaml - create mode 100644 platform/prometheus.cue -``` + {RegisterComponentsGitOutput} @@ -190,21 +140,11 @@ git add . && git commit -m 'add blackbox and prometheus' Holos renders Helm charts with their default values. We can import these default values into CUE to work with them as structured data instead of text markup. -```bash -holos cue import \ - --package holos \ - --path 'Helm: Values:' \ - --outfile components/prometheus/values.cue \ - components/prometheus/vendor/25.27.0/prometheus/values.yaml -``` - -```bash -holos cue import \ - --package holos \ - --path 'Helm: Values:' \ - --outfile components/blackbox/values.cue \ - components/blackbox/vendor/9.0.1/prometheus-blackbox-exporter/values.yaml -``` +import ImportPrometheusValues from '!!raw-loader!../_markdown-tests/script-02-helm-values/import.prometheus.values.sh'; +import ImportBlackboxValues from '!!raw-loader!../_markdown-tests/script-02-helm-values/import.blackbox.values.sh'; + +{ImportPrometheusValues} +{ImportBlackboxValues} These commands convert the YAML data into CUE code and nest the values under the `Values` field of the `Helm` struct. @@ -215,34 +155,25 @@ CUE unifies `values.cue` with the other `\*.cue` files in the same directory. Render the platform using `holos render platform` and commit the results. +import ImportValuesRenderOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/import.values.render.output.txt'; +import ImportValuesGitCommit from '!!raw-loader!../_markdown-tests/script-02-helm-values/import.values.git.commit.sh'; +import ImportValuesGitOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/import.values.git.output.txt'; + -```bash -holos render platform -``` + {RenderCommand} -```txt -rendered blackbox in 365.936792ms -rendered prometheus in 371.855875ms -rendered platform in 372.109916ms -``` + {ImportValuesRenderOutput} -```bash -git add . && git commit -m 'import values' -``` + {ImportValuesGitCommit} -```txt -[main 52e90ea] import values - 2 files changed, 1815 insertions(+) - create mode 100644 components/blackbox/values.cue - create mode 100644 components/prometheus/values.cue -``` + {ImportValuesGitOutput} @@ -252,30 +183,12 @@ To manage shared configuration for both Helm charts, define a structure that holds the common configuration values. Place this configuration in the `components` directory to ensure it is accessible to all components. +import BlackboxCommonConfigHeader from '!!raw-loader!../_markdown-tests/script-02-helm-values/blackbox.common.config.header.sh'; +import BlackboxCommonConfigBody from '!!raw-loader!../_markdown-tests/script-02-helm-values/blackbox.common.config.body.cue'; -```bash -cat < components/blackbox.cue -``` -```cue showLineNumbers -package holos - -// Schema Definition -#Blackbox: { - // host constrained to a lower case dns label - host: string & =~"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$" - // port constrained to a valid range - port: int & >0 & <=65535 -} - -// Concrete values must validate against the schema. -Blackbox: #Blackbox & { - host: "blackbox" - port: 9115 -} -``` -```bash -EOF -``` +{BlackboxCommonConfigHeader} +{BlackboxCommonConfigBody} +{EofTrailer} :::important 1. CUE loads and unifies all `*.cue` files from the root directory containing @@ -286,18 +199,15 @@ languages with only type checking. Add and commit the configuration. +import BlackboxCommonConfigGit from '!!raw-loader!../_markdown-tests/script-02-helm-values/blackbox.common.config.git.commit.sh'; +import BlackboxCommonConfigGitOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/blackbox.common.config.git.output.txt'; + -```bash -git add . && git commit -m 'add blackbox configuration' -``` + {BlackboxCommonConfigGit} -```txt -[main 1adcd08] add blackbox configuration - 1 file changed, 15 insertions(+) - create mode 100644 components/blackbox.cue -``` + {BlackboxCommonConfigGitOutput} @@ -309,52 +219,19 @@ and reliable using Holos and CUE. To apply the common configuration, patch the two `values.cue` files, or manually edit them to reference `Blackbox.host` and `Blackbox.port`. +import CommonConfigPatchCommand from '!!raw-loader!../_markdown-tests/script-02-helm-values/common.config.patch.sh'; +import CommonConfigPatchDiff from '!!raw-loader!../_markdown-tests/script-02-helm-values/values.patch'; +import CommonConfigPatchOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/common.config.patch.txt'; + -```bash -patch -p1 < values.patch -``` + {CommonConfigPatchCommand} -```diff ---- a/components/blackbox/values.cue -+++ b/components/blackbox/values.cue -@@ -1,6 +1,8 @@ - package holos - - Helm: Values: { -+ fullnameOverride: Blackbox.host -+ - global: { - //# Global image registry to use if it needs to be overriden for some specific use cases (e.g local registries, custom images, ...) - //# -@@ -192,7 +194,7 @@ Helm: Values: { - annotations: {} - labels: {} - type: "ClusterIP" -- port: 9115 -+ port: Blackbox.port - ipDualStack: { - enabled: false - ipFamilies: ["IPv6", "IPv4"] ---- a/components/prometheus/values.cue -+++ b/components/prometheus/values.cue -@@ -1083,7 +1083,7 @@ Helm: Values: { - target_label: "__param_target" - }, { - target_label: "__address__" -- replacement: "blackbox" -+ replacement: "\(Blackbox.host):\(Blackbox.port)" - }, { - source_labels: ["__param_target"] - target_label: "instance" -``` + {CommonConfigPatchDiff} -```txt -patching file 'components/blackbox/values.cue' -patching file 'components/prometheus/values.cue' -``` + {CommonConfigPatchOutput} @@ -365,20 +242,17 @@ safely and easily. Remove the patch file, then commit the changes. +import CommonConfigPatchRm from '!!raw-loader!../_markdown-tests/script-02-helm-values/common.config.rm.sh'; +import CommonConfigPatchGitCommit from '!!raw-loader!../_markdown-tests/script-02-helm-values/common.config.git.sh'; +import CommonConfigPatchGitCommitOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/common.config.git.output.txt'; + -```bash -rm values.patch -``` -```bash -git add . && git commit -m 'integrate blackbox and prometheus together' -``` + {CommonConfigPatchRm} + {CommonConfigPatchGitCommit} -```txt -[main 4221803] integrate blackbox and prometheus together - 2 files changed, 4 insertions(+), 2 deletions(-) -``` + {CommonConfigPatchGitCommitOutput} @@ -387,97 +261,28 @@ git add . && git commit -m 'integrate blackbox and prometheus together' Holos makes it easy to view and review platform-wide changes. Render the platform to observe how both Prometheus and Blackbox update in sync. +import ReviewingChangesRenderOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/reviewing.changes.render.output.txt'; + -```bash -holos render platform -``` + {RenderCommand} -```txt -rendered blackbox in 374.810666ms -rendered prometheus in 382.899334ms -rendered platform in 383.270625ms -``` + {ReviewingChangesRenderOutput} Changes are easily visible in version control. +import GitDiffCommand from '!!raw-loader!../_markdown-tests/script-02-helm-values/git.diff.sh'; +import GitDiff from '!!raw-loader!../_markdown-tests/script-02-helm-values/git.diff'; + -```bash -git diff -``` + {GitDiffCommand} -```diff -diff --git a/deploy/components/blackbox/blackbox.gen.yaml b/deploy/components/blackbox/blackbox.gen.yaml -index 3db20cd..5336f44 100644 ---- a/deploy/components/blackbox/blackbox.gen.yaml -+++ b/deploy/components/blackbox/blackbox.gen.yaml -@@ -7,7 +7,7 @@ metadata: - app.kubernetes.io/name: prometheus-blackbox-exporter - app.kubernetes.io/version: v0.25.0 - helm.sh/chart: prometheus-blackbox-exporter-9.0.1 -- name: prometheus-blackbox-exporter -+ name: blackbox - namespace: default - --- - apiVersion: v1 -@@ -31,7 +31,7 @@ metadata: - app.kubernetes.io/name: prometheus-blackbox-exporter - app.kubernetes.io/version: v0.25.0 - helm.sh/chart: prometheus-blackbox-exporter-9.0.1 -- name: prometheus-blackbox-exporter -+ name: blackbox - namespace: default - --- - apiVersion: v1 -@@ -43,7 +43,7 @@ metadata: - app.kubernetes.io/name: prometheus-blackbox-exporter - app.kubernetes.io/version: v0.25.0 - helm.sh/chart: prometheus-blackbox-exporter-9.0.1 -- name: prometheus-blackbox-exporter -+ name: blackbox - namespace: default - spec: - ports: -@@ -65,7 +65,7 @@ metadata: - app.kubernetes.io/name: prometheus-blackbox-exporter - app.kubernetes.io/version: v0.25.0 - helm.sh/chart: prometheus-blackbox-exporter-9.0.1 -- name: prometheus-blackbox-exporter -+ name: blackbox - namespace: default - spec: - replicas: 1 -@@ -119,8 +119,8 @@ spec: - name: config - hostNetwork: false - restartPolicy: Always -- serviceAccountName: prometheus-blackbox-exporter -+ serviceAccountName: blackbox - volumes: - - configMap: -- name: prometheus-blackbox-exporter -+ name: blackbox - name: config -diff --git a/deploy/components/prometheus/prometheus.gen.yaml b/deploy/components/prometheus/prometheus.gen.yaml -index 9e02bce..ab638f0 100644 ---- a/deploy/components/prometheus/prometheus.gen.yaml -+++ b/deploy/components/prometheus/prometheus.gen.yaml -@@ -589,7 +589,7 @@ data: - - source_labels: - - __address__ - target_label: __param_target -- - replacement: blackbox -+ - replacement: blackbox:9115 - target_label: __address__ - - source_labels: - - __param_target - -``` + {GitDiff} @@ -494,17 +299,15 @@ Blackbox host or port will reconfigure both charts correctly. Commit the changes and proceed to deploy them. +import ReviewingChangesGitCommit from '!!raw-loader!../_markdown-tests/script-02-helm-values/reviewing.changes.git.commit.sh'; +import ReviewingChangesGitOutput from '!!raw-loader!../_markdown-tests/script-02-helm-values/reviewing.changes.git.output.txt'; + -```bash -git add . && git commit -m 'render integrated blackbox and prometheus manifests' -``` + {ReviewingChangesGitCommit} -```txt -[main 67efe0d] render integrated blackbox and prometheus manifests - 2 files changed, 7 insertions(+), 7 deletions(-) -``` + {ReviewingChangesGitOutput}