kcl
kcl copied to clipboard
[Discussion] The attribute operators `:` and `=` need to have a unified form that is easier for users to understand and use.
Discussion
In the configuration scenario, there are often problems of configuration data inheritance, overwriting, and merging, such as the classic three-way merge problem. Some parameters in different environments in multiple environments expect to inherit the configuration of the base, and some expect to override the configuration of the base.
Different attribute operators are supported in KCL to express configuration coverage and merging. At the language level, two attribute operators, :
and =
, are provided to express merge and coverage respectively. Although this provides the flexibility of configuration merging, there are two problems:
- There is no limit to the number of configuration merges, which makes users unclear about the path of their own configuration merges (improved by enhancing error messages and displaying merge tracing #193)
- The writing style of the user does not look at the document configuration and sometimes feels inconsistent (whether to use a more conspicuous symbol)
Reference
- KCL Config Operation: https://kusionstack.io/zh-CN/docs/reference/lang/lang/tour/#%E9%85%8D%E7%BD%AE%E6%93%8D%E4%BD%9C
- Jsonnet Nested Field Inheritance: https://jsonnet.org/ref/language.html
- The Logic of CUE: https://cuelang.org/docs/concepts/logic/
- Ksonnet: https://github.com/ksonnet/ksonnet
- StackOverflow Question where to place cross-environment Terraform configs?
Before: {image = "xx", env = []} | {image = "override_image", env += []}
{image = "xx", env = []} | builtin.OpObject {
override: {
image = "override_image"
},
append: {
env: []
}
}
builtin.OpObject {
left: {image = "xx", env = []}
override: {
image = "override_image"
},
append: {
env: []
}
}
A = {
image = "xx"
env = []
}
B = {
@override
image = "override_image"
@append
env = []
}
A|B
In addition, CUE can complete up to two layers of data inheritance through *default_value, and can write multi-environment configurations to a certain extent, but it seems that it cannot cover the problems and scenarios that KCL needs to solve. Ref: https://cuetorials.com/deep-dives/attributes/#cues-attributes
- 显式写出 keyword action. * IDE 启发式辅助识别,降低成本
config1 = { image : "xx", env : [] } | { image : "override_image", env :<append> ["ENV"] }