Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update ApplicationBuilder for improved metadata, parameter compatibility, and env handling #31

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading