-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from kcl-lang/add-set-annotations-package
feat: add set-annotations models
- Loading branch information
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## Introduction | ||
|
||
`set-annotations` is a kcl mutation package, which can be used to add `metadata.annotations` attributes for the Kubernetes resources. | ||
|
||
The KCL code is as follows: | ||
|
||
```python | ||
params = option("params") or {} | ||
# Use `k = v` to override existing annotations | ||
annotations: {str:str} = {k = v for k, v in params.annotations or {}} | ||
items = [item | { | ||
metadata.annotations: annotations | ||
} for item in option("items")] | ||
``` | ||
|
||
## How to Use | ||
|
||
Add the source into your `KCLRun` resource and use the [kubectl kcl plugin](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kubectl-kcl-plugin) or the [kcl operator](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kcl-operator) to integrate this model. | ||
|
||
```yaml | ||
apiVersion: krm.kcl.dev/v1alpha1 | ||
kind: KCLRun | ||
metadata: | ||
name: set-annotations | ||
spec: | ||
params: | ||
annotations: | ||
config.kubernetes.io/local-config: "true" | ||
source: oci://ghcr.io/kcl-lang/set-annotations | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "set-annotations" | ||
version = "0.1.0" | ||
description = "`set-annotations` is a kcl mutation package, which can be used to add `metadata.annotations` attributes for the Kubernetes resources." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
params = option("params") or {} | ||
# Use `k = v` to override existing annotations | ||
annotations: {str:str} = {k = v for k, v in params.annotations or {}} | ||
items = [item | { | ||
metadata.annotations: annotations | ||
} for item in option("items")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: krm.kcl.dev/v1alpha1 | ||
kind: KCLRun | ||
metadata: | ||
name: set-annotations | ||
spec: | ||
params: | ||
annotations: | ||
config.kubernetes.io/local-config: "true" | ||
source: oci://ghcr.io/kcl-lang/set-annotations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: krm.kcl.dev/v1alpha1 | ||
kind: KCLRun | ||
metadata: | ||
name: set-annotations | ||
annotations: | ||
krm.kcl.dev/version: 0.0.1 | ||
krm.kcl.dev/type: mutation | ||
documentation: >- | ||
Set annotations | ||
spec: | ||
params: | ||
annotations: | ||
config.kubernetes.io/local-config: "true" | ||
source: ./examples/mutation/set-annotations/main.k | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.14.2 | ||
ports: | ||
- containerPort: 80 |