Skip to content

Commit 5b8ff6b

Browse files
committed
docs: add 0.8.0 release note in zh
Signed-off-by: zongz <zongzhe1024@163.com>
1 parent 39703a7 commit 5b8ff6b

File tree

1 file changed

+354
-0
lines changed
  • i18n/zh-CN/docusaurus-plugin-content-blog/2024-03-04-kcl-0.8.0-release

1 file changed

+354
-0
lines changed
Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
2+
3+
4+
5+
6+
---
7+
slug: 2024-03-04-kcl-0.8.0-release
8+
title: KCL v0.8.0 重磅发布 - 面向云原生场景更完善的生态模型、语言和工具链
9+
authors:
10+
name: KCL Team
11+
title: KCL Team
12+
tags: [Release Blog, KCL]
13+
---
14+
15+
## 简介
16+
17+
KCL 团队很高兴地宣布 **KCL v0.8.0 新版本现在已经可用**!本次发布为大家带来了三方面的重点更新:**语言****工具链****社区集成 & 扩展支持**
18+
19+
- _使用功能更完善错误更少的 KCL 语言、工具链和 IDE 提升代码编写体验和效率_
20+
- _更加全面丰富的社区生态集成,改善运维体验_
21+
- _更加丰富的 KCL 三方库模型,更加轻松的与云原生生态集成_
22+
23+
进一步您可以在 [KCL v0.8.0 发布页面](https://github.com/kcl-lang/kcl/releases/tag/v0.8.0) 或者 [KCL 官方网站](https://kcl-lang.io) 获得下载安装指南和详细发布信息。
24+
25+
[KCL](https://github.com/kcl-lang/kcl) 是一个 CNCF 基金会托管的面向云原生领域开源的基于约束的记录及函数编程语言,期望通过成熟的编程语言技术和实践来改进对大量繁杂配置比如云原生 Kubernetes 配置场景的编写,致力于围绕配置的模块化、扩展性和稳定性,打造更简单的逻辑编写体验,构建更简单的自动化和生态集成路径。
26+
27+
## 语言更新
28+
29+
### 😸 新增 Linux arm64 版本
30+
31+
KCL 的 Release 产物中新增了对 Linux arm64 平台的支持。
32+
33+
可以在 [KCL Release Page](https://github.com/kcl-lang/kcl/releases) 中找到后缀为 `linux-arm64` 的压缩包。
34+
35+
### 🔧 诊断信息的优化
36+
37+
KCL 语法在 if 块中使用的是 `elif` 关键字,而不是 `else if`
38+
39+
编译以下 KCL 程序:
40+
41+
```kcl
42+
if True: a = 1
43+
else if False: b = 1
44+
```
45+
46+
KCL 在诊断信息中增加了错误修正的建议:
47+
48+
```shell
49+
error[E1001]: InvalidSyntax
50+
--> main.k:2:6
51+
|
52+
2 | else if False: b = 1
53+
| ^ 'else if' here is invalid in KCL, consider using the 'elif' keyword
54+
|
55+
```
56+
57+
### 🚀 语言编写体验优化
58+
59+
#### KCL 标准库新增文件系统访问方法
60+
61+
KCL 增加了访问文件系统的方法。在 v0.8.0 版本中支持了包括 `read`, `glob` 等访问文件系统的方法。
62+
63+
通过 `read` 方法,可以读取一个文件内容为字符串。
64+
65+
```kcl
66+
import file
67+
68+
a = read("hello.txt")
69+
```
70+
71+
在文件 `hello.txt` 中添加如下内容:
72+
73+
```shell
74+
Hello World !
75+
```
76+
77+
编译结果
78+
79+
```shell
80+
a: Hello World !
81+
```
82+
83+
通过结合 `json.decode` 方法,可以轻松的实现将 json 文件反序列化。
84+
85+
`hello.json` 文件中增加如下内容
86+
87+
```json
88+
{
89+
"name": "John",
90+
"age": 10
91+
}
92+
```
93+
94+
KCL 程序如下所示:
95+
96+
```kcl
97+
import file
98+
import json
99+
100+
_a = json.decode(file.read("hello.json"))
101+
102+
name = _a.name
103+
age = _a.age
104+
```
105+
106+
编译结果如下所示:
107+
108+
```shell
109+
name: John
110+
age: 10
111+
```
112+
113+
更多内容 - [https://kcl-lang.io/zh-CN/docs/reference/model/file/](https://kcl-lang.io/zh-CN/docs/reference/model/file/)
114+
115+
#### KCL 编译缓存路径支持使用环境变量 KCL_CACHE_PATH 指定
116+
117+
KCL 编译器会将缓存生成到环境变量`KCL_CACHE_PATH`指定的目录当中,如果没指定,将会生成到项目根目录中。
118+
119+
#### 插件系统支持使用 golang 编写 KCL 插件
120+
121+
使用 golang 定义 hello 插件。
122+
123+
```golang
124+
package hello_plugin
125+
126+
import (
127+
"kcl-lang.io/kcl-go/pkg/plugin"
128+
)
129+
130+
func init() {
131+
plugin.RegisterPlugin(plugin.Plugin{
132+
Name: "hello",
133+
MethodMap: map[string]plugin.MethodSpec{
134+
"add": {
135+
Body: func(args *plugin.MethodArgs) (*plugin.MethodResult, error) {
136+
v := args.IntArg(0) + args.IntArg(1)
137+
return &plugin.MethodResult{V: v}, nil
138+
},
139+
},
140+
},
141+
})
142+
}
143+
```
144+
145+
借助 kcl-go 开发,扩展 KCL 编译器使用插件。
146+
147+
```kcl
148+
package main
149+
150+
import (
151+
"fmt"
152+
153+
"kcl-lang.io/kcl-go/pkg/kcl"
154+
"kcl-lang.io/kcl-go/pkg/native" // Import the native API
155+
_ "kcl-lang.io/kcl-go/pkg/plugin/hello_plugin" // Import the hello plugin
156+
)
157+
158+
func main() {
159+
// Note we use `native.MustRun` here instead of `kcl.MustRun`, because it needs the cgo feature.
160+
yaml := native.MustRun("main.k", kcl.WithCode(code)).GetRawYamlResult()
161+
fmt.Println(yaml)
162+
}
163+
164+
const code = `
165+
import kcl_plugin.hello
166+
167+
name = "kcl"
168+
three = hello.add(1,2) # 3
169+
```
170+
171+
### 🏄 SDK & API 更新
172+
173+
174+
TODO
175+
176+
### 🐞 其他更新及错误修复
177+
178+
TODO
179+
180+
## IDE & 工具链更新
181+
182+
### IDE 更新
183+
184+
体验改进
185+
支持增量解析和异步编译功能,提升性能
186+
错误修复
187+
修复 assert 语句中字符串插值变量不能跳转的异常
188+
修复了字符串中异常触发函数补全的异常
189+
修复 import 语句别名语义检查和补全的异常
190+
修复了 schema 中 check 表达式补全的异常
191+
192+
TODO
193+
194+
### 验证工具更新
195+
196+
本次更新中,我们对 KCL 验证工具的报错信息进行了优化,在使用 KCL 验证工具对 json/yaml 文件进行验证的工作中,将会准确定位到 json 文件的异常位置。
197+
198+
以 json 文件为例,我们将要对以下 hello.json 文件进行验证
199+
200+
```json
201+
{
202+
"name": 10,
203+
"age": 18,
204+
"message": "This is Alice"
205+
}
206+
```
207+
208+
定义如下 main.k 文件来对 json 文件中的内容进行验证
209+
210+
```kcl
211+
schema User:
212+
name: str
213+
age: int
214+
message?: str
215+
```
216+
217+
通过以下命令对 json 文件内容进行验证
218+
219+
```shell
220+
kcl vet hello.json main.k
221+
```
222+
223+
可以看到在 json 文件中的错误位置:
224+
225+
```shell
226+
error[E2G22]: TypeError
227+
--> test.json:2:5
228+
|
229+
2 | "name": 10,
230+
| ^ expected str, got int(10)
231+
|
232+
233+
--> main.k:2:5
234+
|
235+
2 | name: str
236+
| ^ variable is defined here, its type is str, but got int(10)
237+
|
238+
```
239+
240+
#### KCL cli 新增 git 仓库作为编译入口
241+
242+
通过以下命令,可以将 KCL 的 git 仓库作为编译入口
243+
244+
```shell
245+
kcl run <git url>
246+
```
247+
248+
#### kcl mod graph 支持输出 KCL 包依赖图
249+
250+
通过命令 `kcl mod graph` 输出 KCL 包的依赖图。
251+
252+
### KCL 包管理工具
253+
254+
#### KCL 包管理工具支持三方库名称带有“-”
255+
256+
KCL 包管理工具支持三方库名称中带有“-”,KCL 包管理工具会自动将 “-” 替换为 “_”。
257+
258+
以三方库 `set-annotation` 为例,通过以下命令添加 `set-annotation` 为依赖:
259+
260+
```shell
261+
kcl mod add set-annotation
262+
```
263+
264+
在 KCL 程序中,通过 `set_annotation` 引用:
265+
266+
```kcl
267+
import set_annotation
268+
```
269+
270+
### KCL 导入工具更新,支持更多特性
271+
272+
- 支持 OpenAPI multiplyOf 规范映射到 KCL multiplyof 函数进行校验
273+
- 支持 YAML Stream 格式的 Kubernetes CRD 文件输出为多个 KCL 文件
274+
- 支持 OpenAPI allOf 关键字校验表达式生成
275+
- 支持 KCL 数组和字典类型的 all/any 校验表达式生成
276+
277+
## 社区集成 & 扩展更新
278+
279+
### Flux KCL Controller 发布
280+
281+
我们开发了 [Flux KCL Controller](https://github.com/kcl-lang/flux-kcl-controller) 支持 KCL 与 Flux 集成。在集群中安装 Flux KCL Controller 后,通过以下资源就可以实现 KCL git 仓库通过 FluxCD 进行持续集成。
282+
283+
```yaml
284+
apiVersion: source.toolkit.fluxcd.io/v1
285+
kind: GitRepository
286+
metadata:
287+
name: kcl-deployment
288+
namespace: source-system
289+
spec:
290+
interval: 30s
291+
# 需要持续集成的 github 仓库
292+
url: https://github.com/awesome-kusion/kcl-deployment.git
293+
ref:
294+
branch: main
295+
---
296+
apiVersion: krm.kcl.dev.fluxcd/v1alpha1
297+
kind: KCLRun
298+
metadata:
299+
name: kcl-deployment
300+
namespace: source-system
301+
spec:
302+
sourceRef:
303+
kind: GitRepository
304+
name: kcl-deployment
305+
```
306+
307+
更多内容详见: https://kcl-lang.io/zh-CN/blog/2024-02-01-biweekly-newsletter/
308+
309+
### CodeQL KCL 工具
310+
311+
初步支持 CodeQL KCL dbschema 定义以及对 KCL 语法语义进行数据提取,并可通过 CodeQL 进行数据查询对 KCL 代码进行静态分析和扫描,提升代码安全。
312+
313+
更多内容详见: https://github.com/kcl-lang/codeql-kcl
314+
315+
## 其他更新
316+
317+
完整更新和错误修复列表详见: https://github.com/kcl-lang/kcl/compare/v0.7.0...v0.8.0
318+
319+
## 文档更新
320+
321+
KCL 网站新增 KCL v0.7.0 文档内容并支持版本化语义选项,目前支持 v0.4.x, v0.5.x, v0.6.x, v0.7.0 和 v0.8.0 版本选择,同时欢迎社区同学进行文档共建。
322+
323+
## 社区动态
324+
325+
### KCL LFX 项目启动
326+
327+
恭喜 @AkashKumar7902, @octonawish-akcodes, @shashank-iitbhu 入选 CNCF KCL LFX 项目,同时感谢 @Vanshikav123, @Amit Pandey 的积极参与。
328+
329+
### KCL 登陆 Crossplane 官方函数市场
330+
331+
自 Crossplane v1.14 中的组合函数 Beta 版发布以来,使用 Crossplane 构建云原生平台的可能体验范围一直在迅速扩大。KCL 团队在第一时间进行跟进并主动构建了一个可重用的函数,整个 Crossplane 生态系统现在可以利用 KCL 提供的高水平经验和能力来构建自己的云原生平台。
332+
333+
更多内容详见: https://blog.crossplane.io/function-kcl/
334+
335+
### 特别鸣谢
336+
337+
感谢社区的小伙伴在 KCL v0.8.0 版本中的贡献,以下排名不分先后
338+
339+
340+
## 下一步计划
341+
342+
感谢所有 KCL 用户和社区小伙伴在此次版本更新过程中提出的宝贵反馈与建议。预计 2024 年 2 月,我们将发布 KCL v0.9.0 版本,更多详情请参考 KCL 2024 路线规划 和 KCL v0.9.0 Milestone,如果您有更多的想法和需求,欢迎在 KCL Github 仓库发起 Issues 或讨论,也欢迎加入我们的社区进行交流 🙌 🙌 🙌
343+
344+
更多其他资源请参考:
345+
346+
- KCL 网站: https://kcl-lang.io/
347+
- Kusion 网站: https://kusionstack.io/
348+
- KCL GitHub 仓库: https://github.com/kcl-lang/kcl
349+
- Kusion GitHub 仓库: https://github.com/KusionStack/kusion
350+
351+
- KCL v0.9.0 Milestone: https://github.com/kcl-lang/kcl/milestone/9
352+
- KCL 2024 路线规划: https://github.com/kcl-lang/kcl/issues/882
353+
- KCL 社区: https://github.com/kcl-lang/community
354+

0 commit comments

Comments
 (0)