Skip to content

Commit

Permalink
feat(k8s): allow pod annotations
Browse files Browse the repository at this point in the history
provide a way to configure annotations attached at the pod created by the kubernetes runner
  • Loading branch information
LouisVN committed Oct 31, 2024
1 parent 87bbfef commit 215103d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion zoe-cli/src/commands/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ fun mainModule(context: CliContext) = module {
cpu = kubeConfig.cpu,
memory = kubeConfig.memory,
deletePodsAfterCompletion = kubeConfig.deletePodAfterCompletion,
timeoutMs = kubeConfig.timeoutMs
timeoutMs = kubeConfig.timeoutMs,
annotations = kubeConfig.annotations,
),
executor = ioPool,
namespace = kubeConfig.namespace,
Expand Down
3 changes: 2 additions & 1 deletion zoe-cli/src/config/config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ data class KubernetesRunnerConfig(
val cpu: String = "1",
val memory: String = "512M",
val timeoutMs: Long = 300000,
val image: DockerImageConfig = DockerImageConfig()
val image: DockerImageConfig = DockerImageConfig(),
val annotations: Map<String, String> = emptyMap(),
)

data class DockerImageConfig(
Expand Down
7 changes: 5 additions & 2 deletions zoe-service/src/runners/kubernetes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class KubernetesRunner(
val zoeImage: String,
val cpu: String,
val memory: String,
val timeoutMs: Long?
val timeoutMs: Long?,
val annotations: Map<String, String>
)

private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
Expand Down Expand Up @@ -159,6 +160,7 @@ class KubernetesRunner(

val pod = generatePodObject(
image = configuration.zoeImage,
annotations = configuration.annotations,
args = listOf(
mapOf("function" to function, "payload" to payload.toJsonNode()).toJsonString(),
responseFile
Expand Down Expand Up @@ -203,11 +205,12 @@ class KubernetesRunner(
}
}

private fun generatePodObject(image: String, args: List<String>): Pod {
private fun generatePodObject(image: String, annotations: Map<String, String>, args: List<String>): Pod {
val pod = loadFileFromResources("pod.template.json")?.parseJson<Pod>() ?: userError("pod template not found !")
return pod.apply {
metadata.name = "zoe-${UUID.randomUUID()}"
metadata.labels = labels
metadata.annotations = annotations

spec.containers.find { it.name == "zoe" }?.apply {
resources.requests = mapOf(
Expand Down

0 comments on commit 215103d

Please sign in to comment.