kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.41k stars 110 forks source link

feat: support conf merge in api ListVariables #1415

Closed zong-zhe closed 2 weeks ago

zong-zhe commented 2 weeks ago

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

2. What is the scope of this PR (e.g. component or file name):

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

This PR performs configuration merge in the api ListVariable().

Taking the following base.k and main.k as cases to explain the process of this configuration merge.

base.k

appConfiguration: AppConfiguration {
    resource: res.Resource {
        disk = "35Gi"
    }
}

main.k

appConfiguration: AppConfiguration {
    resource: res.Resource {
        cpu = "2"
        memory = "4Gi"
    }
}

Using appConfiguration.resource as the spec, ListVariables() will select two sub-trees in the AST and merge them.

After base.k and main.k are parsed by the KCL parser, the AST will be as follows:

appConfiguration -> resource -> {cpu="2", memory="4Gi"}
                 -> resource -> {disk = "35Gi"}

api ListVariables() will get the two sub-trees

appConfiguration -> resource -> {cpu="2", memory="4Gi"}
appConfiguration -> resource -> {disk = "35Gi"}

Then merge them:

appConfiguration -> resource -> {cpu="2", memory="4Gi", disk = "35Gi"}

Based on the spec appConfiguration.resource, it returns the corresponding configuration block {cpu="2", memory="4Gi", disk = "35Gi"}.

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links: