|
| 1 | +# Set $HOME because: |
| 2 | +# - Helm uses it for temporary files |
| 3 | +# - Git requires it for setting author name/email globally |
| 4 | +env HOME=$WORK/.tmp |
| 5 | +chmod 0755 $WORK/update.sh |
| 6 | + |
| 7 | +# Configure git author for testscript execution |
| 8 | +exec git config --global user.name 'Holos Docs' |
| 9 | +exec git config --global user.email 'hello@holos.run' |
| 10 | +exec git config --global init.defaultBranch main |
| 11 | + |
| 12 | +# Remove the tutorial directory if it already exists |
| 13 | +exec rm -rf holos-helm-values-tutorial |
| 14 | + |
| 15 | +# Create and change to the tutorial directory, and then initialize the Holos platform |
| 16 | +exec bash -c 'bash -euo pipefail mkdir.and.init.sh' |
| 17 | +cd holos-helm-values-tutorial |
| 18 | + |
| 19 | +# Git init and create the component directories |
| 20 | +exec bash -c 'bash -euo pipefail $WORK/git.init.sh' |
| 21 | +exec bash -c 'bash -euo pipefail $WORK/mkdir.components.sh' |
| 22 | + |
| 23 | +# Combine and execute the multiline prometheus/blackbox component header/body/trailer files |
| 24 | +exec cat $WORK/prometheus.component.header.sh ../prometheus.component.body.cue ../eof.trailer.sh |
| 25 | +stdin stdout |
| 26 | +exec bash -xeuo pipefail |
| 27 | +exec cat $WORK/blackbox.component.header.sh ../blackbox.component.body.cue ../eof.trailer.sh |
| 28 | +stdin stdout |
| 29 | +exec bash -xeuo pipefail |
| 30 | + |
| 31 | +# Combine and execute the multiline platform registration header/body/trailer files. |
| 32 | +exec cat $WORK/register.components.header.sh ../register.components.body.cue ../eof.trailer.sh |
| 33 | +stdin stdout |
| 34 | +exec bash -xeuo pipefail |
| 35 | + |
| 36 | +# Render the platform, capture stdout, and use update.sh to gate whether the |
| 37 | +# output file should be updated. |
| 38 | +# |
| 39 | +# NOTE: The [net] condition will test whether external network access is available |
| 40 | +[net] exec bash -c 'bash -euo pipefail $WORK/render.sh 2>&1' |
| 41 | +[net] stdin stdout |
| 42 | +exec $WORK/update.sh $WORK/register.components.output.txt |
| 43 | + |
| 44 | +# Commit and conditionally update the output file |
| 45 | +exec bash -c 'bash -euo pipefail $WORK/register.components.git.commit.sh' |
| 46 | +stdin stdout |
| 47 | +exec $WORK/update.sh $WORK/register.components.git.commit.output.txt |
| 48 | + |
| 49 | +# Import values |
| 50 | +exec bash -c 'bash -euo pipefail $WORK/import.prometheus.values.sh' |
| 51 | +exec bash -c 'bash -euo pipefail $WORK/import.blackbox.values.sh' |
| 52 | + |
| 53 | +# Render, update the output file, commit, and update the commit output file. |
| 54 | +[net] exec bash -c 'bash -euo pipefail $WORK/render.sh 2>&1' |
| 55 | +[net] stdin stdout |
| 56 | +exec $WORK/update.sh $WORK/import.values.render.output.txt |
| 57 | +exec bash -c 'bash -euo pipefail $WORK/import.values.git.commit.sh' |
| 58 | +stdin stdout |
| 59 | +exec $WORK/update.sh $WORK/import.values.git.output.txt |
| 60 | + |
| 61 | +# Combine and execute the common configuration header/body/trailer to write the cue file. |
| 62 | +exec cat $WORK/blackbox.common.config.header.sh ../blackbox.common.config.body.cue ../eof.trailer.sh |
| 63 | +stdin stdout |
| 64 | +exec bash -xeuo pipefail |
| 65 | + |
| 66 | +# Git commit blackbox common config |
| 67 | +exec bash -c 'bash -euo pipefail $WORK/blackbox.common.config.git.commit.sh' |
| 68 | +stdin stdout |
| 69 | +exec $WORK/update.sh $WORK/blackbox.common.config.git.output.txt |
| 70 | + |
| 71 | +# Patch the common config values file and write to output file. |
| 72 | +# |
| 73 | +# NOTE: Using a symlink here because the patch script references values.patch |
| 74 | +# within the same directory, but it actually lives one directory up in the |
| 75 | +# testscript $WORK dir. |
| 76 | +exec ln -s $WORK/values.patch values.patch |
| 77 | +exec bash -c 'bash -euo pipefail $WORK/common.config.patch.sh' |
| 78 | +stdin stdout |
| 79 | +exec $WORK/update.sh $WORK/common.config.patch.txt |
| 80 | + |
| 81 | +# Remove patch and commit changes |
| 82 | +exec bash -c 'bash -euo pipefail $WORK/common.config.rm.sh' |
| 83 | +exec bash -c 'bash -euo pipefail $WORK/common.config.git.sh' |
| 84 | +stdin stdout |
| 85 | +exec $WORK/update.sh $WORK/common.config.git.output.txt |
| 86 | + |
| 87 | +# Final render and update of output file. |
| 88 | +[net] exec bash -c 'bash -euo pipefail $WORK/render.sh 2>&1' |
| 89 | +[net] stdin stdout |
| 90 | +exec $WORK/update.sh $WORK/reviewing.changes.git.output.txt |
| 91 | + |
| 92 | +# Git diff and write to output file. |
| 93 | +exec bash -c 'bash -euo pipefail $WORK/git.diff.sh' |
| 94 | +stdin stdout |
| 95 | +exec $WORK/update.sh $WORK/git.diff |
| 96 | + |
| 97 | +# Final commit and write to output file |
| 98 | +exec bash -c 'bash -euo pipefail $WORK/reviewing.changes.git.commit.sh' |
| 99 | +stdin stdout |
| 100 | +exec $WORK/update.sh $WORK/reviewing.changes.git.output.txt |
| 101 | + |
| 102 | +# Clean up the tutorial directory and tmp $HOME directory |
| 103 | +cd $WORK |
| 104 | +exec rm -rf holos-helm-values-tutorial |
| 105 | +exec rm -rf $HOME |
| 106 | + |
| 107 | +-- update.sh -- |
| 108 | +#! /bin/bash |
| 109 | +set -euo pipefail |
| 110 | +[[ -s "$1" ]] && [[ -z "${HOLOS_UPDATE_SCRIPTS:-}" ]] && exit 0 |
| 111 | +cat > "$1" |
| 112 | +-- mkdir.and.init.sh -- |
| 113 | +mkdir holos-helm-values-tutorial |
| 114 | +cd holos-helm-values-tutorial |
| 115 | +holos init platform v1alpha5 |
| 116 | +-- git.init.sh -- |
| 117 | +git init . && git add . && git commit -m "initial commit" |
| 118 | +-- mkdir.components.sh -- |
| 119 | +mkdir -p components/prometheus components/blackbox |
| 120 | +-- prometheus.component.header.sh -- |
| 121 | +cat <<EOF > components/prometheus/prometheus.cue |
| 122 | +-- prometheus.component.body.cue -- |
| 123 | +package holos |
| 124 | + |
| 125 | +// Produce a helm chart build plan. |
| 126 | +holos: Helm.BuildPlan |
| 127 | + |
| 128 | +Helm: #Helm & { |
| 129 | + Chart: { |
| 130 | + name: "prometheus" |
| 131 | + version: "25.27.0" |
| 132 | + repository: { |
| 133 | + name: "prometheus-community" |
| 134 | + url: "https://prometheus-community.github.io/helm-charts" |
| 135 | + } |
| 136 | + } |
| 137 | +} |
| 138 | +-- eof.trailer.sh -- |
| 139 | +EOF |
| 140 | +-- blackbox.component.header.sh -- |
| 141 | +cat <<EOF > components/blackbox/blackbox.cue |
| 142 | +-- blackbox.component.body.cue -- |
| 143 | +package holos |
| 144 | + |
| 145 | +// Produce a helm chart build plan. |
| 146 | +holos: Helm.BuildPlan |
| 147 | + |
| 148 | +Helm: #Helm & { |
| 149 | + Chart: { |
| 150 | + name: "prometheus-blackbox-exporter" |
| 151 | + version: "9.0.1" |
| 152 | + repository: { |
| 153 | + name: "prometheus-community" |
| 154 | + url: "https://prometheus-community.github.io/helm-charts" |
| 155 | + } |
| 156 | + } |
| 157 | +} |
| 158 | +-- register.components.header.sh -- |
| 159 | +cat <<EOF > platform/prometheus.cue |
| 160 | +-- register.components.body.cue -- |
| 161 | +package holos |
| 162 | + |
| 163 | +Platform: Components: { |
| 164 | + prometheus: { |
| 165 | + name: "prometheus" |
| 166 | + path: "components/prometheus" |
| 167 | + } |
| 168 | + blackbox: { |
| 169 | + name: "blackbox" |
| 170 | + path: "components/blackbox" |
| 171 | + } |
| 172 | +} |
| 173 | +-- render.sh -- |
| 174 | +holos render platform |
| 175 | +-- register.components.output.txt -- |
| 176 | +cached prometheus-blackbox-exporter 9.0.1 |
| 177 | +rendered blackbox in 3.825430417s |
| 178 | +cached prometheus 25.27.0 |
| 179 | +rendered prometheus in 4.840089667s |
| 180 | +rendered platform in 4.840137792s |
| 181 | +-- register.components.git.commit.sh -- |
| 182 | +git add . && git commit -m 'add blackbox and prometheus' |
| 183 | +-- register.components.git.commit.output.txt -- |
| 184 | +[main b5df111] add blackbox and prometheus |
| 185 | + 5 files changed, 1550 insertions(+) |
| 186 | + create mode 100644 components/blackbox/blackbox.cue |
| 187 | + create mode 100644 components/prometheus/prometheus.cue |
| 188 | + create mode 100644 deploy/components/blackbox/blackbox.gen.yaml |
| 189 | + create mode 100644 deploy/components/prometheus/prometheus.gen.yaml |
| 190 | + create mode 100644 platform/prometheus.cue |
| 191 | +-- import.prometheus.values.sh -- |
| 192 | +holos cue import \ |
| 193 | + --package holos \ |
| 194 | + --path 'Helm: Values:' \ |
| 195 | + --outfile components/prometheus/values.cue \ |
| 196 | + components/prometheus/vendor/25.27.0/prometheus/values.yaml |
| 197 | +-- import.blackbox.values.sh -- |
| 198 | +holos cue import \ |
| 199 | + --package holos \ |
| 200 | + --path 'Helm: Values:' \ |
| 201 | + --outfile components/blackbox/values.cue \ |
| 202 | + components/blackbox/vendor/9.0.1/prometheus-blackbox-exporter/values.yaml |
| 203 | +-- import.values.render.output.txt -- |
| 204 | +rendered blackbox in 365.936792ms |
| 205 | +rendered prometheus in 371.855875ms |
| 206 | +rendered platform in 372.109916ms |
| 207 | +-- import.values.git.commit.sh -- |
| 208 | +git add . && git commit -m 'import values' |
| 209 | +-- import.values.git.output.txt -- |
| 210 | +[main 52e90ea] import values |
| 211 | + 2 files changed, 1815 insertions(+) |
| 212 | + create mode 100644 components/blackbox/values.cue |
| 213 | + create mode 100644 components/prometheus/values.cue |
| 214 | +-- blackbox.common.config.header.sh -- |
| 215 | +cat <<EOF > components/blackbox.cue |
| 216 | +-- blackbox.common.config.body.cue -- |
| 217 | +package holos |
| 218 | + |
| 219 | +// Schema Definition |
| 220 | +#Blackbox: { |
| 221 | + // host constrained to a lower case dns label |
| 222 | + host: string & =~"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$" |
| 223 | + // port constrained to a valid range |
| 224 | + port: int & >0 & <=65535 |
| 225 | +} |
| 226 | + |
| 227 | +// Concrete values must validate against the schema. |
| 228 | +Blackbox: #Blackbox & { |
| 229 | + host: "blackbox" |
| 230 | + port: 9115 |
| 231 | +} |
| 232 | +-- blackbox.common.config.git.commit.sh -- |
| 233 | +git add . && git commit -m 'add blackbox configuration' |
| 234 | +-- blackbox.common.config.git.output.txt -- |
| 235 | +[main 1adcd08] add blackbox configuration |
| 236 | + 1 file changed, 15 insertions(+) |
| 237 | + create mode 100644 components/blackbox.cue |
| 238 | +-- common.config.patch.sh -- |
| 239 | +patch -p1 < values.patch |
| 240 | +-- values.patch -- |
| 241 | +--- a/components/blackbox/values.cue |
| 242 | ++++ b/components/blackbox/values.cue |
| 243 | +@@ -1,6 +1,8 @@ |
| 244 | + package holos |
| 245 | + |
| 246 | + Helm: Values: { |
| 247 | ++ fullnameOverride: Blackbox.host |
| 248 | ++ |
| 249 | + global: { |
| 250 | + //# Global image registry to use if it needs to be overriden for some specific use cases (e.g local registries, custom images, ...) |
| 251 | + //# |
| 252 | +@@ -192,7 +194,7 @@ Helm: Values: { |
| 253 | + annotations: {} |
| 254 | + labels: {} |
| 255 | + type: "ClusterIP" |
| 256 | +- port: 9115 |
| 257 | ++ port: Blackbox.port |
| 258 | + ipDualStack: { |
| 259 | + enabled: false |
| 260 | + ipFamilies: ["IPv6", "IPv4"] |
| 261 | +--- a/components/prometheus/values.cue |
| 262 | ++++ b/components/prometheus/values.cue |
| 263 | +@@ -1083,7 +1083,7 @@ Helm: Values: { |
| 264 | + target_label: "__param_target" |
| 265 | + }, { |
| 266 | + target_label: "__address__" |
| 267 | +- replacement: "blackbox" |
| 268 | ++ replacement: "\(Blackbox.host):\(Blackbox.port)" |
| 269 | + }, { |
| 270 | + source_labels: ["__param_target"] |
| 271 | + target_label: "instance" |
| 272 | +-- common.config.patch.txt -- |
| 273 | +patching file 'components/blackbox/values.cue' |
| 274 | +patching file 'components/prometheus/values.cue' |
| 275 | +-- common.config.rm.sh -- |
| 276 | +rm values.patch |
| 277 | +-- common.config.git.sh -- |
| 278 | +git add . && git commit -m 'integrate blackbox and prometheus together' |
| 279 | +-- common.config.git.output.txt -- |
| 280 | +[main 4221803] integrate blackbox and prometheus together |
| 281 | + 2 files changed, 4 insertions(+), 2 deletions(-) |
| 282 | +-- reviewing.changes.render.output.txt -- |
| 283 | +rendered blackbox in 374.810666ms |
| 284 | +rendered prometheus in 382.899334ms |
| 285 | +rendered platform in 383.270625ms |
| 286 | +-- git.diff.sh -- |
| 287 | +git diff |
| 288 | +-- git.diff -- |
| 289 | +diff --git a/deploy/components/blackbox/blackbox.gen.yaml b/deploy/components/blackbox/blackbox.gen.yaml |
| 290 | +index 3db20cd..5336f44 100644 |
| 291 | +--- a/deploy/components/blackbox/blackbox.gen.yaml |
| 292 | ++++ b/deploy/components/blackbox/blackbox.gen.yaml |
| 293 | +@@ -7,7 +7,7 @@ metadata: |
| 294 | + app.kubernetes.io/name: prometheus-blackbox-exporter |
| 295 | + app.kubernetes.io/version: v0.25.0 |
| 296 | + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 |
| 297 | +- name: prometheus-blackbox-exporter |
| 298 | ++ name: blackbox |
| 299 | + namespace: default |
| 300 | + --- |
| 301 | + apiVersion: v1 |
| 302 | +@@ -31,7 +31,7 @@ metadata: |
| 303 | + app.kubernetes.io/name: prometheus-blackbox-exporter |
| 304 | + app.kubernetes.io/version: v0.25.0 |
| 305 | + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 |
| 306 | +- name: prometheus-blackbox-exporter |
| 307 | ++ name: blackbox |
| 308 | + namespace: default |
| 309 | + --- |
| 310 | + apiVersion: v1 |
| 311 | +@@ -43,7 +43,7 @@ metadata: |
| 312 | + app.kubernetes.io/name: prometheus-blackbox-exporter |
| 313 | + app.kubernetes.io/version: v0.25.0 |
| 314 | + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 |
| 315 | +- name: prometheus-blackbox-exporter |
| 316 | ++ name: blackbox |
| 317 | + namespace: default |
| 318 | + spec: |
| 319 | + ports: |
| 320 | +@@ -65,7 +65,7 @@ metadata: |
| 321 | + app.kubernetes.io/name: prometheus-blackbox-exporter |
| 322 | + app.kubernetes.io/version: v0.25.0 |
| 323 | + helm.sh/chart: prometheus-blackbox-exporter-9.0.1 |
| 324 | +- name: prometheus-blackbox-exporter |
| 325 | ++ name: blackbox |
| 326 | + namespace: default |
| 327 | + spec: |
| 328 | + replicas: 1 |
| 329 | +@@ -119,8 +119,8 @@ spec: |
| 330 | + name: config |
| 331 | + hostNetwork: false |
| 332 | + restartPolicy: Always |
| 333 | +- serviceAccountName: prometheus-blackbox-exporter |
| 334 | ++ serviceAccountName: blackbox |
| 335 | + volumes: |
| 336 | + - configMap: |
| 337 | +- name: prometheus-blackbox-exporter |
| 338 | ++ name: blackbox |
| 339 | + name: config |
| 340 | +diff --git a/deploy/components/prometheus/prometheus.gen.yaml b/deploy/components/prometheus/prometheus.gen.yaml |
| 341 | +index 9e02bce..ab638f0 100644 |
| 342 | +--- a/deploy/components/prometheus/prometheus.gen.yaml |
| 343 | ++++ b/deploy/components/prometheus/prometheus.gen.yaml |
| 344 | +@@ -589,7 +589,7 @@ data: |
| 345 | + - source_labels: |
| 346 | + - __address__ |
| 347 | + target_label: __param_target |
| 348 | +- - replacement: blackbox |
| 349 | ++ - replacement: blackbox:9115 |
| 350 | + target_label: __address__ |
| 351 | + - source_labels: |
| 352 | + - __param_target |
| 353 | +-- reviewing.changes.git.commit.sh -- |
| 354 | +git add . && git commit -m 'render integrated blackbox and prometheus manifests' |
| 355 | +-- reviewing.changes.git.output.txt -- |
| 356 | +[main 67efe0d] render integrated blackbox and prometheus manifests |
| 357 | + 2 files changed, 7 insertions(+), 7 deletions(-) |
0 commit comments