Skip to content

Commit 43c67b1

Browse files
committed
Polish registry-proxy params
Insight: At the moment, proxy-username and proxy-password are not optional. The mere purpose of proxy-url is to add the credentials to Jenkins. So, without username and password URL makes no sense as well.
1 parent 3f70a02 commit 43c67b1

File tree

12 files changed

+50
-25
lines changed

12 files changed

+50
-25
lines changed

applications/argocd/petclinic/plain-k8s/Jenkinsfile.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ String getDockerRegistryPath() { env.${namePrefixForEnvVars}REGISTRY_PATH }
1010
String getDockerRegistryCredentials() { 'registry-user' }
1111

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

1717
<#noparse>

docs/configuration.schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,15 @@
503503
},
504504
"proxyPassword" : {
505505
"type" : "string",
506-
"description" : "Optional when registry-url is set"
506+
"description" : "Use with registry-proxy-url, added to Jenkins as credentials."
507507
},
508508
"proxyUrl" : {
509509
"type" : "string",
510-
"description" : "The url of your external proxy-registry. Make sure to always use this with registry-proxy-url"
510+
"description" : "The url of your proxy-registry. Used in pipelines to authorize pull base images. Use in conjunction with petclinic base image."
511511
},
512512
"proxyUsername" : {
513513
"type" : "string",
514-
"description" : "Optional when registry-proxy-url is set"
514+
"description" : "Use with registry-proxy-url, added to Jenkins as credentials."
515515
},
516516
"url" : {
517517
"type" : "string",

docs/developers.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,18 +427,16 @@ That is, for most helm charts, you'll need to set an individual value.
427427

428428
## Testing two registries
429429

430-
### Very simple test
430+
### Basic test
431431
* Start playground once,
432432
* then again with these parameters:
433-
`--registry-proxy-url=localhost:30000`
433+
`--registry-url=localhost:30000 --registry-proxy-url=localhost:30000 --registry-proxy-username=Proxy --registry-proxy-password=Proxy12345`
434434
* The petclinic pipelines should still run
435435

436436
### Proper test
437437

438438
* Start cluster:
439439
```shell
440-
# Stop other cluster, if necessary
441-
# k3d cluster stop gitops-playground
442440
scripts/init-cluster.sh
443441
```
444442
* Setup harbor as stated [above](#external-registry-for-development), but with Port `30000`.
@@ -460,7 +458,7 @@ for operation in "${operations[@]}"; do
460458
echo creating user $operation with PW ${operation}12345
461459
curl -s --fail 'http://localhost:30000/api/v2.0/users' -X POST -u admin:Harbor12345 -H 'Content-Type: application/json' --data-raw "{\"username\":\"$operation\",\"email\":\"[email protected]\",\"realname\":\"$operation example\",\"password\":\"${operation}12345\",\"comment\":null}"
462460
463-
echo "Adding member $operation to project $lower_operation; ID=${projectId}"
461+
echo "Adding member $operation to project $lower_operation; ID=${projectId}"
464462
465463
curl --fail "http://localhost:30000/api/v2.0/projects/${projectId}/members" -X POST -u admin:Harbor12345 -H 'Content-Type: application/json' --data-raw "{\"role_id\":4,\"member_user\":{\"username\":\"$operation\"}}"
466464
done
@@ -473,8 +471,8 @@ skopeo copy docker://eclipse-temurin:11-jre-alpine --dest-creds Proxy:Proxy12345
473471
```bash
474472
docker run --rm -t -u $(id -u) \
475473
-v ~/.config/k3d/kubeconfig-gitops-playground.yaml:/home/.kube/config \
476-
--net=host \
477-
gitops-playground:tag \
474+
--net=host \
475+
gitops-playground:dev \
478476
--yes --argocd --ingress-nginx --base-url=http://localhost \
479477
--registry-url=localhost:30000 \
480478
--registry-path=registry \

exercises/petclinic-helm/Jenkinsfile.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ String getDockerRegistryPath() { env.${namePrefixForEnvVars}REGISTRY_PATH }
1010
String getDockerRegistryCredentials() { 'registry-user' }
1111

1212
<#if registry.twoRegistries>
13-
String getDockerRegistryProxyCredentials() { 'registry-proxy-user' }
14-
String getDockerRegistryProxyBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PROXY_URL }
13+
String getDockerRegistryProxyCredentials() { 'registry-proxy-user' }
14+
String getDockerRegistryProxyBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PROXY_URL }
1515
</#if>
1616
<#noparse>
1717
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib/" }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ class ApplicationConfigurator {
295295
private void addRegistryConfig(Map newConfig) {
296296
if (newConfig.registry['proxyUrl']) {
297297
newConfig.registry['twoRegistries'] = true
298+
if (!newConfig.registry['proxyUsername'] || !newConfig.registry['proxyPassword'] ) {
299+
throw new RuntimeException("Proxy URL needs to be used with proxy-username and proxy-password")
300+
}
298301
}
299302

300303
if (newConfig.registry['url']) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ interface ConfigConstants {
99
String REGISTRY_USERNAME_DESCRIPTION = 'Optional when registry-url is set'
1010
String REGISTRY_PASSWORD_DESCRIPTION = 'Optional when registry-url is set'
1111

12-
String REGISTRY_PROXY_URL_DESCRIPTION = 'The url of your external proxy-registry. Make sure to always use this with registry-proxy-url'
13-
String REGISTRY_PROXY_PATH_DESCRIPTION = 'Optional when registry-proxy-url is set'
14-
String REGISTRY_PROXY_USERNAME_DESCRIPTION = 'Optional when registry-proxy-url is set'
15-
String REGISTRY_PROXY_PASSWORD_DESCRIPTION = 'Optional when registry-proxy-url is set'
12+
String REGISTRY_PROXY_URL_DESCRIPTION = 'The url of your proxy-registry. Used in pipelines to authorize pull base images. Use in conjunction with petclinic base image.'
13+
String REGISTRY_PROXY_USERNAME_DESCRIPTION = 'Use with registry-proxy-url, added to Jenkins as credentials.'
14+
String REGISTRY_PROXY_PASSWORD_DESCRIPTION = 'Use with registry-proxy-url, added to Jenkins as credentials.'
1615

1716
String FEATURES_DESCRIPTION = 'Config parameters for features or tools'
1817

src/main/groovy/com/cloudogu/gitops/config/schema/Schema.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Schema {
6262
String proxyUrl = ""
6363
@JsonPropertyDescription(REGISTRY_PROXY_USERNAME_DESCRIPTION)
6464
String proxyUsername = ""
65-
@JsonPropertyDescription(REGISTRY_PASSWORD_DESCRIPTION)
65+
@JsonPropertyDescription(REGISTRY_PROXY_PASSWORD_DESCRIPTION)
6666
String proxyPassword = ""
6767

6868
HelmConfig helm

src/main/groovy/com/cloudogu/gitops/destroy/JenkinsDestructionHandler.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class JenkinsDestructionHandler implements DestructionHandler {
2626
globalPropertyManager.deleteGlobalProperty("${configuration.getNamePrefixForEnvVars()}REGISTRY_URL")
2727
globalPropertyManager.deleteGlobalProperty("${configuration.getNamePrefixForEnvVars()}REGISTRY_PATH")
2828
globalPropertyManager.deleteGlobalProperty("${configuration.getNamePrefixForEnvVars()}REGISTRY_PROXY_URL")
29-
globalPropertyManager.deleteGlobalProperty("${configuration.getNamePrefixForEnvVars()}REGISTRY_PROXY_PATH")
3029
globalPropertyManager.deleteGlobalProperty("${configuration.getNamePrefixForEnvVars()}K8S_VERSION")
3130
}
3231
}

src/main/groovy/com/cloudogu/gitops/features/Jenkins.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Jenkins extends Feature {
105105
"registry-user",
106106
"${config.registry['username']}",
107107
"${config.registry['password']}",
108-
'credentials for accessing the docker-registry')
108+
'credentials for accessing the docker-registry for writing images built on jenkins')
109109

110110
if (config.registry['twoRegistries']) {
111111
jobManger.createCredential(

src/test/groovy/com/cloudogu/gitops/ApplicationConfiguratorTest.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class ApplicationConfiguratorTest {
3939
registry : [
4040
url : EXPECTED_REGISTRY_URL,
4141
proxyUrl: "proxy-$EXPECTED_REGISTRY_URL",
42+
proxyUsername: "proxy-user",
43+
proxyPassword: "proxy-pw",
4244
internalPort: EXPECTED_REGISTRY_INTERNAL_PORT,
4345
path : null
4446
],
@@ -415,6 +417,30 @@ images:
415417
assertThat(actualConfig['registry']['internal']).isEqualTo(true)
416418
}
417419

420+
@Test
421+
void "Registry: Fails when proxy but no username and password set"() {
422+
def expectedException = 'Proxy URL needs to be used with proxy-username and proxy-password'
423+
424+
testConfig.registry['proxyUsername'] = null
425+
def exception = shouldFail(RuntimeException) {
426+
applicationConfigurator.setConfig(testConfig)
427+
}
428+
assertThat(exception.message).isEqualTo(expectedException)
429+
430+
testConfig.registry['proxyUsername'] = 'something'
431+
testConfig.registry['proxyPassword'] = null
432+
exception = shouldFail(RuntimeException) {
433+
applicationConfigurator.setConfig(testConfig)
434+
}
435+
assertThat(exception.message).isEqualTo(expectedException)
436+
437+
testConfig.registry['proxyUsername'] = null
438+
exception = shouldFail(RuntimeException) {
439+
applicationConfigurator.setConfig(testConfig)
440+
}
441+
assertThat(exception.message).isEqualTo(expectedException)
442+
}
443+
418444
List<String> getAllFieldNames(Class clazz, String parentField = '', List<String> fieldNames = []) {
419445
clazz.declaredFields.each { field ->
420446
def currentField = parentField + field.name

0 commit comments

Comments
 (0)