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

refactor kubernetes config #803

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion charts/jenkins/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: jenkins
home: https://jenkins.io/
version: 4.3.2
version: 5.0.0
appVersion: 2.375.2
description: Jenkins - Build great things at any scale! The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
sources:
Expand Down
4 changes: 2 additions & 2 deletions charts/jenkins/ci/other-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ agent:
- name: PATH
value: /usr/local/bin
nodeSelector:
"app.kubernetes.io/component": "{{ .Values.agent.componentName }}"
"app.kubernetes.io/component": "{{ .Values.kubernetes.agent.componentName }}"
yamlTemplate: |-
apiVersion: v1
kind: Pod
spec:
tolerations:
- key: "app.kubernetes.io/component"
operator: "Equal"
value: "{{ .Values.agent.componentName }}"
value: "{{ .Values.kubernetes.agent.componentName }}"
effect: "NoSchedule"
additionalAgents:
maven:
Expand Down
124 changes: 124 additions & 0 deletions charts/jenkins/templates/_JCasC.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{{/*
Returns configuration as code default config
*/}}
{{- define "jenkins.casc.defaults" -}}
jenkins:
{{- $configScripts := toYaml .Values.controller.JCasC.configScripts }}
{{- if and (.Values.controller.JCasC.authorizationStrategy) (not (contains "authorizationStrategy:" $configScripts)) }}
authorizationStrategy:
{{- tpl .Values.controller.JCasC.authorizationStrategy . | nindent 4 }}
{{- end }}
{{- if and (.Values.controller.JCasC.securityRealm) (not (contains "securityRealm:" $configScripts)) }}
securityRealm:
{{- tpl .Values.controller.JCasC.securityRealm . | nindent 4 }}
{{- end }}
disableRememberMe: {{ .Values.controller.disableRememberMe }}
{{- if .Values.controller.legacyRemotingSecurityEnabled }}
remotingSecurity:
enabled: true
{{- end }}
mode: {{ .Values.controller.executorMode }}
numExecutors: {{ .Values.controller.numExecutors }}
{{- if not (kindIs "invalid" .Values.controller.customJenkinsLabels) }}
labelString: "{{ join " " .Values.controller.customJenkinsLabels }}"
{{- end }}
{{- if .Values.controller.projectNamingStrategy }}
{{- if kindIs "string" .Values.controller.projectNamingStrategy }}
projectNamingStrategy: "{{ .Values.controller.projectNamingStrategy }}"
{{- else }}
projectNamingStrategy:
{{- toYaml .Values.controller.projectNamingStrategy | nindent 4 }}
{{- end }}
{{- end }}
markupFormatter:
{{- if .Values.controller.enableRawHtmlMarkupFormatter }}
rawHtml:
disableSyntaxHighlighting: true
{{- else }}
{{- toYaml .Values.controller.markupFormatter | nindent 4 }}
{{- end }}
{{- if .Values.kubernetes.enabled -}}
{{- include "jenkins.casc.kubernetes" . }}
{{- end -}}
{{- if .Values.controller.csrf.defaultCrumbIssuer.enabled }}
crumbIssuer:
standard:
excludeClientIPFromCrumb: {{ if .Values.controller.csrf.defaultCrumbIssuer.proxyCompatability }}true{{ else }}false{{- end }}
{{- end }}
{{- include "jenkins.casc.security" . }}
{{- if .Values.controller.scriptApproval }}
scriptApproval:
approvedSignatures:
{{- range $key, $val := .Values.controller.scriptApproval }}
- "{{ $val }}"
{{- end }}
{{- end }}
unclassified:
location:
adminAddress: {{ default "" .Values.controller.jenkinsAdminEmail }}
url: {{ template "jenkins.url" . }}
{{- end -}}


{{- define "jenkins.casc.kubernetes" }}
clouds:
- kubernetes:
containerCapStr: "{{ .Values.kubernetes.agent.containerCap }}"
defaultsProviderTemplate: "{{ .Values.kubernetes.agent.defaultsProviderTemplate }}"
connectTimeout: "{{ .Values.kubernetes.agent.kubernetesConnectTimeout }}"
readTimeout: "{{ .Values.kubernetes.agent.kubernetesReadTimeout }}"
{{- if .Values.kubernetes.agent.jenkinsUrl }}
jenkinsUrl: "{{ tpl .Values.kubernetes.agent.jenkinsUrl . }}"
{{- else }}
jenkinsUrl: "http://{{ template "jenkins.fullname" . }}.{{ template "jenkins.namespace" . }}.svc.{{.Values.clusterZone}}:{{.Values.controller.servicePort}}{{ default "" .Values.controller.jenkinsUriPrefix }}"
{{- end }}
{{- if not .Values.kubernetes.agent.websocket }}
{{- if .Values.kubernetes.agent.jenkinsTunnel }}
jenkinsTunnel: "{{ tpl .Values.kubernetes.agent.jenkinsTunnel . }}"
{{- else }}
jenkinsTunnel: "{{ template "jenkins.fullname" . }}-agent.{{ template "jenkins.namespace" . }}.svc.{{.Values.clusterZone}}:{{ .Values.controller.agentListenerPort }}"
{{- end }}
{{- else }}
webSocket: true
{{- end }}
maxRequestsPerHostStr: {{ .Values.kubernetes.agent.maxRequestsPerHostStr | quote }}
name: "{{ .Values.controller.cloudName }}"
namespace: "{{ template "jenkins.kubernetes.namespace" . }}"
serverUrl: "https://kubernetes.default"
{{- if .Values.kubernetes.agent.enabled }}
podLabels:
- key: "jenkins/{{ .Release.Name }}-{{ .Values.kubernetes.agent.componentName }}"
value: "true"
{{- range $key, $val := .Values.kubernetes.agent.podLabels }}
- key: {{ $key | quote }}
value: {{ $val | quote }}
{{- end }}
templates:
{{- if not .Values.kubernetes.agent.disableDefaultAgent }}
{{- include "jenkins.casc.podTemplate" . | nindent 8 }}
{{- end }}
{{- if .Values.additionalAgents }}
{{- /* save .Values.kubernetes.agent */}}
{{- $agent := .Values.kubernetes.agent }}
{{- range $name, $additionalAgent := .Values.additionalAgents }}
{{- $additionalContainersEmpty := and (hasKey $additionalAgent "additionalContainers") (empty $additionalAgent.additionalContainers) }}
{{- /* merge original .Values.kubernetes.agent into additional agent to ensure it at least has the default values */}}
{{- $additionalAgent := merge $additionalAgent $agent }}
{{- /* clear list of additional containers in case it is configured empty for this agent (merge might have overwritten that) */}}
{{- if $additionalContainersEmpty }}
{{- $_ := set $additionalAgent "additionalContainers" list }}
{{- end }}
{{- /* set .Values.kubernetes.agent to $additionalAgent */}}
{{- $_ := set $.Values "agent" $additionalAgent }}
{{- include "jenkins.casc.podTemplate" $ | nindent 8 }}
{{- end }}
{{- /* restore .Values.kubernetes.agent */}}
{{- $_ := set .Values "agent" $agent }}
{{- end }}
{{- if .Values.kubernetes.agent.podTemplates }}
{{- range $key, $val := .Values.kubernetes.agent.podTemplates }}
{{- tpl $val $ | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}
Loading