Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(updatecli): replace argument updatecliDockerImage by updatecliAgentLabel #832

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions test/groovy/UpdatecliStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ class UpdatecliStepTests extends BaseTest {
// Then we expect a successful build
assertJobStatusSuccess()

// And the correct pod template defined
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'jenkinsciinfra/helmfile:'))
// And the correct default container memory
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'resourceRequestMemory=512Mi'))
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'resourceLimitMemory=512Mi'))
// And the correct pod agent used
assertTrue(assertMethodCallContainsPattern('node', 'jnlp-linux-arm64'))

// And the repository checkouted
assertTrue(assertMethodCallContainsPattern('checkout', ''))
Expand Down Expand Up @@ -75,17 +72,12 @@ class UpdatecliStepTests extends BaseTest {
// Then we expect a successful build
assertJobStatusSuccess()


// And the repository checkouted
assertTrue(assertMethodCallContainsPattern('checkout',''))

// And only the default command called with custom config and NO values
assertTrue(assertMethodCallContainsPattern('sh','updatecli diff --config ./ops/config.yml'))
assertFalse(assertMethodCallContainsPattern('sh','--values'))

// And the correct container memory
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'resourceRequestMemory=512Mi'))
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'resourceLimitMemory=512Mi'))
}

@Test
Expand Down Expand Up @@ -113,7 +105,7 @@ class UpdatecliStepTests extends BaseTest {
def script = loadScript(scriptName)

// when calling the "updatecli" function with a custom Docker image
script.call(updatecliDockerImage: 'golang:1.16-alpine')
script.call(updatecliAgentLabel: 'jnlp-linux-amd64')
printCallStack()

// Then we expect a successful build
Expand All @@ -123,7 +115,7 @@ class UpdatecliStepTests extends BaseTest {
assertTrue(assertMethodCallContainsPattern('checkout',''))

// And the correct pod template defined
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'golang:1.16-alpine'))
assertTrue(assertMethodCallContainsPattern('node', 'jnlp-linux-amd64'))

// And only the diff command called with default values
assertTrue(assertMethodCallContainsPattern('sh','updatecli diff --config ./updatecli/updatecli.d --values ./updatecli/values.yaml'))
Expand Down
67 changes: 0 additions & 67 deletions updatecli/updatecli.d/docker-helmfile.yml

This file was deleted.

71 changes: 28 additions & 43 deletions vars/updatecli.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ def call(userConfig = [:]) {
action: 'diff', // Updatecli subcommand to execute
config: './updatecli/updatecli.d', // Config manifest used by updatecli (can be a file or a directory)
values: './updatecli/values.yaml', // Values file used by updatecli
updatecliDockerImage: 'jenkinsciinfra/helmfile:3.0.59', // Container image to use for running updatecli
containerMemory: '512Mi', // When using 'updatecliDockerImage', this is the memory limit+request of the container
updatecliAgentLabel: 'jnlp-linux-arm64', // replace updatecliDockerImage
cronTriggerExpression: '', // When specified, it enables cron trigger for the calling pipeline
credentialsId: 'github-app-updatecli-on-jenkins-infra', // githubApp or usernamePassword credentials id to use to get an Access Token. The corresponding populated env vars are USERNAME_VALUE & UPDATECLI_GITHUB_TOKEN
]
Expand All @@ -29,45 +28,31 @@ def call(userConfig = [:]) {
properties([pipelineTriggers([cron(finalConfig.cronTriggerExpression)])])
}

// The podTemplate must define only a single container, named `jnlp`
// Ref - https://support.cloudbees.com/hc/en-us/articles/360054642231-Considerations-for-Kubernetes-Clients-Connections-when-using-Kubernetes-Plugin
podTemplate(
containers: [
containerTemplate(
name: 'jnlp',
image: finalConfig.updatecliDockerImage,
resourceRequestCpu: '1',
resourceLimitCpu: '1',
resourceRequestMemory: finalConfig.containerMemory,
resourceLimitMemory: finalConfig.containerMemory,
),
]
) {
node(POD_LABEL) {
final String updatecliRunStage = "Run updatecli: ${finalConfig.action}"
boolean runUpdatecli = true
stage("Check if updatecli folder exists: ${finalConfig.action}") {
checkout scm
if (!fileExists('updatecli/')) {
echo 'WARNING: no updatecli folder.'
runUpdatecli = false
org.jenkinsci.plugins.pipeline.modeldefinition.Utils.markStageSkippedForConditional(updatecliRunStage)
}
}
stage(updatecliRunStage) {
if (runUpdatecli) {
withCredentials([
usernamePassword(
credentialsId: finalConfig.credentialsId,
usernameVariable: 'USERNAME_VALUE', // Setting this variable is mandatory, even if of not used when the credentials is a githubApp one
passwordVariable: 'UPDATECLI_GITHUB_TOKEN'
)
]) {
sh 'updatecli version'
sh updatecliCommand
} // withCredentials
} // if (runUpdateCli)
} // stage
} // node
} // podTemplate

node (finalConfig.updatecliAgentLabel) {
final String updatecliRunStage = "Run updatecli: ${finalConfig.action}"
boolean runUpdatecli = true
stage("Check if updatecli folder exists: ${finalConfig.action}") {
checkout scm
if (!fileExists('updatecli/')) {
echo 'WARNING: no updatecli folder.'
runUpdatecli = false
org.jenkinsci.plugins.pipeline.modeldefinition.Utils.markStageSkippedForConditional(updatecliRunStage)
}
}
stage(updatecliRunStage) {
if (runUpdatecli) {
withCredentials([
usernamePassword(
credentialsId: finalConfig.credentialsId,
usernameVariable: 'USERNAME_VALUE', // Setting this variable is mandatory, even if of not used when the credentials is a githubApp one
passwordVariable: 'UPDATECLI_GITHUB_TOKEN'
)
]) {
sh 'updatecli version'
sh updatecliCommand
} // withCredentials
} // if (runUpdateCli)
} // stage
}
}
3 changes: 1 addition & 2 deletions vars/updatecli.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
<li>String action: (Optional - Default: "diff") Updatecli action (e.g. subcommand) to execute.</li>
<li>String config: (Optional - Default: "./updatecli/updatecli.d") path to the file or directory with the updatecli configuration (flag "--config").</li>
<li>String values: (Optional - Default: "./updatecli/values.yaml") path to the file with the updatecli values (flag "--values").</li>
<li>String updatecliDockerImage: (Optional - Default: "jenkinsciinfra/helmfile:3.0.59") Docker Image of updatecli to be used in the process.</li>
<li>String updatecliAgentLabel: (Optional - Default: "jnlp-linux-arm64") agent to be used in the process.</li>
<li>String cronTriggerExpression: (Optional - Default: "") Enable periodic execution by providing a cron-like expression.</li>
<li>String containerMemory: (Optional - Default: "512Mi") specify the amount of memory dedicated to the updatecli container.</li>
<li>String credentialsId: (Optional - Default: "github-app-updatecli-on-jenkins-infra") specify the githubApp or usernamePassword credentials id to use to get an Access Token. The corresponding populated env vars are USERNAME_VALUE & UPDATECLI_GITHUB_TOKEN</li>
</ul>

Expand Down