Skip to content

Commit 34009c9

Browse files
authored
Merge pull request #289 from cloudogu/feature/contentVariables
Allow content variables
2 parents 72d3c40 + b916944 commit 34009c9

33 files changed

+329
-177
lines changed

docs/configuration.schema.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
"type" : "string",
176176
"enum" : [ "INIT", "RESET", "UPGRADE" ]
177177
} ],
178-
"description" : "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist (SCMM Return value 409).\nRESET - delete alle files after cloning source - new files are deleted\nUPGRADE - clone and copy - existing files will be overwritten, new files are kept"
178+
"description" : "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist.\nRESET - delete all files after cloning source - files not in content are deleted\nUPGRADE - clone and copy - existing files will be overwritten, files not in content are kept"
179179
},
180180
"password" : {
181181
"type" : [ "string", "null" ],
@@ -187,7 +187,7 @@
187187
},
188188
"ref" : {
189189
"type" : [ "string", "null" ],
190-
"description" : "Reference for a specific branch, tag, or commit"
190+
"description" : "Reference for a specific branch, tag, or commit. Emtpy defaults to default branch of the repo"
191191
},
192192
"target" : {
193193
"type" : [ "string", "null" ],
@@ -208,6 +208,10 @@
208208
},
209209
"additionalProperties" : false
210210
}
211+
},
212+
"variables" : {
213+
"$ref" : "#/$defs/Map(String,Object)-nullable",
214+
"description" : "Additional variables to use in custom templates."
211215
}
212216
},
213217
"additionalProperties" : false,

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@
366366
<configuration>
367367
<!-- Needed to allow unit tests to do reflection, e.g. for SystemLambda's withEnvironmentVariable -->
368368
<argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
369+
<systemProperties>
370+
<property>
371+
<name>ROOT_LOG_LEVEL</name>
372+
<value>OFF</value>
373+
</property>
374+
<property>
375+
<name>APP_LOG_LEVEL</name>
376+
<value>OFF</value>
377+
</property>
378+
</systemProperties>
379+
369380
</configuration>
370381
</plugin>
371382
<plugin>

src/main/groovy/com/cloudogu/gitops/cli/GitopsPlaygroundCliMainScripted.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ class GitopsPlaygroundCliMainScripted {
9292
new Jenkins(config, executor, fileSystemUtils, new GlobalPropertyManager(jenkinsApiClient),
9393
new JobManager(jenkinsApiClient), new UserManager(jenkinsApiClient),
9494
new PrometheusConfigurator(jenkinsApiClient), helmStrategy, k8sClient, networkingUtils),
95-
new Content(config, k8sClient, scmmRepoProvider, scmmApiClient),
9695
new ArgoCD(config, k8sClient, helmClient, fileSystemUtils, scmmRepoProvider),
9796
new IngressNginx(config, fileSystemUtils, deployer, k8sClient, airGappedUtils),
9897
new CertManager(config, fileSystemUtils, deployer, k8sClient, airGappedUtils),
9998
new Mailhog(config, fileSystemUtils, deployer, k8sClient, airGappedUtils),
10099
new PrometheusStack(config, fileSystemUtils, deployer, k8sClient, airGappedUtils, scmmRepoProvider),
101100
new ExternalSecretsOperator(config, fileSystemUtils, deployer, k8sClient, airGappedUtils),
102-
new Vault(config, fileSystemUtils, k8sClient, deployer, airGappedUtils)
101+
new Vault(config, fileSystemUtils, k8sClient, deployer, airGappedUtils),
102+
new Content(config, k8sClient, scmmRepoProvider, scmmApiClient),
103103
]))
104104
}
105105
}

