
KCL 是一个开源的基于约束的记录及函数语言并通过成熟的编程语言技术和实践来改进对大量繁杂配置比如云原生 Kubernetes 配置场景的编写,致力于构建围绕配置的更好的模块化、扩展性和稳定性,更简单的逻辑编写,以及更简单的自动化和生态工具集成。
本栏目将会双周更新 KCL 语言社区最新动态,包括功能、官网更新和最新的社区动态等,帮助大家更好地了解 KCL 社区!
KCL 官网: https://kcl-lang.io
过去两周 (2023 07.26 - 08.09),KCL 所有项目中总计有34个 PR 被合并,感谢所有贡献者的杰出工作,以下是重点合并内容概述
感谢 @jakezhu9 对 KCL Import 工具 JsonSchema 转换的贡献
感谢 @xxmao123 对 Vim 和 NeoVim KCL 插件的贡献
感谢 @yyxhero 在 Helmfile KCL 插件支持中提供的帮助与支持
感谢 @nkabir, @mihaigalos, @prahaladramji, @dhhopen 等在使用 KCL 过程中提出的宝贵建议和讨论
KCL Import 工具在 Protobuf, OpenAPI 模型和 Go 结构体转换为 KCL Schema 的基础上,新增 JsonSchema 到 KCL Schema 的转换支持,比如对于如下的 JsonSchema
{ "$schema":"http://json-schema.org/draft-07/schema#", "$id":"https://example.com/schemas/customer.json", "type":"object", "$defs":{ "address":{ "type":"object", "properties":{ "city":{ "type":"string" }, "state":{ "$ref":"#/$defs/state" } } }, "state":{ "type":"object, "properties":{ "name":{ "type":"string" } } } }, "properties":{ "name":{ "type":"string" }, "address":{ "$ref":"#/$defs/address" } } } 经过 KCL Import 工具可以输出为如下 KCL 代码
schemaCustomer: """ Customer Attributes ---------- name:str,optional address:Address,optional """ name?:str address?:Address schemaAddress: """ Address Attributes ---------- city:str,optional state:State,optional """ city?:str state?:State schemaState: """ State Attributes ---------- name:str,optional """ name?:str Helmfile 是用于部署 Helm Chart 的声明性规范和工具,通过 Helmfile KCL 插件您可以
下面以一个简单示例进行详细说明,使用 Helmfile KCL 插件无需您安装与 KCL 任何相关的组件,只需本机具备 Helmfile 工具的最新版本即可。
我们可以编写一个如下所示helmfile.yaml文件
repositories: -name:prometheus-community url:https://prometheus-community.github.io/helm-charts releases: -name:prom-norbac-ubuntu namespace:prometheus chart:prometheus-community/prometheus set: -name:rbac.create value:false transformers: #UseKCLPlugintomutateorvalidateKubernetesmanifests. -apiVersion:krm.kcl.dev/v1alpha1 kind:KCLRun metadata: name:"set-annotation" annotations: config.kubernetes.io/function:| container: image:docker.io/kcllang/kustomize-kcl:v0.2.0 spec: source:| [resource|{ifresource.kind=="Deployment":metadata.annotations:{"managed-by"="helmfile-kcl"}}forresourceinoption("resource_list").items] 在上述配置中,我们引用了 Prometheus Helm Chart, 并通过一行 KCL 代码就可以完成 Prometheus 的所有的 Deployment 资源注入标签managed-by="helmfile-kcl",通过如下命令我们可以将上述配置下发到集群
helmfileapply 更多用例请参考:https://github.com/kcl-lang/krm-kcl
详见
感谢所有 KCL 用户和社区小伙伴在社区中提出的宝贵反馈与建议。后续我们会撰写更多 KCL v0.5.x 新版本功能解读系列文章,敬请期待!
更多其他资源请参考:
KCL 网站 : https://kcl-lang.io/
KusionStack 网站: https://kusionstack.io/
KCL 2023 路线规划: https://kcl-lang.io/docs/community/release-policy/roadmap
KCL v0.6.0 Milestone: https://github.com/kcl-lang/kcl/milestone/6
KCL Github Issues: https://github.com/kcl-lang/kcl/issues
KCL Github Discussion: https://github.com/orgs/kcl-lang/discussions
KCL Community: https://github.com/kcl-lang/community
KCL v0.5.1 Release:https://github.com/kcl-lang/kcl/releases/tag/v0.5.1
*KCL v0.5.2Release:https://github.com/kcl-lang/kcl/releases/tag/v0.5.2