Skip to content

Commit

Permalink
Merge pull request #7 from kcl-lang/change-env-map-in-the-front-end-m…
Browse files Browse the repository at this point in the history
…odule

feat: change env to map in the front-end model
  • Loading branch information
Peefy authored Mar 26, 2024
2 parents 7797c6a + ba2c394 commit 4193546
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 31 deletions.
9 changes: 3 additions & 6 deletions examples/appops/guestbook/base/base.k
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/appops/http-echo/dev/kcl.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "http-echo-dev"
version = "0.0.1"

[dependencies]
konfig = "0.3.0"
konfig = { path = "../../../../../konfig" }
k8s = "1.28"

[profile]
Expand Down
4 changes: 3 additions & 1 deletion examples/appops/nginx-example/base/base.k
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,6 +9,9 @@ appConfiguration: frontend.Server {
ports = [
{containerPort = 80}
]
env.MY_ENV: {
value = "MY_VALUE"
}
}
image = "nginx:1.7.8"
services = [
Expand Down
9 changes: 3 additions & 6 deletions examples/server/app_main_container/prod/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions examples/server/app_sidecar/prod/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
Expand Down
2 changes: 1 addition & 1 deletion kcl.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "konfig"
version = "0.3.0"
version = "0.4.0"

[dependencies]
k8s = "1.28"
4 changes: 2 additions & 2 deletions models/kube/frontend/container/container.k
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]

Expand Down
5 changes: 5 additions & 0 deletions models/kube/frontend/container/env/env.k
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
9 changes: 3 additions & 6 deletions models/kube/frontend/server.k
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion models/kube/frontend/sidecar/sidecar.k
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/kube/utils/container_frontend2kube.k
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4193546

Please sign in to comment.