Skip to content

Commit dda445c

Browse files
authored
Feature/config template refactoring (#299)
* Replace ${namePrefix} with config.application.namePrefix and remove the entry from replaceTemplate() * Fix unit tests by wrapping config.application.namePrefix in ${} for interpolation * fix unit test * Fix build error by removing unnecessary ${} around config.application.namePrefix * refactor namePrefixForEnvVars , podResources * refactor images * Refactoring isRemote * Refactoring isInsecure * Refactoring isOpenshift, urlSeparatorHyphen, mirrorRepos, skipCrds, netpols * Refactoring argocd.env und argocd.isOperator * Refactoring argocd.emailFrom, argocd.emailToUser, argocd.emailToAdmin, argocd.resourceInclusionsCluster, registry.twoRegistries, monitoring.active * Refactoring mail template * Comment out secrets.active * Refactor secrets.active, scmm.provider * refactor jenkins.mavenCentralMirror, exampleApps.petclinic, exampleApps.nginx * Refactor templating in PrometheusStack.groovy * Refactor templating in PrometheusStack.groovy. Extract templating logic into a dedicated context. Add ScmUrlResolver for the SCM base URL and use it in the templating context. * small cleanup * add repo URL helper to ScmUrlResolver; use in Prometheus and CertManager * refactor(scm): use ScmUrlResolver.repoUrl in CertManager, ExternalSecretsOperator, IngressNginx, Mailhog, Vault refactor(prometheus): move Docker image parsing from templates into templating code * Add ArgoCDTemplateContextBuilder, refactor PrometheusTemplateContextBuilder, small clean up, * Remove unused freemarker statics from ArgoCD * Rename PrometheusTemplateContextBuilder to PrometheusValuesBuilder, ArgoCDTemplateContextBuilder to ArgoCDValuesBuilder * Revert "Rename PrometheusTemplateContextBuilder to PrometheusValuesBuilder, ArgoCDTemplateContextBuilder to ArgoCDValuesBuilder" This reverts commit 2d7df84. * Extend ScmUrlResolver, use statics in templates,extract templateContextBuilder * Add unit tests for ScmUrlResolver * Add missing ${} for config.application.namePrefix * Add missing config in scmm.provider * Refactor Mailhog 1:1 aliases
1 parent 1199ee7 commit dda445c

File tree

77 files changed

+745
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+745
-630
lines changed

applications/argocd/nginx/helm-jenkins/Jenkinsfile.ftl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
String getApplication() { "nginx-helm-jenkins" }
44
String getScmManagerCredentials() { 'scmm-user' }
5-
String getConfigRepositoryPRBaseUrl() { env.${namePrefixForEnvVars}SCMM_URL }
6-
String getConfigRepositoryPRRepo() { '${namePrefix}argocd/example-apps' }
5+
String getConfigRepositoryPRBaseUrl() { env.${config.application.namePrefixForEnvVars}SCMM_URL }
6+
String getConfigRepositoryPRRepo() { '${config.application.namePrefix}argocd/example-apps' }
77
<#noparse>
88

99
String getCesBuildLibRepo() { configRepositoryPRBaseUrl+"/repo/3rd-party-dependencies/ces-build-lib/" }
@@ -58,13 +58,13 @@ node('docker') {
5858
gitopsTool: 'ARGO',
5959
folderStructureStrategy: 'ENV_PER_APP',
6060
</#noparse>
61-
k8sVersion : env.${namePrefixForEnvVars}K8S_VERSION,
61+
k8sVersion : env.${config.application.namePrefixForEnvVars}K8S_VERSION,
6262
buildImages : [
63-
helm: '${images.helm}',
64-
kubectl: '${images.kubectl}',
65-
kubeval: '${images.kubeval}',
66-
helmKubeval: '${images.helmKubeval}',
67-
yamllint: '${images.yamllint}'
63+
helm: '${config.images.helm}',
64+
kubectl: '${config.images.kubectl}',
65+
kubeval: '${config.images.kubeval}',
66+
helmKubeval: '${config.images.helmKubeval}',
67+
yamllint: '${config.images.yamllint}'
6868
],
6969
deployments: [
7070
sourcePath: 'k8s',
@@ -78,11 +78,11 @@ node('docker') {
7878
],
7979
stages: [
8080
staging: [
81-
namespace: '${namePrefix}example-apps-staging',
81+
namespace: '${config.application.namePrefix}example-apps-staging',
8282
deployDirectly: true
8383
],
8484
production: [
85-
namespace: '${namePrefix}example-apps-production',
85+
namespace: '${config.application.namePrefix}example-apps-production',
8686
deployDirectly: false
8787
],
8888
],
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
namespaceOverride: ${namePrefix}example-apps-production
1+
namespaceOverride: ${config.application.namePrefix}example-apps-production
22

3-
<#if exampleApps.nginx.baseDomain?has_content>
3+
<#if config.features.exampleApps.nginx.baseDomain?has_content>
44
ingress:
55
enabled: true
66
pathType: Prefix
7-
<#if urlSeparatorHyphen>
8-
hostname: production-nginx-helm-${exampleApps.nginx.baseDomain}
7+
<#if config.application.urlSeparatorHyphen>
8+
hostname: production-nginx-helm-${config.features.exampleApps.nginx.baseDomain}
99
<#else>
10-
hostname: production.nginx-helm.${exampleApps.nginx.baseDomain}
10+
hostname: production.nginx-helm.${config.features.exampleApps.nginx.baseDomain}
1111
</#if>
1212
</#if>

applications/argocd/nginx/helm-jenkins/k8s/values-shared.ftl.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<#if nginxImage?has_content>
1+
<#assign DockerImageParser=statics['com.cloudogu.gitops.utils.DockerImageParser']>
2+
<#if config.images.nginx?has_content>
3+
<#assign nginxImageObject = DockerImageParser.parse(config.images.nginx)>
24
image:
3-
registry: ${nginxImage.registry}
4-
repository: ${nginxImage.repository}
5-
tag: ${nginxImage.tag}
5+
registry: ${nginxImageObject.registry}
6+
repository: ${nginxImageObject.repository}
7+
tag: ${nginxImageObject.tag}
68
<#else>
79
image:
810
repository: bitnamilegacy/nginx
@@ -16,7 +18,7 @@ global:
1618
service:
1719
ports:
1820
http: 80
19-
type: <#if isRemote>LoadBalancer<#else>ClusterIP</#if>
21+
type: <#if config.application.remote>LoadBalancer<#else>ClusterIP</#if>
2022
# We don't use staticSiteConfigmap, so this is extensible for our secret example. See ArgoCD.groovy
2123
extraVolumes:
2224
- name: index
@@ -25,7 +27,7 @@ extraVolumes:
2527
items:
2628
- key: index.html
2729
path: index.html
28-
<#if secrets.active>
30+
<#if config.features.secrets.active>
2931
- name: secret
3032
secret:
3133
secretName: nginx-helm-jenkins
@@ -37,13 +39,13 @@ extraVolumeMounts:
3739
- name: index
3840
mountPath: /app
3941
readOnly: true
40-
<#if secrets.active>
42+
<#if config.features.secrets.active>
4143
- name: secret
4244
mountPath: /app/secret
4345
readOnly: true
4446
</#if>
4547

46-
<#if podResources == true>
48+
<#if config.application.podResources == true>
4749
resources:
4850
limits:
4951
cpu: 1
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
namespaceOverride: ${namePrefix}example-apps-staging
1+
namespaceOverride: ${config.application.namePrefix}example-apps-staging
22

3-
<#if exampleApps.nginx.baseDomain?has_content>
3+
<#if config.features.exampleApps.nginx.baseDomain?has_content>
44
ingress:
55
enabled: true
66
pathType: Prefix
7-
<#if urlSeparatorHyphen>
8-
hostname: staging-nginx-helm-${exampleApps.nginx.baseDomain}
7+
<#if config.application.urlSeparatorHyphen>
8+
hostname: staging-nginx-helm-${config.features.exampleApps.nginx.baseDomain}
99
<#else>
10-
hostname: staging.nginx-helm.${exampleApps.nginx.baseDomain}
10+
hostname: staging.nginx-helm.${config.features.exampleApps.nginx.baseDomain}
1111
</#if>
1212
</#if>
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
<#assign DockerImageParser=statics['com.cloudogu.gitops.utils.DockerImageParser']>
12
nginx:
2-
<#if nginxImage?has_content>
3+
<#if config.images.nginx?has_content>
4+
<#assign nginxImageObject = DockerImageParser.parse(config.images.nginx)>
35
image:
4-
registry: ${nginxImage.registry}
5-
repository: ${nginxImage.repository}
6-
tag: ${nginxImage.tag}
6+
registry: ${nginxImageObject.registry}
7+
repository: ${nginxImageObject.repository}
8+
tag: ${nginxImageObject.tag}
79
<#else>
810
image:
911
repository: bitnamilegacy/nginx
@@ -18,8 +20,8 @@ nginx:
1820
service:
1921
ports:
2022
http: 80
21-
type: <#if isRemote>LoadBalancer<#else>ClusterIP</#if>
22-
<#if podResources == true>
23+
type: <#if config.application.remote>LoadBalancer<#else>ClusterIP</#if>
24+
<#if config.application.podResources == true>
2325
resources:
2426
limits:
2527
cpu: 100m
@@ -29,13 +31,13 @@ nginx:
2931
memory: 15Mi
3032
</#if>
3133

32-
<#if exampleApps.nginx.baseDomain?has_content>
34+
<#if config.features.exampleApps.nginx.baseDomain?has_content>
3335
ingress:
3436
enabled: true
3537
pathType: Prefix
36-
<#if urlSeparatorHyphen>
37-
hostname: production-nginx-helm-umbrella-${exampleApps.nginx.baseDomain}
38+
<#if config.application.urlSeparatorHyphen>
39+
hostname: production-nginx-helm-umbrella-${config.features.exampleApps.nginx.baseDomain}
3840
<#else>
39-
hostname: production.nginx-helm-umbrella.${exampleApps.nginx.baseDomain}
41+
hostname: production.nginx-helm-umbrella.${config.features.exampleApps.nginx.baseDomain}
4042
</#if>
4143
</#if>

applications/argocd/petclinic/helm/Jenkinsfile.ftl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
String getApplication() { "spring-petclinic-helm" }
44
String getScmManagerCredentials() { 'scmm-user' }
5-
String getConfigRepositoryPRBaseUrl() { env.${namePrefixForEnvVars}SCMM_URL }
6-
String getConfigRepositoryPRRepo() { '${namePrefix}argocd/example-apps' }
5+
String getConfigRepositoryPRBaseUrl() { env.${config.application.namePrefixForEnvVars}SCMM_URL }
6+
String getConfigRepositoryPRRepo() { '${config.application.namePrefix}argocd/example-apps' }
77

8-
String getDockerRegistryBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_URL }
9-
String getDockerRegistryPath() { env.${namePrefixForEnvVars}REGISTRY_PATH }
8+
String getDockerRegistryBaseUrl() { env.${config.application.namePrefixForEnvVars}REGISTRY_URL }
9+
String getDockerRegistryPath() { env.${config.application.namePrefixForEnvVars}REGISTRY_PATH }
1010
String getDockerRegistryCredentials() { 'registry-user' }
1111

12-
<#if registry.twoRegistries>
13-
String getDockerRegistryProxyBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PROXY_URL }
12+
<#if config.registry.twoRegistries>
13+
String getDockerRegistryProxyBaseUrl() { env.${config.application.namePrefixForEnvVars}REGISTRY_PROXY_URL }
1414
String getDockerRegistryProxyCredentials() { 'registry-proxy-user' }
1515
</#if>
1616

@@ -40,18 +40,18 @@ properties([
4040
node {
4141

4242
</#noparse>
43-
<#if images.maven?has_content>
44-
<#if registry.twoRegistries>
45-
mvn = cesBuildLib.MavenInDocker.new(this, '${images.maven}', dockerRegistryProxyCredentials)
43+
<#if config.images.maven?has_content>
44+
<#if config.registry.twoRegistries>
45+
mvn = cesBuildLib.MavenInDocker.new(this, '${config.images.maven}', dockerRegistryProxyCredentials)
4646
<#else>
47-
mvn = cesBuildLib.MavenInDocker.new(this, '${images.maven}')
47+
mvn = cesBuildLib.MavenInDocker.new(this, '${config.images.maven}')
4848
</#if>
4949
<#else>
5050
mvn = cesBuildLib.MavenWrapper.new(this)
5151
</#if>
5252

53-
<#if jenkins.mavenCentralMirror?has_content>
54-
mvn.useMirrors([name: 'maven-central-mirror', mirrorOf: 'central', url: env.${namePrefixForEnvVars}MAVEN_CENTRAL_MIRROR])
53+
<#if config.jenkins.mavenCentralMirror?has_content>
54+
mvn.useMirrors([name: 'maven-central-mirror', mirrorOf: 'central', url: env.${config.application.namePrefixForEnvVars}MAVEN_CENTRAL_MIRROR])
5555
</#if>
5656
<#noparse>
5757

@@ -80,7 +80,7 @@ node {
8080
String pathPrefix = !dockerRegistryPath?.trim() ? "" : "${dockerRegistryPath}/"
8181
imageName = "${dockerRegistryBaseUrl}/${pathPrefix}${application}:${imageTag}"
8282
</#noparse>
83-
<#if registry.twoRegistries>
83+
<#if config.registry.twoRegistries>
8484
<#noparse>
8585
docker.withRegistry("https://${dockerRegistryProxyBaseUrl}", dockerRegistryProxyCredentials) {
8686
image = docker.build(imageName, '.')
@@ -119,35 +119,35 @@ node {
119119
gitopsTool: 'ARGO',
120120
folderStructureStrategy: 'ENV_PER_APP',
121121
</#noparse>
122-
k8sVersion : env.${namePrefixForEnvVars}K8S_VERSION,
122+
k8sVersion : env.${config.application.namePrefixForEnvVars}K8S_VERSION,
123123
buildImages : [
124-
<#if registry.twoRegistries>
124+
<#if config.registry.twoRegistries>
125125
helm: [
126-
image: '${images.helm}',
126+
image: '${config.images.helm}',
127127
credentialsId: dockerRegistryProxyCredentials
128128
],
129129
kubectl: [
130-
image: '${images.kubectl}',
130+
image: '${config.images.kubectl}',
131131
credentialsId: dockerRegistryProxyCredentials
132132
],
133133
kubeval: [
134-
image: '${images.kubeval}',
134+
image: '${config.images.kubeval}',
135135
credentialsId: dockerRegistryProxyCredentials
136136
],
137137
helmKubeval: [
138-
image: '${images.helmKubeval}',
138+
image: '${config.images.helmKubeval}',
139139
credentialsId: dockerRegistryProxyCredentials
140140
],
141141
yamllint: [
142-
image: '${images.yamllint}',
142+
image: '${config.images.yamllint}',
143143
credentialsId: dockerRegistryProxyCredentials
144144
]
145145
<#else>
146-
helm: '${images.helm}',
147-
kubectl: '${images.kubectl}',
148-
kubeval: '${images.kubeval}',
149-
helmKubeval: '${images.helmKubeval}',
150-
yamllint: '${images.yamllint}'
146+
helm: '${config.images.helm}',
147+
kubectl: '${config.images.kubectl}',
148+
kubeval: '${config.images.kubeval}',
149+
helmKubeval: '${config.images.helmKubeval}',
150+
yamllint: '${config.images.yamllint}'
151151
</#if>
152152
],
153153
deployments: [
@@ -163,10 +163,10 @@ node {
163163
],
164164
stages: [
165165
staging: [
166-
namespace: '${namePrefix}example-apps-staging',
166+
namespace: '${config.application.namePrefix}example-apps-staging',
167167
deployDirectly: true ],
168168
production: [
169-
namespace: '${namePrefix}example-apps-production',
169+
namespace: '${config.application.namePrefix}example-apps-production',
170170
deployDirectly: false ]
171171
]
172172
]
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
service:
22
port: 80
33

4-
<#if exampleApps.petclinic.baseDomain?has_content>
4+
<#if config.features.exampleApps.petclinic.baseDomain?has_content>
55
ingress:
66
hosts:
7-
<#if urlSeparatorHyphen>
8-
- host: production-petclinic-helm-${exampleApps.petclinic.baseDomain}
7+
<#if config.application.urlSeparatorHyphen>
8+
- host: production-petclinic-helm-${config.features.exampleApps.petclinic.baseDomain}
99
<#else>
10-
- host: production.petclinic-helm.${exampleApps.petclinic.baseDomain}
10+
- host: production.petclinic-helm.${config.features.exampleApps.petclinic.baseDomain}
1111
</#if>
1212
paths: ['/']
1313
</#if>

applications/argocd/petclinic/helm/k8s/values-shared.ftl.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ extraEnv: |
33
value: Europe/Berlin
44
55
service:
6-
type: <#if isRemote>LoadBalancer<#else>ClusterIP</#if>
6+
type: <#if config.application.remote>LoadBalancer<#else>ClusterIP</#if>
77

88
ingress:
9-
enabled: <#if exampleApps.petclinic.baseDomain?has_content>true<#else>false</#if>
9+
enabled: <#if config.features.exampleApps.petclinic.baseDomain?has_content>true<#else>false</#if>
1010

1111
# this is a helm chart dependency
1212
podinfo:
@@ -19,7 +19,7 @@ securityContext:
1919
runAsGroup: null
2020
</#if>
2121

22-
<#if podResources == true>
22+
<#if config.application.podResources == true>
2323
resources:
2424
limits:
2525
cpu: '1'
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
service:
22
port: 80
33

4-
<#if exampleApps.petclinic.baseDomain?has_content>
4+
<#if config.features.exampleApps.petclinic.baseDomain?has_content>
55
ingress:
66
hosts:
7-
<#if urlSeparatorHyphen>
8-
- host: staging-petclinic-helm-${exampleApps.petclinic.baseDomain}
7+
<#if config.application.urlSeparatorHyphen>
8+
- host: staging-petclinic-helm-${config.features.exampleApps.petclinic.baseDomain}
99
<#else>
10-
- host: staging.petclinic-helm.${exampleApps.petclinic.baseDomain}
10+
- host: staging.petclinic-helm.${config.features.exampleApps.petclinic.baseDomain}
1111
</#if>
1212
paths: ['/']
1313
</#if>

0 commit comments

Comments
 (0)