-
is kcl support Insert yaml fragment ? This is my configuration requirement, i want insert cni-plugins config in flannel helm chart values.yaml initcontinaer options. now i use shell command sed, i want know can kcl implement this configuration?
the source file: https://github.com/flannel-io/flannel/blob/master/chart/kube-flannel/templates/daemonset.yaml |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
Hi @willzhang there. Thank you for providing the information. ❤️ The first answer to your question is affirmative. 🎉 In fact, in-place mutating or validating of existing Kubernetes YAML configurations is a key capability provided by KCL. For this purpose, we propose the KRM KCL specification to carry KCL code to achieve this function. You can refer to here for more information:
In addition, we also provide many examples on container configuration editing and validation of KCL code models here. You can refer to these examples to insert container configurations, and we also welcome contributing more models e.g., |
Beta Was this translation helpful? Give feedback.
-
Besides, we have offered kcl operator to mutate k8s manifests at cluster runtime. Ref: https://github.com/kcl-lang/kcl-operator |
Beta Was this translation helpful? Give feedback.
-
i can't understand how to use this examples
|
Beta Was this translation helpful? Give feedback.
-
HI @willzhang, you can use this examples in the krm-kcl repo top level cat ./examples/mutation/add-certificates-volume/suite/good.yaml | go run main.go The input YAML is apiVersion: v1
kind: Pod
metadata:
name: nginx
annotations:
inject-certs: "enabled"
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80 The output YAML is (with volumes and volumeMounts) apiVersion: v1
kind: Pod
metadata:
annotations:
inject-certs: enabled
name: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80
volumeMounts:
- name: etc-ssl-certs
mountPath: /etc/ssl/certs
volumes:
- name: etc-ssl-certs
configMap:
name: ca-pemstore |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply. I find the good.yaml have Is this possible for kcl ? it's like So here are two questions: Here is a simple scenario. part1
part2, or maybe it's kcl lang yaml
run kcl
the results
|
Beta Was this translation helpful? Give feedback.
-
If you only want to use KCL code and YAML files, this is also possible. I will write the following example to illustrate: The kcl code (main.k) import yaml
yaml.decode(option("source", default="{}")) | {
# Use the `+=` to patch the cni-plugin sidecar container config
spec.containers += [
{
image: "docker.io/labring4docker/cni-plugins:v1.3.0"
name: "install-cni-plugins"
command: ["/bin/sh"]
args: ["-c", "cp -au /cni-plugins/* /cni-plugin/"]
}
]
} The source yaml (source.yaml) apiVersion: v1
kind: Pod
metadata:
annotations:
inject-certs: enabled
name: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80 Run the following command kcl main.k -D source="$(cat source.yaml)" -o output.yaml The output yaml (output.yaml) apiVersion: v1
kind: Pod
metadata:
annotations:
inject-certs: enabled
name: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80
- image: docker.io/labring4docker/cni-plugins:v1.3.0
name: install-cni-plugins
command:
- /bin/sh
args:
- -c
- cp -au /cni-plugins/* /cni-plugin/ |
Beta Was this translation helpful? Give feedback.
-
Furthermore, patching a helm template file with kcl syntax may be difficult as it is not a standard structure. Of course, we are conducting appropriate exploration, but the difficulty lies in the fact that the syntax structure of the helm template does not accurately represent the indentation (parent-child relationship of configuration fields) in yaml. |
Beta Was this translation helpful? Give feedback.
If you only want to use KCL code and YAML files, this is also possible. I will write the following example to illustrate:
The kcl code (main.k)
The source yaml (source.yaml)