Skip to content

Commit

Permalink
docs: Rename _config to #config
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed Dec 30, 2023
1 parent 6deb373 commit c3bb793
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 56 deletions.
12 changes: 6 additions & 6 deletions docs/cue/module/apply-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions docs/cue/module/custom-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
```
Expand Down Expand Up @@ -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}
}
}
Expand Down
37 changes: 18 additions & 19 deletions docs/cue/module/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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}
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
```

Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/cue/module/semver-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
Expand Down
14 changes: 7 additions & 7 deletions docs/cue/module/test-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
}
```

Expand Down
34 changes: 17 additions & 17 deletions docs/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
```
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
```
Expand Down

0 comments on commit c3bb793

Please sign in to comment.