From 627c29b6cfba7e4c8a3c4cccc454bde31e6cffa9 Mon Sep 17 00:00:00 2001 From: zongz Date: Thu, 24 Oct 2024 15:18:12 +0800 Subject: [PATCH 1/2] feat: add 'deploymentStrategy' to server Signed-off-by: zongz --- .../app_deployment_strategy/base/base.k | 11 ++++++++ .../server/app_deployment_strategy/kcl.mod | 7 ++++++ .../app_deployment_strategy/prod/kcl.mod | 10 ++++++++ .../app_deployment_strategy/prod/main.k | 13 ++++++++++ models/kube/backend/server_backend.k | 2 ++ .../frontend/deployment/deployment_strategy.k | 25 +++++++++++++++++++ .../deployment/rolling_update_deployment.k | 25 +++++++++++++++++++ models/kube/frontend/server.k | 4 +++ 8 files changed, 97 insertions(+) create mode 100644 examples/server/app_deployment_strategy/base/base.k create mode 100644 examples/server/app_deployment_strategy/kcl.mod create mode 100644 examples/server/app_deployment_strategy/prod/kcl.mod create mode 100644 examples/server/app_deployment_strategy/prod/main.k create mode 100644 models/kube/frontend/deployment/deployment_strategy.k create mode 100644 models/kube/frontend/deployment/rolling_update_deployment.k diff --git a/examples/server/app_deployment_strategy/base/base.k b/examples/server/app_deployment_strategy/base/base.k new file mode 100644 index 0000000..2303e06 --- /dev/null +++ b/examples/server/app_deployment_strategy/base/base.k @@ -0,0 +1,11 @@ +import konfig.models.kube.frontend +import konfig.models.kube.frontend.container +import konfig.models.kube.templates.resource as res_tpl + +# Application Configuration +appConfiguration: frontend.Server { + # Main Container Configuration + mainContainer = container.Main {} + schedulingStrategy.resource = res_tpl.tiny + image = "gcr.io/google-samples/gb-frontend:v4" +} diff --git a/examples/server/app_deployment_strategy/kcl.mod b/examples/server/app_deployment_strategy/kcl.mod new file mode 100644 index 0000000..eb9aab2 --- /dev/null +++ b/examples/server/app_deployment_strategy/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "nginx-example" +version = "0.0.1" + +[dependencies] +konfig = { path = "../../../../konfig" } +k8s = "1.28" diff --git a/examples/server/app_deployment_strategy/prod/kcl.mod b/examples/server/app_deployment_strategy/prod/kcl.mod new file mode 100644 index 0000000..3363cff --- /dev/null +++ b/examples/server/app_deployment_strategy/prod/kcl.mod @@ -0,0 +1,10 @@ +[package] +name = "app_stateful_set-prod" +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/server/app_deployment_strategy/prod/main.k b/examples/server/app_deployment_strategy/prod/main.k new file mode 100644 index 0000000..ef4e61b --- /dev/null +++ b/examples/server/app_deployment_strategy/prod/main.k @@ -0,0 +1,13 @@ +import konfig.models.kube.frontend + +# The application configuration in stack will overwrite +# the configuration with the same attribute in base. +appConfiguration: frontend.Server { + deploymentStrategy: { + type = "RollingUpdate" + rollingUpdate: { + maxSurge = 1 + maxUnavailable = 1 + } + } +} diff --git a/models/kube/backend/server_backend.k b/models/kube/backend/server_backend.k index 2f374e6..212bdf0 100644 --- a/models/kube/backend/server_backend.k +++ b/models/kube/backend/server_backend.k @@ -84,6 +84,8 @@ schema ServerBackend[inputConfig: server.Server]: serviceAccountName = config.serviceAccount.name } } + if config.deploymentStrategy: + strategy = config.deploymentStrategy } } diff --git a/models/kube/frontend/deployment/deployment_strategy.k b/models/kube/frontend/deployment/deployment_strategy.k new file mode 100644 index 0000000..8921d60 --- /dev/null +++ b/models/kube/frontend/deployment/deployment_strategy.k @@ -0,0 +1,25 @@ +""" +This is the deployment_strategy module in k8s.api.apps.v1 package. +This file was generated by the KCL auto-gen tool. DO NOT EDIT. +Editing this file might prove futile when you re-run the KCL auto-gen generate command. +""" + + +schema DeploymentStrategy: + """ + DeploymentStrategy describes how to replace existing pods with new ones. + + Attributes + ---------- + rollingUpdate : RollingUpdateDeployment, default is Undefined, optional + Rolling update config params. Present only if DeploymentStrategyType = RollingUpdate. + $type : str, default is Undefined, optional + Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate. + """ + + + rollingUpdate?: RollingUpdateDeployment + + $type?: str + + diff --git a/models/kube/frontend/deployment/rolling_update_deployment.k b/models/kube/frontend/deployment/rolling_update_deployment.k new file mode 100644 index 0000000..89fabff --- /dev/null +++ b/models/kube/frontend/deployment/rolling_update_deployment.k @@ -0,0 +1,25 @@ +""" +This is the rolling_update_deployment module in k8s.api.apps.v1 package. +This file was generated by the KCL auto-gen tool. DO NOT EDIT. +Editing this file might prove futile when you re-run the KCL auto-gen generate command. +""" + + +schema RollingUpdateDeployment: + """ + Spec to control the desired behavior of rolling update. + + Attributes + ---------- + maxSurge : int | str, default is Undefined, optional + The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to 25%. Example: when this is set to 30%, the new ReplicaSet can be scaled up immediately when the rolling update starts, such that the total number of old and new pods do not exceed 130% of desired pods. Once old pods have been killed, new ReplicaSet can be scaled up further, ensuring that total number of pods running at any time during the update is at most 130% of desired pods. + maxUnavailable : int | str, default is Undefined, optional + The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to 25%. Example: when this is set to 30%, the old ReplicaSet can be scaled down to 70% of desired pods immediately when the rolling update starts. Once new pods are ready, old ReplicaSet can be scaled down further, followed by scaling up the new ReplicaSet, ensuring that the total number of pods available at all times during the update is at least 70% of desired pods. + """ + + + maxSurge?: int | str + + maxUnavailable?: int | str + + diff --git a/models/kube/frontend/server.k b/models/kube/frontend/server.k index 21fe469..ff3e646 100644 --- a/models/kube/frontend/server.k +++ b/models/kube/frontend/server.k @@ -9,6 +9,7 @@ import models.kube.frontend.volume import models.kube.frontend.sidecar as s import models.kube.frontend.strategy import models.kube.frontend.storage +import models.kube.frontend.deployment schema Server: """Server is abstaction of Deployment and StatefulSet. @@ -151,3 +152,6 @@ schema Server: # extra resources extraResources?: {str: {str:}} + + # Strategy for deployment + deploymentStrategy?: deployment.DeploymentStrategy From b7b7fb2d09b1f40acee76909c1ccb610dd24a5e7 Mon Sep 17 00:00:00 2001 From: zongz Date: Thu, 24 Oct 2024 15:57:07 +0800 Subject: [PATCH 2/2] chore: bump konfig version to 0.11.0 Signed-off-by: zongz --- examples/server/app_need_namespace/prod/kcl.mod.lock | 4 ++-- examples/server/app_scheduling_strategy/prod/kcl.mod.lock | 4 ++-- kcl.mod | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/server/app_need_namespace/prod/kcl.mod.lock b/examples/server/app_need_namespace/prod/kcl.mod.lock index a662678..71c2699 100644 --- a/examples/server/app_need_namespace/prod/kcl.mod.lock +++ b/examples/server/app_need_namespace/prod/kcl.mod.lock @@ -5,5 +5,5 @@ version = "1.31.2" [dependencies.konfig] name = "konfig" - full_name = "konfig_0.10.0" - version = "0.10.0" + full_name = "konfig_0.11.0" + version = "0.11.0" diff --git a/examples/server/app_scheduling_strategy/prod/kcl.mod.lock b/examples/server/app_scheduling_strategy/prod/kcl.mod.lock index a662678..71c2699 100644 --- a/examples/server/app_scheduling_strategy/prod/kcl.mod.lock +++ b/examples/server/app_scheduling_strategy/prod/kcl.mod.lock @@ -5,5 +5,5 @@ version = "1.31.2" [dependencies.konfig] name = "konfig" - full_name = "konfig_0.10.0" - version = "0.10.0" + full_name = "konfig_0.11.0" + version = "0.11.0" diff --git a/kcl.mod b/kcl.mod index 440a68f..7c6b6e1 100644 --- a/kcl.mod +++ b/kcl.mod @@ -1,6 +1,6 @@ [package] name = "konfig" -version = "0.10.0" +version = "0.11.0" [dependencies] k8s = "1.31.2"