Skip to content

Commit

Permalink
feat: update ApplicationBuilder for improved metadata, parameter comp…
Browse files Browse the repository at this point in the history
…atibility, and env handling

- added a new option parameter to set application metadata, enabling metadata specification within the KCLRun file. This addresses a limitation when building with the kcl kubeclt plugin.
- renamed `env` to `appenv` and `cluster` to `appcluster` to avoid conflicts with system environment variables, especially when using `env` as a key in options with KCLRun.
- modified `ApplicationBuilder` to use `EnvMap` instead of a list of dictionaries for envs, ensuring compatibility with the container env parameter structure.

Signed-off-by: Emin Aktas <[email protected]>
  • Loading branch information
eminaktas committed Nov 14, 2024
1 parent 05dc765 commit 73e8477
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion models/kube/backend/job_backend.k
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ schema JobBackend[inputConfig: frontend.Job]:
mainContainerDict = {
**config.mainContainer
if config.mainContainer.useBuiltInEnv:
env += app.envs
env = config.mainContainer.env | app.envs
name = config.mainContainer.name or "main"
image = config.image
resource = config?.schedulingStrategy?.resource
Expand Down
2 changes: 1 addition & 1 deletion models/kube/backend/server_backend.k
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ schema ServerBackend[inputConfig: server.Server]:
mainContainer = utils.volume_patch(config.volumes, [utils.ContainerFrontend2Kube({
**config.mainContainer
if config.mainContainer.useBuiltInEnv:
env += app.envs
env = config.mainContainer.env | app.envs
name = config.mainContainer.name or "main"
image = config.image
resource = config?.schedulingStrategy?.resource
Expand Down
8 changes: 4 additions & 4 deletions models/kube/metadata/metadata.k
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__META_APP_NAME = option("app") or "sampleapp"
__META_APP_NAMESPACE = option("appns") or "sampleappns"
__META_ENV_TYPE_NAME = option("env") or "prod"
__META_CLUSTER_NAME = option("cluster") or Undefined
__META_APP_NAME = option("app") or option("params").app or "sampleapp"
__META_APP_NAMESPACE = option("appns") or option("params").appns or "sampleappns"
__META_ENV_TYPE_NAME = option("appenv") or option("params").appenv or "prod"
__META_CLUSTER_NAME = option("appcluster") or option("params").appcluster or Undefined
25 changes: 12 additions & 13 deletions models/kube/utils/application_builder.k
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import models.kube.metadata
import models.kube.frontend.container.env as e

schema ApplicationBuilder:
"""ApplicationBuilder contains the workload labels, selector and environments about the application
Expand All @@ -9,26 +10,24 @@ schema ApplicationBuilder:
"app.kubernetes.io/name": metadata.__META_APP_NAME
"app.kubernetes.io/env": metadata.__META_ENV_TYPE_NAME
"app.kubernetes.io/instance": "{}-{}".format(metadata.__META_APP_NAME, metadata.__META_ENV_TYPE_NAME).lower()
"cluster.x-k8s.io/cluster-name": metadata.__META_CLUSTER_NAME
if metadata.__META_CLUSTER_NAME:
"cluster.x-k8s.io/cluster-name": metadata.__META_CLUSTER_NAME
}

selector: {str:str} = labels

envs: [{str:}] = [
{
name: "APP_NAME"
envs: e.EnvMap = {
APP_NAME: {
value: metadata.__META_APP_NAME
}
{
name: "ENVIRONMENT"
ENVIRONMENT: {
value: metadata.__META_ENV_TYPE_NAME
}
{
name: "INSTANCE"
INSTANCE: {
value: "{}-{}".format(metadata.__META_APP_NAME, metadata.__META_ENV_TYPE_NAME).lower()
}
{
name: "CLUSTER"
value: metadata.__META_CLUSTER_NAME
}
]
if metadata.__META_CLUSTER_NAME:
CLUSTER: {
value: metadata.__META_CLUSTER_NAME
}
}

0 comments on commit 73e8477

Please sign in to comment.