Self described in coding-style.cue
Try out in https://cuelang.org/play/ to understand how it works.
application: [N=_]: {
name: N
}The constraint above defines a struct with field name equals the key.
_is the top value, basically it means no constraint.Nis an alias which we may use as a reference to the value.[]is pattern, it define constraints that apply to a collection of fields.
Expression
let N="myapp"
application: (N): _results in
application: "myapp": _(N) is a dynamic field whose label is determined by an expression.
Expression
deploy: chart: _
if deploy.chart.build != _|_ {
application: build: deploy.chart.build
}results in
deploy: {
chart: _
}_|_is the bottom value. Any evaluation error in CUE results in a bottom value.ifdefines conditional fields.
#App: {
name: string
}
app: #App & {
name: "myapp"
}
appWithVersion: {
#App
version: "1.0.0"
}
// appWithVersion.version: field not allowed:
// appWithVersion: #App & {
// #App
// version: "1.0.0"
// }#defines a definition that closes a struct to forbid unknown fields.&is a unification of#Appwith a concrete value for the fieldname.{ A }is a struct contains an embedded value bypassing the definition restrict to add fieldversion.
Override default conditionally
*r | (r & {expr: strings.Replace(r.expr, T, "\(#var.alerts.threshold[r.alert][strings.ToLower(r.labels.severity)])", -1)})- Default to
rwhen threshold not defined, i.e#var.alerts.threshold[r.alert][strings.ToLower(r.labels.severity)]evals to_|_
Documents
- Tour - good first reading
- Kubernetes tutorial
- The CUE Language Specification - worth weeks of deep dive to understand the philosophy of CUE
- _Cuetorials - many useful patterns
CUE in upstream
- https://github.com/tnarg/rules_cue - current bazel rules for cue in git-av/maglev
- https://github.com/tnarg/cue_terraform - current tooling for terraform with cue
- https://github.com/seh/rules_cue - a more featureful set of bazel rules for cue