Skip to content

Commit db58e00

Browse files
committed
fixing hardcoded central Argocd namespace
1 parent 18f3982 commit db58e00

File tree

5 files changed

+73
-13
lines changed

5 files changed

+73
-13
lines changed

argocd/cluster-resources/argocd/misc.ftl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: argoproj.io/v1alpha1
44
kind: Application
55
metadata:
66
name: <#if config.multiTenant.useDedicatedInstance>${namePrefix}misc<#else>misc</#if>
7-
namespace: <#if config.multiTenant.useDedicatedInstance>argocd<#else>${namePrefix}argocd</#if>
7+
namespace: <#if config.multiTenant.useDedicatedInstance>${config.multiTenant.centralArgocdNamespace}<#else>${namePrefix}argocd</#if>
88
spec:
99
project: <#if config.multiTenant.useDedicatedInstance>${tenantName}<#else>cluster-resources</#if>
1010
destination:

src/main/groovy/com/cloudogu/gitops/features/argocd/ArgoCD.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,14 @@ class ArgoCD extends Feature {
345345
// Append new namespaces to existing ones from the secret.
346346
// `kubectl patch` can't merge list subfields, so we read, decode, merge, and update the secret.
347347
// This ensures all centrally managed namespaces are preserved.
348-
String base64Namespaces = k8sClient.getArgoCDNamespacesSecret('argocd-default-cluster-config', 'argocd')
348+
String base64Namespaces = k8sClient.getArgoCDNamespacesSecret('argocd-default-cluster-config', config.multiTenant.centralArgocdNamespace)
349349
byte[] decodedBytes = Base64.decoder.decode(base64Namespaces)
350350
String decoded = new String(decodedBytes, "UTF-8")
351351
def decodedList = decoded?.split(',') as List ?: []
352352
def activeList = config.application.namespaces.activeNamespaces?.flatten() as List ?: []
353353
def merged = (decodedList + activeList).unique().join(',')
354354
log.debug("Updating Central Argocd 'argocd-default-cluster-config' secret")
355-
k8sClient.patch('secret', 'argocd-default-cluster-config', 'argocd',
355+
k8sClient.patch('secret', 'argocd-default-cluster-config', config.multiTenant.centralArgocdNamespace,
356356
[stringData: ['namespaces': merged]])
357357
}
358358
}

src/main/groovy/com/cloudogu/gitops/kubernetes/argocd/ArgoApplication.groovy

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cloudogu.gitops.kubernetes.argocd
22

3-
import com.cloudogu.gitops.config.Config
3+
44
import com.cloudogu.gitops.scmm.ScmmRepo
55
import com.cloudogu.gitops.utils.TemplatingEngine
66
import groovy.util.logging.Slf4j
@@ -14,28 +14,30 @@ class ArgoApplication {
1414

1515
String name
1616
String namespace
17+
String destinationNamespace
1718
String path
1819
String repoUrl
1920
String project
2021

2122
private final TemplatingEngine templater = new TemplatingEngine()
2223

23-
ArgoApplication(String name, String repoUrl, String namespace, String path, String project = 'default') {
24+
ArgoApplication(String name, String repoUrl, String namespace, String destinationNamespace, String path, String project = 'default') {
2425
this.name = name
26+
this.namespace = namespace
27+
this.destinationNamespace = destinationNamespace
2528
this.project = project
2629
this.repoUrl = repoUrl
27-
this.namespace = namespace
2830
this.path = path
2931
}
3032

3133
Map<String, Object> toTemplateParams() {
3234
return [
33-
name : name,
34-
namespace : namespace,
35-
project : project,
36-
path : path,
37-
namePrefix: new Config().application.namePrefix,
38-
repoUrl : repoUrl
35+
name : this.name,
36+
namespace : this.namespace,
37+
project : this.project,
38+
path : this.path,
39+
destinationNamespace: this.destinationNamespace,
40+
repoUrl : this.repoUrl
3941
]
4042
}
4143

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.cloudogu.gitops.kubernetes.rbac
2+
3+
import com.cloudogu.gitops.config.Config
4+
import com.cloudogu.gitops.kubernetes.argocd.ArgoApplication
5+
import com.cloudogu.gitops.scmm.ScmmRepo
6+
import com.cloudogu.gitops.utils.FileSystemUtils
7+
import groovy.yaml.YamlSlurper
8+
import org.junit.jupiter.api.Test
9+
10+
import static org.assertj.core.api.Assertions.assertThat
11+
12+
class ArgocdApplicationTest {
13+
14+
15+
Config config = Config.fromMap([
16+
scmm : [
17+
username: 'user',
18+
password: 'pass',
19+
protocol: 'http',
20+
host : 'localhost',
21+
provider: 'scm-manager',
22+
rootPath: 'scm'
23+
],
24+
application: [
25+
namePrefix: '',
26+
insecure : false,
27+
gitName : 'Test User',
28+
gitEmail : 'test@example.com'
29+
]
30+
])
31+
32+
33+
@Test
34+
void 'simple ArgoCD Application with common values'() {
35+
36+
ScmmRepo repo = new ScmmRepo(config, "my-repo", new FileSystemUtils())
37+
38+
new ArgoApplication(
39+
'example-apps',
40+
'testurl.com/argocd/example-apps',
41+
'testprefix-argocd',
42+
'testnamespace',
43+
'argocd/')
44+
.generate(repo, 'testsubfolder/test')
45+
46+
47+
File file = new File(repo.getAbsoluteLocalRepoTmpDir(), "testsubfolder/test/argocd-application-example-apps-testprefix-argocd.yaml")
48+
assertThat(file).exists()
49+
Map yaml = new YamlSlurper().parse(file) as Map
50+
51+
assertThat(yaml["metadata"]["name"]).isEqualTo('example-apps')
52+
assertThat(yaml["metadata"]["namespace"]).isEqualTo('testprefix-argocd')
53+
assertThat(yaml["spec"]["destination"]["namespace"]).isEqualTo('testnamespace')
54+
55+
assertThat(yaml["spec"]["source"]["path"]).isEqualTo('argocd/')
56+
assertThat(yaml["spec"]["source"]["repoURL"]).isEqualTo('testurl.com/argocd/example-apps')
57+
}
58+
}

templates/kubernetes/argocd/application.ftl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ metadata:
99
spec:
1010
destination:
1111
server: https://kubernetes.default.svc
12-
namespace: ${namePrefix}argocd
12+
namespace: ${destinationNamespace}
1313
project: default
1414
source:
1515
path: ${path}

0 commit comments

Comments
 (0)