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

Migrate Jenkins deployment from Bash to Groovy #253

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

schnatterer
Copy link
Member

Reducing the burden of our bash legacy.

This also introduces some other minor improvements

  • All Jenkins config is done in value.ftl.yaml, no more imperative helming
  • Clean up value.ftl.yaml
  • Several versions strewn across the code base now moved into Config.groovy
  • Jenkins GID grepper is now a one-shot temporary pod
  • config.jenkins.helm.values allows for full customization of Jenkins helm deployment
  • Some more logging for all helm deployments
  • namespace variables in Jenkins, ScmManager and Registry
  • This lead to Application.setNamespaceListToConfig() to return redundant default namespaces 🤔 which this PR fixed
  • Boy scout: Also updated some docs/comments that became outdated when versions moved from ApplicationConfigurator to Config in Typed Config for GOP #241

Otherwise the gid grepper pod will keep running unnecessarily.

This implementation should also be easier to migrate to groovy later.
Because it is only a single command.

An alternative would have been to use kubectl wait --for=condition=complete pod/tmp-docker-gid-grepper
instead of until.
This makes explicit which values need to be changed per tests and
otherwise relies on defaults.

This way it became obvious that b38f42d (accidentally?) introduced a
change that resulted in most of the Jenkins config to be only executed
when config.registry.url was set.
This also implements config.jenkins.helm.values,
 allow for full customization of Jenkins helm deployment
* JCasC was not necessary
* sidecars.configAutoReload.enabled might reduce number of Jenkins
reboots (or might not be necessary at all)
* Update PATH to current agent image
  (jenkins/inbound-agent:3261.v9c670a_4748a_9-1 as of chart 5.5.11)
* Elaborate on comments
After they moved there from ApplicationConfigurator in #241
This allows for better logging.
Right now, our build on Jenkins returns empty string when grepping and
cutting.

This lead to the insight
that pretty print of the override JSON causes the gid grepper
command to return empty. 🙄
@nihussmann nihussmann force-pushed the feature/cleanup-gidgrepper branch from c1ed4ea to 4e6eddf Compare January 2, 2025 09:33

if (newConfig.application.baseUrl) {
newConfig.jenkins.ingress = new URL(injectSubdomain('jenkins',
newConfig.application.baseUrl as String, newConfig.application.urlSeparatorHyphen as Boolean)).host
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
newConfig.application.baseUrl as String, newConfig.application.urlSeparatorHyphen as Boolean)).host
newConfig.application.baseUrl, newConfig.application.urlSeparatorHyphen)).host

HelmConfigWithValues helm = new HelmConfigWithValues(
chart: 'jenkins',
repoURL: 'https://charts.jenkins.io',
version: '5.5.11')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version: '5.5.11')
version: '5.7.26')

Maybe we can test and update jenkins to latest? 5.5.11(27 Aug, 2024) -> 5.7.26(22 Dec, 2024). According to the documentation, this should not be a major change. https://github.com/jenkinsci/helm-charts/blob/main/charts/jenkins/CHANGELOG.md

@@ -51,96 +68,193 @@ class Jenkins extends Feature {

@Override
void enable() {

if (config.jenkins.internal) {
// Mark the first node for Jenkins and agents. See jenkins/values.yaml "agent.workingDir" for details.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Mark the first node for Jenkins and agents. See jenkins/values.yaml "agent.workingDir" for details.
// Mark the first node for Jenkins and agents. See jenkins/values.ftl.yaml "agent.workingDir" for details.

}
}

if (!gid) {
log.warn 'Unable to determine Docker Group ID (GID). Jenkins Agent pods will run as root user (UID 0)!\n' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps brackets would be better for the uniformity between the logging commands

}
}

if (!gid) {
log.warn 'Unable to determine Docker Group ID (GID). Jenkins Agent pods will run as root user (UID 0)!\n' +
Copy link
Contributor

@nihussmann nihussmann Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.warn 'Unable to determine Docker Group ID (GID). Jenkins Agent pods will run as root user (UID 0)!\n' +
log.warn('Unable to determine Docker Group ID (GID). Jenkins Agent pod will run as root user (UID 0)!\n' +

new Tuple2('jenkins-admin-password', config.jenkins.password))

def helmConfig = config.jenkins.helm
def templatedMap = templateToMap(HELM_VALUES_PATH,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already rebased onto main and refactored this and the fileSystemUtils part like in the other features. This came with #251. Just for your information. So nothing to do here.

"Group docker not found in /etc/group:\n${etcGroup}"
return ''
} else {
log.debug("Using Docker Group ID (GID) ${gid} for Jenkins Agent pods")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering if it is one or muliple pod/s here?

import org.junit.jupiter.api.Test
import org.mockito.ArgumentCaptor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


@Test
void 'Additional helm values are merged with default values'() {
config.jenkins.helm.values = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good that you thought of this directly and implemented it straight away

@nihussmann nihussmann self-requested a review January 2, 2025 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants