|
| 1 | +--- |
| 2 | +slug: 2023-09-06-biweekly-newsletter |
| 3 | +title: KCL Biweekly Newsletter (2023 08.24 - 09.06) | Kubernetes Operator, IDE Extensions and v0.5.6 are out! |
| 4 | +authors: |
| 5 | + name: KCL Team |
| 6 | + title: KCL Team |
| 7 | +tags: [KCL, Biweekly-Newsletter] |
| 8 | +--- |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +[KCL](https://github.com/kcl-lang) is an open-source, constraint-based record and functional language that enhances the writing of complex configurations, including those for cloud-native scenarios. With its advanced programming language technology and practices, KCL is dedicated to promoting better modularity, scalability, and stability for configurations. It enables simpler logic writing and offers ease of automation APIs and integration with homegrown systems. |
| 13 | + |
| 14 | +This section will update the KCL language community's latest developments every two weeks, including features, website updates, and the latest community news, helping everyone better understand the KCL community! |
| 15 | + |
| 16 | +***KCL Website: [https://kcl-lang.io](https://kcl-lang.io)*** |
| 17 | + |
| 18 | +## Overview |
| 19 | + |
| 20 | +Thank you to all contributors for their outstanding work over the past two weeks (08.10-08.23 2023). Here is an overview of the key content: |
| 21 | + |
| 22 | +**🔧 Language and Toolchain Updates** |
| 23 | + |
| 24 | +- **KCL Import Tool Updates** - Supports exporting JSON/YAML data to KCL configuration. |
| 25 | +- **KCL IDE Updates** - Supports right-click formatting ability, formatting individual files or parts of KCL code. |
| 26 | +- **KCL Documentation Tool Updates** - Exported documents support HTML escape. |
| 27 | +- **KCL Package Management Tool KPM Updates** - `kpm run` command execution and error message optimization, supports running KCL packages located in local paths. |
| 28 | +- **KCL Language Updates** - Optimized system package type check error messages and unified error message codes. |
| 29 | + |
| 30 | +**📰 Official Website and Use Case Updates** |
| 31 | + |
| 32 | +- KCL website adds v0.5.6 documentation version. |
| 33 | +- Publishing KCL packages to docker.io or ghcr.io registries using Github Actions Example: [https://github.com/kcl-lang/kpm/blob/main/docs/push_by_github_action.md](https://github.com/kcl-lang/kpm/blob/main/docs/push_by_github_action.md) |
| 34 | +- KCL Operator example: [https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kcl-operator](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kcl-operator) |
| 35 | + |
| 36 | +## Special Thanks |
| 37 | + |
| 38 | +The following are listed in no particular order: |
| 39 | + |
| 40 | ++ Thanks to @jakezhu9 for the contribution of converting JSON and YAML configuration data to KCL configuration in the KCL Import Tool 🙌 [https://github.com/kcl-lang/kcl-go/pull/141](https://github.com/kcl-lang/kcl-go/pull/141) |
| 41 | ++ Thanks to @xxmao123 and @starkers for their contributions to the KCL NeoVim and Idea IDE extensions 🙌 [https://github.com/kcl-lang/intellij-kcl/pull/12](https://github.com/kcl-lang/intellij-kcl/pull/12) |
| 42 | ++ Thanks to @kolloch, @prahaladramji, and others for their valuable feedback and discussions during the use of KCL in the past two weeks 🙌 |
| 43 | + |
| 44 | +**Congratulations @jakezhu9 for becoming a KCL community Maintainer 🎉** |
| 45 | + |
| 46 | +## Featured Updates |
| 47 | + |
| 48 | +### KCL Operator |
| 49 | + |
| 50 | +KCL Operator provides cluster integration, allowing you to use Access Webhook to generate, mutate, or validate resources based on KCL configuration when apply resources to the cluster. Webhook will capture creation, application, and editing operations, and execute [KCLRun](https://github.com/kcl-lang/krm-kcl) on the configuration associated with each operation, and the KCL programming language can be used to |
| 51 | + |
| 52 | ++ Add labels or annotations based on a condition. |
| 53 | ++ Inject a sidecar container in all KRM resources that contain a `PodTemplate`. |
| 54 | ++ Validating all KRM resources using KCL Schema, such as constraints on starting containers only in a root mode. |
| 55 | ++ Generating KRM resources using an abstract model or combining and using different KRM APIs. |
| 56 | + |
| 57 | +With KCL Operator, you can automate resource configuration management and security validation in a Kubernetes cluster using lightweight KCL code, without the need to develop a webhook server to dynamically mutate and validate configurations at runtime. |
| 58 | + |
| 59 | +Furthermore, leveraging KCL's modeling and abstraction capabilities, we can define functionality abstractions/compositions for different resource APIs and expose them in the form of KCL Schema. We can further generate OpenAPI Schema definitions from KCL Schema for other clients in the cluster to use, without manually maintaining complex OpenAPI Schema definitions for API abstractions/compositions. Here is an example of using KCL Operator to modify resource annotations: |
| 60 | + |
| 61 | +#### 0. Prerequisites |
| 62 | + |
| 63 | +Prepare a Kubernetes cluster like `k3d` the kubectl tool. |
| 64 | + |
| 65 | +#### 1. Install KCL Operator |
| 66 | + |
| 67 | +```shell |
| 68 | +kubectl apply -f https://raw.githubusercontent.com/kcl-lang/kcl-operator/main/config/all.yaml |
| 69 | +``` |
| 70 | + |
| 71 | +Use the following command to observe and wait for the pod status to be `Running`. |
| 72 | + |
| 73 | +```shell |
| 74 | +kubectl get po |
| 75 | +``` |
| 76 | + |
| 77 | +#### 2. Deploy KCL Annotation Setting Model |
| 78 | + |
| 79 | +```shell |
| 80 | +kubectl apply -f- << EOF |
| 81 | +apiVersion: krm.kcl.dev/v1alpha1 |
| 82 | +kind: KCLRun |
| 83 | +metadata: |
| 84 | + name: set-annotation |
| 85 | +spec: |
| 86 | + # Set dynamic parameters required for the annotation modification model, here we can add the labels we want to modify/add |
| 87 | + params: |
| 88 | + annotations: |
| 89 | + managed-by: kcl-operator |
| 90 | + # Reference the annotation modification model on OCI |
| 91 | + source: oci://ghcr.io/kcl-lang/set-annotation |
| 92 | +EOF |
| 93 | +``` |
| 94 | + |
| 95 | +#### 3. Deploy a Pod to Verify the Model Result |
| 96 | + |
| 97 | +Execute the following command to deploy a `Pod` resource: |
| 98 | + |
| 99 | +```shell |
| 100 | +kubectl apply -f- << EOF |
| 101 | +apiVersion: v1 |
| 102 | +kind: Pod |
| 103 | +metadata: |
| 104 | + name: nginx |
| 105 | + annotations: |
| 106 | + app: nginx |
| 107 | +spec: |
| 108 | + containers: |
| 109 | + - name: nginx |
| 110 | + image: nginx:1.14.2 |
| 111 | + ports: |
| 112 | + - containerPort: 80 |
| 113 | +EOF |
| 114 | +kubectl get po nginx -o yaml | grep kcl-operator |
| 115 | +``` |
| 116 | + |
| 117 | +We can see the following output: |
| 118 | + |
| 119 | +```shell |
| 120 | + managed-by: kcl-operator |
| 121 | +``` |
| 122 | + |
| 123 | +We can see that the Nginx Pod automatically added the annotation `managed-by=kcl-operator`. |
| 124 | + |
| 125 | +In addition, besides referencing an existing model for the source field of the `KCLRun` resource, we can directly set KCL code for the source field to achieve the same effect. For example: |
| 126 | + |
| 127 | +```yaml |
| 128 | +apiVersion: krm.kcl.dev/v1alpha1 |
| 129 | +kind: KCLRun |
| 130 | +metadata: |
| 131 | + name: set-annotation |
| 132 | +spec: |
| 133 | + params: |
| 134 | + annotations: |
| 135 | + managed-by: kcl-operator |
| 136 | + # Resource modification can be achieved with just one line of KCL code |
| 137 | + source: | |
| 138 | + items = [item | {metadata.annotations: option("params").annotations} for item in option("items")] |
| 139 | +``` |
| 140 | +
|
| 141 | +We have provided more than 30 built-in models, and you can find more code examples in the following link: [https://github.com/kcl-lang/krm-kcl/tree/main/examples](https://github.com/kcl-lang/krm-kcl/tree/main/examples) |
| 142 | +
|
| 143 | +### IDE Extension Updates |
| 144 | +
|
| 145 | +In the past two weeks, we have integrated the KCL language server LSP into NeoVim and Idea, enabling the completion, navigation, and hover features supported by VS Code IDE in NeoVim and IntelliJ IDEA. |
| 146 | +
|
| 147 | ++ NeoVim KCL Extension |
| 148 | +
|
| 149 | + |
| 150 | +
|
| 151 | ++ IntelliJ Extension |
| 152 | +
|
| 153 | + |
| 154 | +
|
| 155 | +For more information on downloading, installation, and features of the IDE plugins, please refer to: |
| 156 | +
|
| 157 | ++ [https://kcl-lang.io/docs/user_docs/getting-started/install#neovim](https://kcl-lang.io/docs/user_docs/getting-started/install#neovim) |
| 158 | ++ [https://kcl-lang.io/docs/user_docs/getting-started/install#intellij-idea](https://kcl-lang.io/docs/user_docs/getting-started/install#intellij-idea) |
| 159 | +
|
| 160 | +## Resources |
| 161 | +
|
| 162 | +❤️ Thanks to all KCL users and community members for their valuable feedback and suggestions in the community. |
| 163 | +
|
| 164 | +For more resources, please refer to |
| 165 | +
|
| 166 | +- [KCL Website](https://kcl-lang.io/) |
| 167 | +- [KusionStack Website](https://kusionstack.io/) |
| 168 | +
|
| 169 | +- [KCL 2023 Roadmap](https://kcl-lang.io/docs/community/release-policy/roadmap) |
| 170 | +- [KCL v0.6.0 Milestone](https://github.com/kcl-lang/kcl/milestone/6) |
| 171 | +- [KCL Github Issues](https://github.com/kcl-lang/kcl/issues) |
| 172 | +- [KCL Github Discussion](https://github.com/orgs/kcl-lang/discussions) |
| 173 | +- [KCL Community](https://github.com/kcl-lang/community) |
0 commit comments