Skip to content

Commit

Permalink
doc: Import blackbox common configuration
Browse files Browse the repository at this point in the history
This commit updates the Helm Values document so that we import the
common configuration instead of relying upon CUE's ability to search
root-to-leaf for all *.cue files.
  • Loading branch information
glarizza committed Jan 10, 2025
1 parent bb050fa commit c59df4b
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 38 deletions.
35 changes: 26 additions & 9 deletions doc/md/tutorial/_helm-values/examples/02-helm-values.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ exec bash -c 'bash -euo pipefail $WORK/import-values-git-commit.sh'
stdin stdout
exec $WORK/update.sh $WORK/import-values-git-output.txt

# Create the common configuration path
exec bash -c 'bash -euo pipefail $WORK/mkdir-common-config.sh'

# 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
Expand Down Expand Up @@ -211,10 +214,12 @@ git add . && git commit -m 'import values'
2 files changed, 1815 insertions(+)
create mode 100644 components/blackbox/values.cue
create mode 100644 components/prometheus/values.cue
-- mkdir-common-config.sh --
mkdir -p config/prometheus
-- blackbox-common-config-header.sh --
cat <<EOF > components/blackbox.cue
cat <<EOF > config/prometheus/blackbox.cue
-- blackbox-common-config-body.cue --
package holos
package prometheus

// Schema Definition
#Blackbox: {
Expand All @@ -225,7 +230,7 @@ package holos
}

// Concrete values must validate against the schema.
Blackbox: #Blackbox & {
blackbox: #Blackbox & {
host: "blackbox"
port: 9115
}
Expand All @@ -240,32 +245,44 @@ patch -p1 < values.patch
-- values.patch --
--- a/components/blackbox/values.cue
+++ b/components/blackbox/values.cue
@@ -1,6 +1,8 @@
@@ -1,6 +1,11 @@
package holos

