From 79a8b725ce1169d63f28f536d346563ecbbf7ee6 Mon Sep 17 00:00:00 2001 From: Rustam Tagaev Date: Mon, 9 Dec 2024 13:38:16 +0300 Subject: [PATCH] [DO-1378] add_new_pod (#49) add couple pod templates and one method for jenkins class Co-authored-by: Rustam Tagaev Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/49 Reviewed-by: Stanislav Gabenov Reviewed-by: Denis Patrakeev Co-authored-by: Rustam Tagaev Co-committed-by: Rustam Tagaev --- src/tech/avroid/jenkins/Jenkins.groovy | 9 ++++ src/tech/avroid/kube/PodTemplates.groovy | 67 ++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/tech/avroid/jenkins/Jenkins.groovy b/src/tech/avroid/jenkins/Jenkins.groovy index 6992485..3fd09bc 100644 --- a/src/tech/avroid/jenkins/Jenkins.groovy +++ b/src/tech/avroid/jenkins/Jenkins.groovy @@ -31,4 +31,13 @@ class Jenkins implements Serializable { } } } + + /** + * Get current username who run build + * @param script Script - jenkins context + * @return String - username + */ + static String GetCurrentBuildUser(Map args = [:]){ + return args.script.currentBuild.getBuildCauses()[0].userId + } } diff --git a/src/tech/avroid/kube/PodTemplates.groovy b/src/tech/avroid/kube/PodTemplates.groovy index ed4f36e..8c5f2a8 100644 --- a/src/tech/avroid/kube/PodTemplates.groovy +++ b/src/tech/avroid/kube/PodTemplates.groovy @@ -159,4 +159,71 @@ class PodTemplates implements Serializable { } } + public void helm(imageVersion='3.16.3', body) { + this.script.podTemplate( + serviceAccount: 'jenkins-deploy', + containers: [ + this.script.containerTemplate( + alwaysPullImage: true, + name: 'helm', + image: "${registry}/docker-hub-proxy/alpine/helm:${imageVersion}", + envVars: [ + this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), + ], + ttyEnabled: true, + command: "cat", + resourceRequestCpu: '100m', + resourceLimitCpu: '100m', + resourceRequestMemory: '256Mi', + resourceLimitMemory: '256Mi', + workingDir: '/jenkins', + ), + ], + instanceCap: 1, + showRawYaml: false, + volumes: [ + this.script.emptyDirVolume(memory: false, mountPath: '/tmp'), + ], + workspaceVolume: this.script.emptyDirWorkspaceVolume(false), + ) + + { + body.call() + } + } + + public void kubectl(imageVersion='1.31.3', body) { + this.script.podTemplate( + serviceAccount: 'jenkins-deploy', + runAsUser: "0", + containers: [ + this.script.containerTemplate( + alwaysPullImage: true, + name: 'kubectl', + image: "${registry}/docker-hub-proxy/bitnami/kubectl:${imageVersion}", + envVars: [ + this.script.containerEnvVar(key: 'HOME', value: '/home/jenkins'), + ], + ttyEnabled: true, + command: "cat", + resourceRequestCpu: '100m', + resourceLimitCpu: '100m', + resourceRequestMemory: '256Mi', + resourceLimitMemory: '256Mi', + workingDir: '/jenkins', + ), + ], + instanceCap: 1, + showRawYaml: false, + volumes: [ + this.script.emptyDirVolume(memory: false, mountPath: '/tmp'), + ], + workspaceVolume: this.script.emptyDirWorkspaceVolume(false), + ) + + { + body.call() + } + } + }