From ba2c3943a1d4096b6371d562567fa7e89a0884a5 Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 26 Mar 2024 19:59:48 +0800 Subject: [PATCH] feat: change env to map in the front-end model Signed-off-by: peefy --- examples/appops/guestbook/base/base.k | 9 +++------ examples/appops/http-echo/dev/kcl.mod | 2 +- examples/appops/nginx-example/base/base.k | 4 +++- examples/server/app_main_container/prod/main.k | 9 +++------ examples/server/app_sidecar/prod/main.k | 9 +++------ kcl.mod | 2 +- models/kube/frontend/container/container.k | 4 ++-- models/kube/frontend/container/env/env.k | 5 +++++ models/kube/frontend/server.k | 9 +++------ models/kube/frontend/sidecar/sidecar.k | 2 +- models/kube/utils/container_frontend2kube.k | 2 +- 11 files changed, 26 insertions(+), 31 deletions(-) diff --git a/examples/appops/guestbook/base/base.k b/examples/appops/guestbook/base/base.k index 3bda637..f55fd68 100644 --- a/examples/appops/guestbook/base/base.k +++ b/examples/appops/guestbook/base/base.k @@ -9,12 +9,9 @@ guestbookFrontend: frontend.Server { # Main Container Configuration mainContainer = container.Main { name = "php-redis" - env = [ - { - name = "GET_HOSTS_FROM" - value = "dns" - } - ] + env.GET_HOSTS_FROM: { + value = "dns" + } ports = [{containerPort = 80}] } schedulingStrategy.resource = res_tpl.tiny diff --git a/examples/appops/http-echo/dev/kcl.mod b/examples/appops/http-echo/dev/kcl.mod index 2c81dd9..cfdbf2e 100644 --- a/examples/appops/http-echo/dev/kcl.mod +++ b/examples/appops/http-echo/dev/kcl.mod @@ -3,7 +3,7 @@ name = "http-echo-dev" version = "0.0.1" [dependencies] -konfig = "0.3.0" +konfig = { path = "../../../../../konfig" } k8s = "1.28" [profile] diff --git a/examples/appops/nginx-example/base/base.k b/examples/appops/nginx-example/base/base.k index 5477a42..99e159b 100644 --- a/examples/appops/nginx-example/base/base.k +++ b/examples/appops/nginx-example/base/base.k @@ -1,7 +1,6 @@ import konfig.models.kube.frontend import konfig.models.kube.frontend.service import konfig.models.kube.frontend.container -import konfig.models.kube.templates.resource as res_tpl # Application Configuration appConfiguration: frontend.Server { @@ -10,6 +9,9 @@ appConfiguration: frontend.Server { ports = [ {containerPort = 80} ] + env.MY_ENV: { + value = "MY_VALUE" + } } image = "nginx:1.7.8" services = [ diff --git a/examples/server/app_main_container/prod/main.k b/examples/server/app_main_container/prod/main.k index aa07562..da2703a 100644 --- a/examples/server/app_main_container/prod/main.k +++ b/examples/server/app_main_container/prod/main.k @@ -17,12 +17,9 @@ appConfiguration: frontend.Server { # 主容器启动参数,可选 args = ["start"] # 主容器环境变量,可选 - env = [ - e.Env { - name = "app.version" - value = "v1.0.0" - } - ] + env: { + "app.version": {value = "v1.0.0"} + } envFrom = [ e.EnvFromSource { configMapRef = "my-configmap" diff --git a/examples/server/app_sidecar/prod/main.k b/examples/server/app_sidecar/prod/main.k index 29194fd..0a2bca4 100644 --- a/examples/server/app_sidecar/prod/main.k +++ b/examples/server/app_sidecar/prod/main.k @@ -11,12 +11,9 @@ appConfiguration: frontend.Server { s.Sidecar { name = "sidecar-log-collector" image = "gcr.io/google_containers/fluentd-sidecar-es:1.0" - env = [ - e.Env { - name = "FILES_TO_COLLECT" - value = "/mnt/log/synthetic-count.log /mnt/log/synthetic-dates.log" - } - ] + env: { + "FILES_TO_COLLECT": {value = "/mnt/log/synthetic-count.log /mnt/log/synthetic-dates.log"} + } resource = res_tpl.small } ] diff --git a/kcl.mod b/kcl.mod index 5f04a07..81a5208 100644 --- a/kcl.mod +++ b/kcl.mod @@ -1,6 +1,6 @@ [package] name = "konfig" -version = "0.3.0" +version = "0.4.0" [dependencies] k8s = "1.28" diff --git a/models/kube/frontend/container/container.k b/models/kube/frontend/container/container.k index 8240627..7a4e466 100644 --- a/models/kube/frontend/container/container.k +++ b/models/kube/frontend/container/container.k @@ -19,7 +19,7 @@ schema Main: args: [str], default is Undefined, optional. A Container-level attribute. The startup arguments of main process. The image's cmd is used if this is not provided. - env: [e.Env], default is Undefined, optional. + env: e.EnvMap, default is Undefined, optional. A Container-level attribute. List of environment variables in the container. envFrom: [e.EnvFromSource], default is Undefined, optional. @@ -65,7 +65,7 @@ schema Main: command?: [str] args?: [str] useBuiltInEnv?: bool = False - env?: [e.Env] + env?: e.EnvMap envFrom?: [e.EnvFromSource] ports?: [cp.ContainerPort] diff --git a/models/kube/frontend/container/env/env.k b/models/kube/frontend/container/env/env.k index a859e95..0ddb975 100644 --- a/models/kube/frontend/container/env/env.k +++ b/models/kube/frontend/container/env/env.k @@ -1,6 +1,11 @@ import regex import units +schema EnvMap: + [name: str]: Env = { + name = name + } + schema Env: """ Env represents an environment variable present in a Container. diff --git a/models/kube/frontend/server.k b/models/kube/frontend/server.k index 42a3113..51f51a0 100644 --- a/models/kube/frontend/server.k +++ b/models/kube/frontend/server.k @@ -77,12 +77,9 @@ schema Server: appConfiguration: frontend.Server { mainContainer = container.Main { name = "php-redis" - env = [ - { - name = "GET_HOSTS_FROM" - value = "dns" - } - ] + env: { + "GET_HOSTS_FROM": {value = "dns"} + } ports = [{containerPort = 80}] } selector = { diff --git a/models/kube/frontend/sidecar/sidecar.k b/models/kube/frontend/sidecar/sidecar.k index 76b9a1a..fed29c2 100644 --- a/models/kube/frontend/sidecar/sidecar.k +++ b/models/kube/frontend/sidecar/sidecar.k @@ -71,7 +71,7 @@ schema Sidecar: name: str command?: [str] args?: [str] - env?: [e.Env] + env?: e.EnvMap envFrom?: [e.EnvFromSource] ports?: [cp.ContainerPort] resource: str | res.Resource diff --git a/models/kube/utils/container_frontend2kube.k b/models/kube/utils/container_frontend2kube.k index 01eb86e..705e458 100644 --- a/models/kube/utils/container_frontend2kube.k +++ b/models/kube/utils/container_frontend2kube.k @@ -38,7 +38,7 @@ ContainerFrontend2Kube = lambda c -> {str:} { divisor: str(e.valueFrom.resourceFieldRef.divisor) } if e.valueFrom.resourceFieldRef else Undefined } if e.valueFrom else Undefined - } for e in c.env + } for _, e in c.env ] # Convert frontend envFrom to kube envFrom