KCL 语言开源社区双周快讯 | KCL 0.5.1 和 0.5.2 版本正式发布

316 天前
 peefy

KCL 是一个开源的基于约束的记录及函数语言并通过成熟的编程语言技术和实践来改进对大量繁杂配置比如云原生 Kubernetes 配置场景的编写,致力于构建围绕配置的更好的模块化、扩展性和稳定性,更简单的逻辑编写,以及更简单的自动化和生态工具集成。

本栏目将会双周更新 KCL 语言社区最新动态,包括功能、官网更新和最新的社区动态等,帮助大家更好地了解 KCL 社区!

KCL 官网: https://kcl-lang.io

内容概述

过去两周 (2023 07.26 - 08.09),KCL 所有项目中总计有 34 个 PR 被合并,感谢所有贡献者的杰出工作,以下是重点合并内容概述

特别鸣谢

精选更新

KCL Import 工具更新

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 代码

schema Customer:
    """
    Customer

    Attributes
    ----------
    name: str, optional
    address: Address, optional
    """

    name?: str
    address?: Address

schema Address:
    """
    Address

    Attributes
    ----------
    city: str, optional
    state: State, optional
    """

    city?: str
    state?: State

schema State:
    """
    State

    Attributes
    ----------
    name: str, optional
    """

    name?: str

Helmfile KCL 插件

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:
  # Use KCL Plugin to mutate or validate Kubernetes manifests.
  - 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 | {if resource.kind == "Deployment": metadata.annotations: {"managed-by" = "helmfile-kcl"}} for resource in option("resource_list").items]

在上述配置中,我们引用了 Prometheus Helm Chart, 并通过一行 KCL 代码就可以完成 Prometheus 的所有的 Deployment 资源注入标签 managed-by="helmfile-kcl",通过如下命令我们可以将上述配置下发到集群

helmfile apply

更多用例请参考: https://github.com/kcl-lang/krm-kcl

其他更新内容

详见

其他资源

❤️ 感谢所有 KCL 用户和社区小伙伴在社区中提出的宝贵反馈与建议。后续我们会撰写更多 KCL v0.5.x 新版本功能解读系列文章,敬请期待!

更多其他资源请参考:

396 次点击
所在节点    推广
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/965810

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX