From 4211a862ce4c4f24c5baa426d69d7bf04a4e2e3a Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Sat, 30 Dec 2023 20:40:04 +0200 Subject: [PATCH] docs: Rename `_config` to `#config` Signed-off-by: Stefan Prodan --- docs/cue/module/apply-behavior.md | 12 ++++----- docs/cue/module/custom-resources.md | 12 ++++----- docs/cue/module/initialization.md | 37 +++++++++++++-------------- docs/cue/module/semver-constraints.md | 2 +- docs/cue/module/test-jobs.md | 14 +++++----- docs/module.md | 34 ++++++++++++------------ 6 files changed, 55 insertions(+), 56 deletions(-) diff --git a/docs/cue/module/apply-behavior.md b/docs/cue/module/apply-behavior.md index ba3ebe9c..bad1f8f7 100644 --- a/docs/cue/module/apply-behavior.md +++ b/docs/cue/module/apply-behavior.md @@ -27,11 +27,11 @@ import ( ) #TestJob: batchv1.#Job & { - _config: #Config + #config: #Config apiVersion: "batch/v1" kind: "Job" metadata: timoniv1.#MetaComponent & { - #Meta: _config.metadata + #Meta: #config.metadata #Component: "test" } metadata: annotations: timoniv1.Action.Force @@ -56,11 +56,11 @@ import ( ) #InstallJob: batchv1.#Job & { - _config: #Config + #config: #Config apiVersion: "batch/v1" kind: "Job" metadata: timoniv1.#MetaComponent & { - #Meta: _config.metadata + #Meta: #config.metadata #Component: "install" } metadata: annotations: timoniv1.Action.OneOff @@ -87,11 +87,11 @@ import ( ) #DatabasePVC: corev1.#PersistentVolumeClaim & { - _config: #Config + #config: #Config apiVersion: "v1" kind: "PersistentVolumeClaim" metadata: timoniv1.#MetaComponent & { - #Meta: _config.metadata + #Meta: #config.metadata #Component: "database" } metadata: annotations: timoniv1.Action.Keep diff --git a/docs/cue/module/custom-resources.md b/docs/cue/module/custom-resources.md index 1bb13900..8cd42378 100644 --- a/docs/cue/module/custom-resources.md +++ b/docs/cue/module/custom-resources.md @@ -51,18 +51,18 @@ import ( ) #ServiceMonitor: promv1.#ServiceMonitor & { - _config: #Config - metadata: _config.metadata + #config: #Config + metadata: #config.metadata spec: { endpoints: [{ // Change this to match the Service port where // your app exposes the /metrics endpoint port: "http-metrics" path: "/metrics" - interval: "\(_config.monitoring.interval)s" + interval: "\(#config.monitoring.interval)s" }] - namespaceSelector: matchNames: [_config.metadata.namespace] - selector: matchLabels: _config.selector.labels + namespaceSelector: matchNames: [#config.metadata.namespace] + selector: matchLabels: #config.selector.labels } } ``` @@ -101,7 +101,7 @@ In the `templates/config.cue` file, add the `ServiceMonitor` resource to the ins config: #Config if config.monitoring.enabled { - objects: servicemonitor: #ServiceMonitor & {_config: config} + objects: servicemonitor: #ServiceMonitor & {#config: config} } } diff --git a/docs/cue/module/initialization.md b/docs/cue/module/initialization.md index 576c1524..fc529de6 100644 --- a/docs/cue/module/initialization.md +++ b/docs/cue/module/initialization.md @@ -241,9 +241,9 @@ The `replicas` value is used in the `deployment.cue` template to set the ```cue #Deployment: appsv1.#Deployment & { - _config: #Config + #config: #Config spec: { - replicas: _config.replicas + replicas: #config.replicas } } @@ -263,8 +263,8 @@ and returns the list of objects with the `#Deployment` and `#Service` types: config: #Config objects: { - deploy: #Deployment & {_config: config} - service: #Service & {_config: config} + deploy: #Deployment & {#config: config} + service: #Service & {#config: config} } } @@ -306,18 +306,18 @@ import ( ) #Service: corev1.#Service & { - _config: #Config + #config: #Config apiVersion: "v1" kind: "Service" - metadata: _config.metadata - if _config.service.annotations != _|_ { - metadata: annotations: _config.service.annotations + metadata: #config.metadata + if #config.service.annotations != _|_ { + metadata: annotations: #config.service.annotations } spec: corev1.#ServiceSpec & { - selector: _config.selector.labels + selector: #config.selector.labels ports: [ { - port: _config.service.port + port: #config.service.port protocol: "TCP" name: "http" targetPort: name @@ -340,20 +340,19 @@ is a Kubernetes Service object, and that it should inherit all the fields from t `corev1.#Service` type. This ensures that the generated object will be validated against the Kubernetes API schema. -Inside the `#Service` definition, we have a `_config` field of type `#Config`. -The `_config` field is used as an input parameter for the user-supplied values. -The `_` prefix defines the field as hidden, meaning that it will not be part of the generated object. +Inside the `#Service` definition, we have a `#config` field of type `#Config`. +The `#config` field is used as an input parameter for the user-supplied values. The rest of the `#Service` definition is used to set the Kubernetes object fields -to the `_config` values. +to the `#config` values. Optional config fields, like the `service.annotations`, should be set only if the user supplied a value for them. To verify if a field has a value, we can use an if statement and map the config field inside: ```cue -if _config.service.annotations != _|_ { - metadata: annotations: _config.service.annotations +if #config.service.annotations != _|_ { + metadata: annotations: #config.service.annotations } ``` @@ -392,14 +391,14 @@ With the `|` operator we enumerate the allowed values for the `type` field. ### Map the field in the template -Open the `service.cue` file and set the `spec.type` field to the `_config.service.type` value: +Open the `service.cue` file and set the `spec.type` field to the `#config.service.type` value: ```cue #Service: corev1.#Service & { - _config: #Config + #config: #Config spec: { - type: _config.service.type + type: #config.service.type } } diff --git a/docs/cue/module/semver-constraints.md b/docs/cue/module/semver-constraints.md index 37362750..982e3d12 100644 --- a/docs/cue/module/semver-constraints.md +++ b/docs/cue/module/semver-constraints.md @@ -44,7 +44,7 @@ you can use the following condition in your module's `#Instance` definition: config: #Config if config.clusterVersion.minor >= 29 { - objects: flowSchema: #FlowSchema & {_config: config} + objects: flowSchema: #FlowSchema & {#config: config} } } diff --git a/docs/cue/module/test-jobs.md b/docs/cue/module/test-jobs.md index d14b6da0..97a4b955 100644 --- a/docs/cue/module/test-jobs.md +++ b/docs/cue/module/test-jobs.md @@ -36,29 +36,29 @@ import ( ) #TestJob: batchv1.#Job & { - _config: #Config + #config: #Config apiVersion: "batch/v1" kind: "Job" metadata: timoniv1.#MetaComponent & { - #Meta: _config.metadata + #Meta: #config.metadata #Component: "test" } metadata: annotations: timoniv1.Action.Force spec: batchv1.#JobSpec & { template: corev1.#PodTemplateSpec & { - let checksum = uuid.SHA1(uuid.ns.DNS, yaml.Marshal(_config)) + let checksum = uuid.SHA1(uuid.ns.DNS, yaml.Marshal(#config)) metadata: annotations: "timoni.sh/checksum": checksum spec: { containers: [{ name: "curl" - image: _config.test.image.reference - imagePullPolicy: _config.test.image.pullPolicy + image: #config.test.image.reference + imagePullPolicy: #config.test.image.pullPolicy command: [ "curl", "-v", "-m", "5", - "\(_config.metadata.name):\(_config.service.port)", + "\(#config.metadata.name):\(#config.service.port)", ] }] restartPolicy: "Never" @@ -99,7 +99,7 @@ In the module's `#Instance` definition we'll add the `#TestJob` to the `tests` l #Instance: { config: #Config - tests: curl: #TestJob & {_config: config} + tests: curl: #TestJob & {#config: config} } ``` diff --git a/docs/module.md b/docs/module.md index d96f1700..af8e8eb7 100644 --- a/docs/module.md +++ b/docs/module.md @@ -283,8 +283,8 @@ Example of defining an instance containing a Kubernetes Service and Deployment: config: #Config objects: { - svc: #Service & {_config: config} - deploy: #Deployment & {_config: config} + svc: #Service & {#config: config} + deploy: #Deployment & {#config: config} } } ``` @@ -303,16 +303,16 @@ import ( ) #Service: corev1.#Service & { - _config: #Config + #config: #Config apiVersion: "v1" kind: "Service" - metadata: _config.metadata + metadata: #config.metadata spec: corev1.#ServiceSpec & { type: corev1.#ServiceTypeClusterIP - selector: _config.selector.labels + selector: #config.selector.labels ports: [ { - port: _config.service.port + port: #config.service.port protocol: "TCP" name: "http" targetPort: name @@ -373,29 +373,29 @@ Example of a test that verifies that an app is accessible from inside the cluste // source: myapp/templates/job.cue #TestJob: batchv1.#Job & { - _config: #Config + #config: #Config apiVersion: "batch/v1" kind: "Job" metadata: timoniv1.#MetaComponent & { - #Meta: _config.metadata + #Meta: #config.metadata #Component: "test" } metadata: annotations: timoniv1.Action.Force spec: batchv1.#JobSpec & { template: corev1.#PodTemplateSpec & { - let _checksum = uuid.SHA1(uuid.ns.DNS, yaml.Marshal(_config)) + let _checksum = uuid.SHA1(uuid.ns.DNS, yaml.Marshal(#config)) metadata: annotations: "timoni.sh/checksum": "\(_checksum)" spec: { containers: [{ name: "curl" - image: _config.test.image.reference - imagePullPolicy: _config.test.image.pullPolicy + image: #config.test.image.reference + imagePullPolicy: #config.test.image.pullPolicy command: [ "curl", "-v", "-m", "5", - "\(_config.metadata.name):\(_config.service.port)", + "\(#config.metadata.name):\(#config.service.port)", ] }] restartPolicy: "Never" @@ -500,16 +500,16 @@ import ( ) #ServiceMonitor: promv1.#ServiceMonitor & { - _config: #Config - metadata: _config.metadata + #config: #Config + metadata: #config.metadata spec: { endpoints: [{ path: "/metrics" port: "http-metrics" - interval: "\(_config.monitoring.interval)s" + interval: "\(#config.monitoring.interval)s" }] - namespaceSelector: matchNames: [_config.metadata.namespace] - selector: matchLabels: _config.selector.labels + namespaceSelector: matchNames: [#config.metadata.namespace] + selector: matchLabels: #config.selector.labels } } ```