src/main/groovy/com/cloudogu/gitops/config/ApplicationConfigurator.groovy

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ApplicationConfigurator {
2424
addScmmConfig(newConfig)
2525

2626
addRegistryConfig(newConfig)
27-
27+
2828
addJenkinsConfig(newConfig)
2929

3030
addFeatureConfig(newConfig)
@@ -41,23 +41,23 @@ class ApplicationConfigurator {
4141
private void addFeatureConfig(Config newConfig) {
4242
if (newConfig.features.secrets.vault.mode)
4343
newConfig.features.secrets.active = true
44-
44+
4545
if (newConfig.features.mail.smtpAddress || newConfig.features.mail.mailhog)
4646
newConfig.features.mail.active = true
4747
if (newConfig.features.mail.smtpAddress && newConfig.features.mail.mailhog) {
4848
newConfig.features.mail.mailhog = false
4949
log.warn("Enabled both external Mailserver and MailHog! Implicitly deactivating MailHog")
5050
}
51-
51+
5252
if (newConfig.features.ingressNginx.active && !newConfig.application.baseUrl) {
5353
log.warn("Ingress-controller is activated without baseUrl parameter. Services will not be accessible by hostnames. To avoid this use baseUrl with ingress. ")
5454
}
5555
if (newConfig.content.examples) {
56-
if (!newConfig.registry.active) {
56+
if (!newConfig.registry.active) {
5757
throw new RuntimeException("content.examples requires either registry.active or registry.url")
5858
}
5959
String prefix = newConfig.application.namePrefix
60-
newConfig.content.namespaces += [ prefix+"example-apps-staging", prefix+"example-apps-production"]
60+
newConfig.content.namespaces += [prefix + "example-apps-staging", prefix + "example-apps-production"]
6161
}
6262
}
6363

@@ -161,7 +161,7 @@ class ApplicationConfigurator {
161161
// "jenkins.localhost" will not work inside the Pods and k3d-container IP + Port (e.g. 172.x.y.z:9090)
162162
// will not work on Windows and MacOS.
163163
newConfig.jenkins.urlForScmm = "http://jenkins.${newConfig.application.namePrefix}jenkins.svc.cluster.local"
164-
164+
165165
// More internal fields are set lazily in Jenkins.groovy (after Jenkins is deployed and ports are known)
166166
} else {
167167
// Jenkins not active, no need to set the following values
@@ -265,22 +265,29 @@ class ApplicationConfigurator {
265265
"LOCAL_HELM_CHART_FOLDER='charts' after running 'scripts/downloadHelmCharts.sh' from the repo")
266266
}
267267
}
268-
268+
269269
static void validateContent(Config config) {
270270
config.content.repos.each { repo ->
271271
if (!repo.url) {
272-
throw new RuntimeException('content.repos requires a url parameter')
272+
throw new RuntimeException("content.repos requires a url parameter.")
273273
}
274274
if (!repo.folderBased && !repo.target) {
275-
throw new RuntimeException('content.repos.folderBased: false requires folder content.repos.target to be set')
275+
throw new RuntimeException("content.repos.folderBased: false requires folder content.repos.target to be set. ${repo.url}")
276+
}
277+
if (repo.target) {
278+
if (repo.target.count('/') == 0) {
279+
throw new RuntimeException("content.target needs / to separate namespace/group from repo name. ${repo.url}")
280+
}
281+
282+
276283
}
277284
}
278285
}
279286

280287
private void validateScmmAndJenkinsAreBothSet(Config configToSet) {
281-
if (configToSet.jenkins.active &&
288+
if (configToSet.jenkins.active &&
282289
(configToSet.scmm.url && !configToSet.jenkins.url ||
283-
!configToSet.scmm.url && configToSet.jenkins.url)) {
290+
!configToSet.scmm.url && configToSet.jenkins.url)) {
284291
throw new RuntimeException('When setting jenkins URL, scmm URL must also be set and the other way round')
285292
}
286293
}

src/main/groovy/com/cloudogu/gitops/config/Config.groovy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class Config {
9898
@JsonPropertyDescription(CONTENT_REPO_DESCRIPTION)
9999
List<ContentRepositorySchema> repos = []
100100

101+
@JsonPropertyDescription(CONTENT_VARIABLES_DESCRIPTION)
102+
Map<String, Object> variables = [:]
103+
101104
static class ContentRepositorySchema {
102105
@JsonPropertyDescription(CONTENT_REPO_URL_DESCRIPTION)
103106
String url = ''
@@ -106,7 +109,7 @@ class Config {
106109
String path = '.'
107110

108111
@JsonPropertyDescription(CONTENT_REPO_REF_DESCRIPTION)
109-
String ref = 'main'
112+
String ref = ''
110113

111114
@JsonPropertyDescription(CONTENT_REPO_USERNAME_DESCRIPTION)
112115
String username = ''
@@ -124,7 +127,7 @@ class Config {
124127
String target = ''
125128

126129
@JsonPropertyDescription(CONTENT_REPO_TARGET_OVERRIDE_MODE)
127-
OverrideMode overrideMode = OverrideMode.INIT // default is init a new repository
130+
OverrideMode overrideMode = OverrideMode.INIT // Defensively use init to not override existing files by default
128131
}
129132
}
130133

@@ -788,6 +791,7 @@ class Config {
788791

789792
/**
790793
* This defines, how customer repos will be updated.
794+
* See {@link ConfigConstants#CONTENT_REPO_TARGET_OVERRIDE_MODE}
791795
*/
792796
static enum OverrideMode {
793797
INIT, RESET, UPGRADE

src/main/groovy/com/cloudogu/gitops/config/ConfigConstants.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ interface ConfigConstants {
3333
String CONTENT_REPO_DESCRIPTION = "Content repos to push into target environment"
3434
String CONTENT_REPO_URL_DESCRIPTION = "URL of the content repo"
3535
String CONTENT_REPO_PATH_DESCRIPTION = "Path within the content repo to process"
36-
String CONTENT_REPO_REF_DESCRIPTION = "Reference for a specific branch, tag, or commit"
36+
String CONTENT_REPO_REF_DESCRIPTION = "Reference for a specific branch, tag, or commit. Emtpy defaults to default branch of the repo"
3737
String CONTENT_REPO_USERNAME_DESCRIPTION = "Username to authenticate against content repo"
3838
String CONTENT_REPO_PASSWORD_DESCRIPTION = "Password to authenticate against content repo"
3939
String CONTENT_REPO_TEMPLATING_DESCRIPTION = "When true, template all files ending in .ftl within the repo"
4040
String CONTENT_REPO_FOLDER_BASED_REPOS_DESCRIPTION = "When true, interpret the folder structure of each repo as repos. That is, root folder becomes namespace in SCM, sub folders become repository names in SCM"
4141
String CONTENT_REPO_TARGET_DESCRIPTION = "Target path for the repository"
42-
String CONTENT_REPO_TARGET_OVERRIDE_MODE = "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist (SCMM Return value 409).\nRESET - delete alle files after cloning source - new files are deleted\nUPGRADE - clone and copy - existing files will be overwritten, new files are kept"
43-
42+
String CONTENT_REPO_TARGET_OVERRIDE_MODE = "This defines, how customer repos will be updated.\nINIT - push only if repo does not exist.\nRESET - delete all files after cloning source - files not in content are deleted\nUPGRADE - clone and copy - existing files will be overwritten, files not in content are kept"
43+
String CONTENT_VARIABLES_DESCRIPTION = "Additional variables to use in custom templates."
44+
4445
// group jenkins
4546
String JENKINS_ENABLE_DESCRIPTION = 'Installs Jenkins as CI server'
4647
String JENKINS_SKIP_RESTART_DESCRIPTION = 'Skips restarting Jenkins after plugin installation. Use with caution! If the plugins are not installed up front, the installation will likely fail. The intended use case for this is after the first installation, for config changes only. Do not use on first installation or upgrades.'

0 commit comments

Comments
 (0)