- Firstly, download and install KCL according to the instructions, and then prepare a Kubernetes environment.
We can run the following command to show the config.
cat main.k
The output is
schema App:
"""The application model."""
name: str
replicas: int
labels?: {str:str} = {app = name}
app: App {
name = "app"
replicas = 1
labels.key = "value"
}
We can run the command to get the config
kcl main.k
The output is
app:
name: app
replicas: 1
labels:
app: app
key: value
KCL allows us to directly modify the values in the configuration model through the KCL CLI -O|--overrides
parameter. The parameter contains three parts e.g., pkg
, identifier
, attribute
and override_value
.
kcl main.k -O override_spec
override_spec
represents a unified representation of the configuration model fields and values that need to be modified
override_spec: [[pkgpath] ":"] identifier ("=" value | "-")
pkgpath
: indicates the package path where the identifier needs to be modified, usually in the form ofa.b.c
. For the main package,pkgpath
is represented as__ main__
. When omitted or not written, it indicates the main packageidentifier
indicates the identifier that needs to modify the configuration, usually in the form ofa.b.c
.value
indicates the value of the configuration that needs to be modified, which can be any legal KCL expression, such as number/string literal value, list/dict/schema expression, etc.=
denotes modifying of the value of the identifier.-
denotes deleting of the identifier.
Run the command to update the application name.
kcl main.k -O app.name='new_app'
The output is
app:
name: new_app
replicas: 1
labels:
app: new_app
key: value
We can see the name
attribute of the app
config is updated to new_app
.
Besides, when we use KCL CLI -d
argument, the KCL file will be modified to the following content at the same time.
kcl main.k -O app.name='new_app' -d
schema App:
"""The application model."""
name: str
replicas: int
labels?: {str:str} = {app = name}
app: App {
name = "new_app"
replicas = 1
labels: {key = "value"}
}
Run the command to delete the key
attribute of labels
.
kcl main.k -O app.labels.key-
The output is
app:
name: app
replicas: 1
labels:
app: app