From 1b37d9510d9abde83dab3078f7083440ccf53a03 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 14 Jan 2024 16:48:55 -0600 Subject: [PATCH] bci2: Allow jobs to choose if they run on an RPi Jobs that need to compile code, as opposed to simply installing prebuilt packages and/or copying in files, probably do not want to run on a Raspberry Pi. To allow such jobs to opt out of running on a Pi and wait for the Cluster Autoscaler to bring up an aarch64 node in AWS, the `buildContainerImage2` function now takes an optional `pi` argument. The argument defaults to `true`, so existing jobs that expect to run on a Pi will continue to do so. --- resources/podTemplate2.yaml | 4 ---- vars/buildContainerImage2.groovy | 31 ++++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/resources/podTemplate2.yaml b/resources/podTemplate2.yaml index 818faf6..5da469f 100644 --- a/resources/podTemplate2.yaml +++ b/resources/podTemplate2.yaml @@ -17,7 +17,3 @@ spec: limits: github.com/fuse: 1 hostUsers: false - tolerations: - - key: du5t1n.me/machine - value: raspberrypi - effect: NoExecute diff --git a/vars/buildContainerImage2.groovy b/vars/buildContainerImage2.groovy index 2061bff..4d888af 100644 --- a/vars/buildContainerImage2.groovy +++ b/vars/buildContainerImage2.groovy @@ -8,6 +8,7 @@ def call(args) { def archlist = args?.archlist def schedule = args?.schedule def defaultBranch = args?.defaultBranch + def pi = args?.pi properties([ pipelineTriggers([cron(schedule ?: 'H H H * *')]) @@ -31,6 +32,9 @@ def call(args) { if (defaultBranch == null) { defaultBranch = 'main' } + if (pi == null) { + pi = true + } def repo = "${registry}/${project}/${name}" def full_name = "${repo}:${tag}" @@ -44,13 +48,14 @@ def call(args) { full_name: full_name, registry: registry, arch: arch, + pi: pi, ) } } } parallel stages - runInPod { + runInPod(pi: false) { container('buildah') { withBuildahCreds(registry) { if (archlist.size() > 1) { @@ -91,8 +96,9 @@ def buildStage(args) { def full_name = args.full_name def registry = args.registry def arch = args.arch + def pi = args.pi - runInPod(arch) { + runInPod(arch: arch, pi: pi) { checkout scm container('buildah') { @@ -105,14 +111,25 @@ def buildStage(args) { } } -def runInPod(... args) { - def arch = null - def block = args.last() - if (args.size() > 1) { - arch = args[0] +def runInPod(args, block) { + def arch = args?.arch + def pi = args?.pi + if (pi == null) { + pi = true } def podTemplateYaml = libraryResource('podTemplate2.yaml') + if (pi) { + def tmpl = readYaml(text: podTemplateYaml) + def tolerations = tmpl['spec']['tolerations'] ?: [] + tolerations.push([ + key: 'du5t1n.me/machine', + value: 'raspberrypi', + effect: 'NoExecute', + ]) + tmpl['spec']['tolerations'] = tolerations + podTemplateYaml = writeYaml(data: tmpl, returnText: true) + } podTemplate( yaml: podTemplateYaml, nodeSelector: arch ? "kubernetes.io/arch=${arch}" : null,