From a7ac1889fbe31a0e3dc66e376e54fc727ec26430 Mon Sep 17 00:00:00 2001 From: peefy Date: Wed, 11 Sep 2024 11:21:51 +0800 Subject: [PATCH 1/2] feat: add more examples and documents Signed-off-by: peefy --- .gitignore | 2 +- README.md | 8 ++++-- examples/README.md | 25 +++++++++++++++++++ .../extra-resources-example/dev/kcl.mod.lock | 13 ---------- .../extra-resources-example/kcl.mod.lock | 13 ---------- .../appops/nginx-example/dev/kcl.mod.lock | 4 +-- examples/appops/nginx-example/kcl.mod.lock | 4 +-- examples/job/app_main_container/base/base.k | 16 ++++++++++++ examples/job/app_main_container/dev/kcl.mod | 10 ++++++++ examples/job/app_main_container/dev/main.k | 8 ++++++ examples/job/app_main_container/kcl.mod | 7 ++++++ .../extra_resources}/base/base.k | 0 .../extra_resources}/dev/kcl.mod | 2 +- .../extra_resources}/dev/main.k | 0 .../extra_resources}/kcl.mod | 2 +- kcl.mod | 2 +- models/kube/frontend/job.k | 7 ++++++ models/kube/frontend/server.k | 4 +-- 18 files changed, 89 insertions(+), 38 deletions(-) create mode 100644 examples/README.md delete mode 100644 examples/appops/extra-resources-example/dev/kcl.mod.lock delete mode 100644 examples/appops/extra-resources-example/kcl.mod.lock create mode 100644 examples/job/app_main_container/base/base.k create mode 100644 examples/job/app_main_container/dev/kcl.mod create mode 100644 examples/job/app_main_container/dev/main.k create mode 100644 examples/job/app_main_container/kcl.mod rename examples/{appops/extra-resources-example => server/extra_resources}/base/base.k (100%) rename examples/{appops/extra-resources-example => server/extra_resources}/dev/kcl.mod (87%) rename examples/{appops/extra-resources-example => server/extra_resources}/dev/main.k (100%) rename examples/{appops/extra-resources-example => server/extra_resources}/kcl.mod (79%) diff --git a/.gitignore b/.gitignore index e5f33b1..e0447f5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ __pycache__ __kclcache__ .kclvm - +kcl.mod.lock # test report report/ diff --git a/README.md b/README.md index e2dfb4e..db54efd 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,13 @@ Install [KCL](https://kcl-lang.io/docs/user_docs/getting-started/install) See [here](https://kcl-lang.io/docs/user_docs/guides/working-with-konfig/guide) +## Resources + +- More examples can be found [here](https://github.com/kcl-lang/konfig/blob/main/examples/README.md) +- Konfig schema reference document can be found [here](https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md) + ## License Apache License Version 2.0 - -[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkcl-lang%2Fkonfig.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkcl-lang%2Fkonfig?ref=badge_large) \ No newline at end of file +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkcl-lang%2Fkonfig.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkcl-lang%2Fkonfig?ref=badge_large) diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..630c055 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,25 @@ +# Examples + +``` +. +├── README.md +├── appops # Some real and simple application examples +│ ├── guestbook +│ ├── http-echo +│ └── nginx-example +├── job # How to use the job schema to render Kubernetes specific resources +│ └── app_main_container +└── server # How to use the server schema to render Kubernetes specific resources + ├── app_config_map + ├── app_label_selector + ├── app_main_container + ├── app_need_namespace + ├── app_rbac + ├── app_scheduling_strategy + ├── app_secret + ├── app_service + ├── app_sidecar + ├── app_stateful_set + ├── app_volume + └── extra_resources +``` diff --git a/examples/appops/extra-resources-example/dev/kcl.mod.lock b/examples/appops/extra-resources-example/dev/kcl.mod.lock deleted file mode 100644 index a866cfa..0000000 --- a/examples/appops/extra-resources-example/dev/kcl.mod.lock +++ /dev/null @@ -1,13 +0,0 @@ -[dependencies] - [dependencies.k8s] - name = "k8s" - full_name = "k8s_1.28" - version = "1.28" - sum = "aTxPUVZyr9MdiB3YdiY/8pCh9sC55yURnZdGlJsKG6Q=" - reg = "ghcr.io" - repo = "kcl-lang/k8s" - oci_tag = "1.28" - [dependencies.konfig] - name = "konfig" - full_name = "konfig_0.6.0" - version = "0.6.0" diff --git a/examples/appops/extra-resources-example/kcl.mod.lock b/examples/appops/extra-resources-example/kcl.mod.lock deleted file mode 100644 index a866cfa..0000000 --- a/examples/appops/extra-resources-example/kcl.mod.lock +++ /dev/null @@ -1,13 +0,0 @@ -[dependencies] - [dependencies.k8s] - name = "k8s" - full_name = "k8s_1.28" - version = "1.28" - sum = "aTxPUVZyr9MdiB3YdiY/8pCh9sC55yURnZdGlJsKG6Q=" - reg = "ghcr.io" - repo = "kcl-lang/k8s" - oci_tag = "1.28" - [dependencies.konfig] - name = "konfig" - full_name = "konfig_0.6.0" - version = "0.6.0" diff --git a/examples/appops/nginx-example/dev/kcl.mod.lock b/examples/appops/nginx-example/dev/kcl.mod.lock index a866cfa..d32e5a4 100644 --- a/examples/appops/nginx-example/dev/kcl.mod.lock +++ b/examples/appops/nginx-example/dev/kcl.mod.lock @@ -9,5 +9,5 @@ oci_tag = "1.28" [dependencies.konfig] name = "konfig" - full_name = "konfig_0.6.0" - version = "0.6.0" + full_name = "konfig_0.7.0" + version = "0.7.0" diff --git a/examples/appops/nginx-example/kcl.mod.lock b/examples/appops/nginx-example/kcl.mod.lock index a866cfa..d32e5a4 100644 --- a/examples/appops/nginx-example/kcl.mod.lock +++ b/examples/appops/nginx-example/kcl.mod.lock @@ -9,5 +9,5 @@ oci_tag = "1.28" [dependencies.konfig] name = "konfig" - full_name = "konfig_0.6.0" - version = "0.6.0" + full_name = "konfig_0.7.0" + version = "0.7.0" diff --git a/examples/job/app_main_container/base/base.k b/examples/job/app_main_container/base/base.k new file mode 100644 index 0000000..6ac06c5 --- /dev/null +++ b/examples/job/app_main_container/base/base.k @@ -0,0 +1,16 @@ +import konfig.models.kube.frontend +import konfig.models.kube.frontend.container + +# Application Configuration +appConfiguration: frontend.Job { + # Main Container Configuration + mainContainer = container.Main { + ports = [ + {containerPort = 80} + ] + env.MY_ENV: { + value = "MY_VALUE" + } + } + image = "nginx:1.7.8" +} diff --git a/examples/job/app_main_container/dev/kcl.mod b/examples/job/app_main_container/dev/kcl.mod new file mode 100644 index 0000000..40d7a41 --- /dev/null +++ b/examples/job/app_main_container/dev/kcl.mod @@ -0,0 +1,10 @@ +[package] +name = "app_main_container_dev" +version = "0.0.1" + +[dependencies] +konfig = { path = "../../../../../konfig" } +k8s = "1.28" +[profile] +entries = ["../base/base.k", "main.k", "${konfig:KCL_MOD}/models/kube/render/render.k"] + diff --git a/examples/job/app_main_container/dev/main.k b/examples/job/app_main_container/dev/main.k new file mode 100644 index 0000000..3dfa7be --- /dev/null +++ b/examples/job/app_main_container/dev/main.k @@ -0,0 +1,8 @@ +import konfig.models.kube.frontend +import konfig.models.kube.templates.resource as res_tpl + +# The application configuration in stack will overwrite +# the configuration with the same attribute in base. +appConfiguration: frontend.Job { + schedulingStrategy.resource = res_tpl.tiny +} diff --git a/examples/job/app_main_container/kcl.mod b/examples/job/app_main_container/kcl.mod new file mode 100644 index 0000000..7626f26 --- /dev/null +++ b/examples/job/app_main_container/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "app_main_container" +version = "0.0.1" + +[dependencies] +konfig = { path = "../../../../konfig" } +k8s = "1.28" diff --git a/examples/appops/extra-resources-example/base/base.k b/examples/server/extra_resources/base/base.k similarity index 100% rename from examples/appops/extra-resources-example/base/base.k rename to examples/server/extra_resources/base/base.k diff --git a/examples/appops/extra-resources-example/dev/kcl.mod b/examples/server/extra_resources/dev/kcl.mod similarity index 87% rename from examples/appops/extra-resources-example/dev/kcl.mod rename to examples/server/extra_resources/dev/kcl.mod index 37339ec..47e9884 100644 --- a/examples/appops/extra-resources-example/dev/kcl.mod +++ b/examples/server/extra_resources/dev/kcl.mod @@ -1,5 +1,5 @@ [package] -name = "nginx-example-dev" +name = "extra_resources_dev" version = "0.0.1" [dependencies] diff --git a/examples/appops/extra-resources-example/dev/main.k b/examples/server/extra_resources/dev/main.k similarity index 100% rename from examples/appops/extra-resources-example/dev/main.k rename to examples/server/extra_resources/dev/main.k diff --git a/examples/appops/extra-resources-example/kcl.mod b/examples/server/extra_resources/kcl.mod similarity index 79% rename from examples/appops/extra-resources-example/kcl.mod rename to examples/server/extra_resources/kcl.mod index eb9aab2..c4510d9 100644 --- a/examples/appops/extra-resources-example/kcl.mod +++ b/examples/server/extra_resources/kcl.mod @@ -1,5 +1,5 @@ [package] -name = "nginx-example" +name = "extra_resources" version = "0.0.1" [dependencies] diff --git a/kcl.mod b/kcl.mod index 101dffe..b3a2630 100644 --- a/kcl.mod +++ b/kcl.mod @@ -1,6 +1,6 @@ [package] name = "konfig" -version = "0.7.0" +version = "0.8.0" [dependencies] k8s = "1.28" diff --git a/models/kube/frontend/job.k b/models/kube/frontend/job.k index 4d45c1c..e214b84 100644 --- a/models/kube/frontend/job.k +++ b/models/kube/frontend/job.k @@ -13,6 +13,11 @@ schema Job: Attributes ---------- + name: str, default is Undefined, optional. + The name of the workload and service. + If not defined, a generated name ("{__META_APP_NAME}-{__META_ENV_TYPE_NAME}") will be used. + The value of metadata.__META_APP_NAME will be extracted from the value of the "name" defined through option("app"), + and the value of __META_ENV_TYPE_NAME will be extracted from the value of the "name" defined through option("env"). activeDeadlineSeconds: int, default is Undefined, optional. Specifies the duration in seconds relative to the startTime that the job may be active before the system tries to terminate it; value must be positive integer @@ -80,6 +85,8 @@ schema Job: } """ + # job name + name?: str # subset of batchv1.JobSpec activeDeadlineSeconds?: int backoffLimit?: int = 6 diff --git a/models/kube/frontend/server.k b/models/kube/frontend/server.k index 718fd04..4865d3d 100644 --- a/models/kube/frontend/server.k +++ b/models/kube/frontend/server.k @@ -18,8 +18,8 @@ schema Server: name: str, default is Undefined, optional. The name of the workload and service. If not defined, a generated name ("{__META_APP_NAME}-{__META_ENV_TYPE_NAME}") will be used. - The value of __META_APP_NAME will be extracted from the value of the "name" defined in project.yaml, - and the value of __META_ENV_TYPE_NAME will be extracted from the value of the "name" defined in stack.yaml. + The value of metadata.__META_APP_NAME will be extracted from the value of the "name" defined through option("app"), + and the value of __META_ENV_TYPE_NAME will be extracted from the value of the "name" defined through option("env"). workloadType: "Deployment" | "StatefulSet", default is "Deployment", required. Application workload type, default to 'Deployment' renderType: "Server" | "KubeVelaApplication", default is "Server", optional. From ecc3f40afb07b0af52fc1354db36b9fbeca4d338 Mon Sep 17 00:00:00 2001 From: peefy Date: Wed, 11 Sep 2024 11:24:30 +0800 Subject: [PATCH 2/2] docs: add code repo Signed-off-by: peefy --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index db54efd..d6b69dd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Konfig -[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkcl-lang%2Fkonfig.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkcl-lang%2Fkonfig?ref=badge_shield) +> Note: Sync from the [modules](https://github.com/kcl-lang/modules/tree/main/konfig) code repo. + +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkcl-lang%2Fkonfig.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkcl-lang%2Fkonfig?ref=badge_shield) [English](README.md) | [Chinese](README-zh.md)