kcl icon indicating copy to clipboard operation
kcl copied to clipboard

[Discussion] The attribute operators `:` and `=` need to have a unified form that is easier for users to understand and use.

Open Peefy opened this issue 1 year ago • 4 comments

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?

Peefy avatar Sep 13 '22 09:09 Peefy

Before: {image = "xx", env = []} | {image = "override_image", env += []}

Peefy avatar Sep 23 '22 09:09 Peefy

{image = "xx", env = []} | builtin.OpObject {
    override: {
        image = "override_image"
    },
    append: {
        env: []
    }
}
builtin.OpObject {
    left: {image = "xx", env = []}
    override: {
        image = "override_image"
    },
    append: {
        env: []
    }
}

chai2010 avatar Sep 23 '22 09:09 chai2010

A = {
  image = "xx"
  env = []
}
B = {
  @override
  image = "override_image"
  @append
  env = []
}
A|B

He1pa avatar Sep 23 '22 09:09 He1pa

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

Peefy avatar Sep 23 '22 09:09 Peefy

  • 显式写出 keyword action. * IDE 启发式辅助识别,降低成本

Peefy avatar Nov 03 '22 09:11 Peefy

config1 = {   image : "xx",   env : [] } | {   image : "override_image",   env :<append> ["ENV"] }

NeverRaR avatar Nov 03 '22 09:11 NeverRaR