+// Import common blackbox configuration
+import "holos.example/config/prometheus"
+
Helm: Values: {
+ fullnameOverride: Blackbox.host
+ fullnameOverride: prometheus.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: {
@@ -192,7 +197,7 @@ Helm: Values: {
annotations: {}
labels: {}
type: "ClusterIP"
- port: 9115
+ port: Blackbox.port
+ port: prometheus.blackbox.port
ipDualStack: {
enabled: false
ipFamilies: ["IPv6", "IPv4"]
--- a/components/prometheus/values.cue
+++ b/components/prometheus/values.cue
@@ -1083,7 +1083,7 @@ Helm: Values: {
@@ -1,5 +1,8 @@
package holos

+// Import common blackbox configuration
+import "holos.example/config/prometheus"
+
Helm: Values: {
// yaml-language-server: $schema=values.schema.json
// Default values for prometheus.
@@ -1083,7 +1086,7 @@ Helm: Values: {
target_label: "__param_target"
}, {
target_label: "__address__"
- replacement: "blackbox"
+ replacement: "\(Blackbox.host):\(Blackbox.port)"
+ replacement: "\(prometheus.blackbox.host):\(prometheus.blackbox.port)"
}, {
source_labels: ["__param_target"]
target_label: "instance"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.102.4
0.102.5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package holos
package prometheus

// Schema Definition
#Blackbox: {
Expand All @@ -9,7 +9,7 @@ package holos
}

// Concrete values must validate against the schema.
Blackbox: #Blackbox & {
blackbox: #Blackbox & {
host: "blackbox"
port: 9115
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[main ffea4dd] add blackbox configuration
[main 884be5f] add blackbox configuration
1 file changed, 15 insertions(+)
create mode 100644 components/blackbox.cue
create mode 100644 config/prometheus/blackbox.cue
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cat <<EOF > components/blackbox.cue
cat <<EOF > config/prometheus/blackbox.cue
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[main a4bc817] integrate blackbox and prometheus together
2 files changed, 4 insertions(+), 2 deletions(-)
[main 209de0b] integrate blackbox and prometheus together
3 files changed, 1348 insertions(+), 2 deletions(-)
create mode 100644 components/prometheus/values.cue.orig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[main d8046af] import values
[main 7c2a61e] import values
2 files changed, 1815 insertions(+)
create mode 100644 components/blackbox/values.cue
create mode 100644 components/prometheus/values.cue
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rendered blackbox in 161.782375ms
rendered prometheus in 203.388ms
rendered platform in 203.481459ms
rendered blackbox in 168.983792ms
rendered prometheus in 206.797625ms
rendered platform in 207.001459ms
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mkdir -p config/prometheus
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[main 8971a74] add blackbox and prometheus
[main 4bebc8b] add blackbox and prometheus
5 files changed, 1550 insertions(+)
create mode 100644 components/blackbox/blackbox.cue
create mode 100644 components/prometheus/prometheus.cue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rendered blackbox in 1.324044833s
rendered prometheus in 1.336657625s
rendered platform in 1.33672525s
rendered blackbox in 1.108670875s
rendered prometheus in 1.114354292s
rendered platform in 1.114471791s
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[main 1200227] render integrated blackbox and prometheus manifests
[main 09736f1] render integrated blackbox and prometheus manifests
2 files changed, 7 insertions(+), 7 deletions(-)
24 changes: 18 additions & 6 deletions doc/md/tutorial/_helm-values/script-02-helm-values/values.patch
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
--- a/components/blackbox/values.cue
+++ b/components/blackbox/values.cue
@@ -1,6 +1,8 @@
@@ -1,6 +1,11 @@
package holos

+// Import common blackbox configuration
+import "holos.example/config/prometheus"
+
Helm: Values: {
+ fullnameOverride: Blackbox.host
+ fullnameOverride: prometheus.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: {
@@ -192,7 +197,7 @@ Helm: Values: {
annotations: {}
labels: {}
type: "ClusterIP"
- port: 9115
+ port: Blackbox.port
+ port: prometheus.blackbox.port
ipDualStack: {
enabled: false
ipFamilies: ["IPv6", "IPv4"]
--- a/components/prometheus/values.cue
+++ b/components/prometheus/values.cue
@@ -1083,7 +1083,7 @@ Helm: Values: {
@@ -1,5 +1,8 @@
package holos

+// Import common blackbox configuration
+import "holos.example/config/prometheus"
+
Helm: Values: {
// yaml-language-server: $schema=values.schema.json
// Default values for prometheus.
@@ -1083,7 +1086,7 @@ Helm: Values: {
target_label: "__param_target"
}, {
target_label: "__address__"
- replacement: "blackbox"
+ replacement: "\(Blackbox.host):\(Blackbox.port)"
+ replacement: "\(prometheus.blackbox.host):\(prometheus.blackbox.port)"
}, {
source_labels: ["__param_target"]
target_label: "instance"
15 changes: 10 additions & 5 deletions doc/md/tutorial/helm-values.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@ import ImportValuesGitOutput from '!!raw-loader!./_helm-values/script-02-helm-va
### Managing Common Configuration

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.
holds the common configuration values. Create a `config` directory at the root
of the repository, and place the configuration file there to ensure it is
accessible to all components.

import BlackboxCommonConfigMkdir from '!!raw-loader!./_helm-values/script-02-helm-values/mkdir-common-config.sh';
import BlackboxCommonConfigHeader from '!!raw-loader!./_helm-values/script-02-helm-values/blackbox-common-config-header.sh';
import BlackboxCommonConfigBody from '!!raw-loader!./_helm-values/script-02-helm-values/blackbox-common-config-body.cue';

<CodeBlock language="bash">{BlackboxCommonConfigMkdir}</CodeBlock>
<CodeBlock language="bash">{BlackboxCommonConfigHeader}</CodeBlock>
<CodeBlock language="cue" showLineNumbers>{BlackboxCommonConfigBody}</CodeBlock>
<CodeBlock language="bash" showLineNumbers>{EofTrailer}</CodeBlock>
Expand Down Expand Up @@ -214,10 +217,12 @@ import BlackboxCommonConfigGitOutput from '!!raw-loader!./_helm-values/script-02
### Using Common Configuration Across Components

Referencing common configuration across multiple components is straightforward
and reliable using Holos and CUE.
and reliable using Holos and CUE. Configuration can be imported where necessary
following [CUE module standards], which are similar to Golang.

To apply the common configuration, patch the two `values.cue` files, or manually
edit them to reference `Blackbox.host` and `Blackbox.port`.
edit them to import the configuration and reference `prometheus.blackbox.host`
and `prometheus.blackbox.port`.

import CommonConfigPatchCommand from '!!raw-loader!./_helm-values/script-02-helm-values/common-config-patch.sh';
import CommonConfigPatchDiff from '!!raw-loader!./_helm-values/script-02-helm-values/values.patch';
Expand Down Expand Up @@ -327,7 +332,7 @@ service endpoint.
[prometheus]: https://github.com/prometheus-community/helm-charts/tree/prometheus-25.27.0/charts/prometheus
[blackbox]: https://github.com/prometheus-community/helm-charts/tree/prometheus-blackbox-exporter-9.0.1/charts/prometheus-blackbox-exporter
[httpbin]: https://github.com/mccutchen/go-httpbin/tree/v2.15.0

[CUE module standards]: https://cuelang.org/docs/concept/modules-packages-instances/
[Config Schema]: #config-schema

[Technical Overview]: ./overview.mdx
Expand Down
2 changes: 1 addition & 1 deletion doc/md/tutorial/helm-values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestMain(m *testing.M) {

// Run these with go test -v to see the verbose names
func TestHelmValues(t *testing.T) {
t.Run("AddOnPromoter", func(t *testing.T) {
t.Run("TestHelmValues", func(t *testing.T) {
// Get an ordered list of test script files.
dir := "_helm-values"
for _, file := range sortedTestScripts(t, filepath.Join(dir, "examples")) {
Expand Down

0 comments on commit c59df4b

Please sign in to comment.