Skip to content

Commit

Permalink
Custom pod annotations for Kubernetes runner (#57)
Browse files Browse the repository at this point in the history
* chore(deps): move msk iam sdk to core

this would allow core usage of such library, notably when using kubernetes runner

* feat(k8s): allow pod annotations

provide a way to configure annotations attached at the pod created by the kubernetes runner

* docs(k8s): pod annotations reference

document how to configure annotations attached at the pod created by the kubernetes runner
  • Loading branch information
LouisVN authored Oct 31, 2024
1 parent 0f5831e commit f752916
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/advanced/runners/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ runners:
memory: "512M"
# Timeout for the client operations.
timeoutMs: 300000
# Annotations to attach to the pods. Optional: By default, empty
annotations:
key1: value1
key2: value2
```
4 changes: 4 additions & 0 deletions docs/configuration/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ runners:
memory: "512M"
# Timeout of the commands
timeoutMs: 300000
# Annotations to attach to the pods
annotations:
key1: value1
key2: value2

# The lambda runner configuration
lambda:
Expand Down
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
1 change: 1 addition & 0 deletions zoe-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jib {

dependencies {
implementation("com.amazonaws:aws-lambda-java-core:1.2.1")
implementation("software.amazon.msk:aws-msk-iam-auth:2.2.0")

implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.0")
implementation("org.jetbrains.kotlin:kotlin-reflect")
Expand Down
1 change: 0 additions & 1 deletion zoe-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies {
implementation("software.amazon.awssdk:lambda")
implementation("software.amazon.awssdk:s3")
implementation("software.amazon.awssdk:secretsmanager")
implementation("software.amazon.msk:aws-msk-iam-auth:2.2.0")

implementation("org.slf4j:slf4j-log4j12:1.7.30")
implementation("log4j:log4j:1.2.17")
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 f752916

Please sign in to comment.