Skip to content

Namespace prefix for multi-tenancy support #273

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

Merged
merged 2 commits into from
Apr 29, 2025
Merged
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: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ node('high-cpu') {
images[1].push(git.tag + '-dev')
images[1].push('dev')
images[1].push('latest-dev')
images[1].push('main-dev')
images[0].push()
images[0].push('latest')
images[0].push('main')
images[0].push(git.tag)

currentBuild.description = createImageName(git.tag)
Expand Down
11 changes: 7 additions & 4 deletions applications/argocd/nginx/helm-jenkins/Jenkinsfile.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

String getApplication() { "nginx-helm-jenkins" }
String getScmManagerCredentials() { 'scmm-user' }
String getConfigRepositoryPRBaseUrl() { env.SCMM_URL }
String getConfigRepositoryPRBaseUrl() { env.${namePrefixForEnvVars}SCMM_URL }
String getConfigRepositoryPRRepo() { '${namePrefix}argocd/example-apps' }
<#noparse>
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib/" }

String getCesBuildLibRepo() { configRepositoryPRBaseUrl+"/repo/3rd-party-dependencies/ces-build-lib/" }
String getGitOpsBuildLibRepo() { configRepositoryPRBaseUrl+"/repo/3rd-party-dependencies/gitops-build-lib" }

String getCesBuildLibVersion() { '2.5.0' }
String getGitOpsBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/gitops-build-lib" }
String getGitOpsBuildLibVersion() { '0.7.0'}

String getHelmChartRepository() { "https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami" }
String getHelmChartName() { "nginx" }
String getHelmChartVersion() { "13.2.21" }
Expand Down Expand Up @@ -104,4 +107,4 @@ node('docker') {

def cesBuildLib
def gitOpsBuildLib
</#noparse>
</#noparse>
11 changes: 6 additions & 5 deletions applications/argocd/petclinic/helm/Jenkinsfile.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

String getApplication() { "spring-petclinic-helm" }
String getScmManagerCredentials() { 'scmm-user' }
String getConfigRepositoryPRBaseUrl() { env.SCMM_URL }
String getConfigRepositoryPRBaseUrl() { env.${namePrefixForEnvVars}SCMM_URL }
String getConfigRepositoryPRRepo() { '${namePrefix}argocd/example-apps' }

String getDockerRegistryBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_URL }
Expand All @@ -15,11 +15,12 @@ String getDockerRegistryProxyCredentials() { 'registry-proxy-user' }
</#if>

<#noparse>
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib/" }

String getCesBuildLibRepo() { configRepositoryPRBaseUrl+"/repo/3rd-party-dependencies/ces-build-lib/" }
String getCesBuildLibVersion() { '2.5.0' }
String getGitOpsBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/gitops-build-lib" }
String getGitOpsBuildLibRepo() { configRepositoryPRBaseUrl+"/repo/3rd-party-dependencies/gitops-build-lib" }
String getGitOpsBuildLibVersion() { '0.7.0'}
String getHelmChartRepository() { "${env.SCMM_URL}/repo/3rd-party-dependencies/spring-boot-helm-chart-with-dependency" }
String getHelmChartRepository() { configRepositoryPRBaseUrl+"/repo/3rd-party-dependencies/spring-boot-helm-chart-with-dependency" }
String getHelmChartVersion() { "1.0.0" }
String getMainBranch() { 'main' }

Expand Down Expand Up @@ -196,4 +197,4 @@ String createImageTag() {

def cesBuildLib
def gitOpsBuildLib
</#noparse>
</#noparse>
10 changes: 6 additions & 4 deletions applications/argocd/petclinic/plain-k8s/Jenkinsfile.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
String getApplication() { 'spring-petclinic-plain' }
String getConfigRepositoryPRRepo() { '${namePrefix}argocd/example-apps' }
String getScmManagerCredentials() { 'scmm-user' }
String getConfigRepositoryPRBaseUrl() { env.SCMM_URL }
String getConfigRepositoryPRBaseUrl() { env.${namePrefixForEnvVars}SCMM_URL }

String getDockerRegistryBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_URL }
String getDockerRegistryPath() { env.${namePrefixForEnvVars}REGISTRY_PATH }
Expand All @@ -15,9 +15,11 @@ String getDockerRegistryProxyCredentials() { 'registry-proxy-user' }
</#if>

<#noparse>
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib" }

String getCesBuildLibRepo() { configRepositoryPRBaseUrl+"/repo/3rd-party-dependencies/ces-build-lib/" }
String getGitOpsBuildLibRepo() { configRepositoryPRBaseUrl+"/repo/3rd-party-dependencies/gitops-build-lib" }

String getCesBuildLibVersion() { '2.5.0' }
String getGitOpsBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/gitops-build-lib" }
String getGitOpsBuildLibVersion() { '0.7.0'}

loadLibraries()
Expand Down Expand Up @@ -229,4 +231,4 @@ def loadLibraries() {

def cesBuildLib
def gitOpsBuildLib
</#noparse>
</#noparse>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ${namePrefix}monitoring
kubernetes.io/metadata.name: "${namePrefix}monitoring"
podSelector:
matchLabels:
prometheus: kube-prometheus-stack-prometheus
6 changes: 3 additions & 3 deletions argocd/argocd/operator/rbac/example-apps-production.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: example-apps-production
namespace: "${namePrefix}example-apps-production"
name: argocd
rules:
- apiGroups:
Expand Down Expand Up @@ -166,7 +166,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argocd
namespace: example-apps-production
namespace: "${namePrefix}example-apps-production"
subjects:
- kind: ServiceAccount
name: argocd-argocd-server
Expand All @@ -180,4 +180,4 @@ subjects:
roleRef:
kind: Role
name: argocd
apiGroup: rbac.authorization.k8s.io
apiGroup: rbac.authorization.k8s.io
6 changes: 3 additions & 3 deletions argocd/argocd/operator/rbac/example-apps-staging.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: example-apps-staging
namespace: "${namePrefix}example-apps-staging"
name: argocd
rules:
- apiGroups:
Expand Down Expand Up @@ -166,7 +166,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argocd
namespace: example-apps-staging
namespace: "${namePrefix}example-apps-staging"
subjects:
- kind: ServiceAccount
name: argocd-argocd-server
Expand All @@ -180,4 +180,4 @@ subjects:
roleRef:
kind: Role
name: argocd
apiGroup: rbac.authorization.k8s.io
apiGroup: rbac.authorization.k8s.io
6 changes: 3 additions & 3 deletions argocd/argocd/operator/rbac/ingress-nginx.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: ingress-nginx
namespace: "${namePrefix}ingress-nginx"
name: argocd
rules:
- apiGroups:
Expand Down Expand Up @@ -166,7 +166,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argocd
namespace: ingress-nginx
namespace: "${namePrefix}ingress-nginx"
subjects:
- kind: ServiceAccount
name: argocd-argocd-server
Expand All @@ -180,4 +180,4 @@ subjects:
roleRef:
kind: Role
name: argocd
apiGroup: rbac.authorization.k8s.io
apiGroup: rbac.authorization.k8s.io
6 changes: 3 additions & 3 deletions argocd/argocd/operator/rbac/monitoring.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: monitoring
namespace: "${namePrefix}monitoring"
name: argocd
rules:
- apiGroups:
Expand Down Expand Up @@ -166,7 +166,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argocd
namespace: monitoring
namespace: "${namePrefix}monitoring"
subjects:
- kind: ServiceAccount
name: argocd-argocd-server
Expand All @@ -180,4 +180,4 @@ subjects:
roleRef:
kind: Role
name: argocd
apiGroup: rbac.authorization.k8s.io
apiGroup: rbac.authorization.k8s.io
6 changes: 3 additions & 3 deletions argocd/argocd/operator/rbac/secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: secrets
namespace: "${namePrefix}secrets"
name: argocd
rules:
- apiGroups:
Expand Down Expand Up @@ -166,7 +166,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argocd
namespace: secrets
namespace: "${namePrefix}secrets"
subjects:
- kind: ServiceAccount
name: argocd-argocd-server
Expand All @@ -180,4 +180,4 @@ subjects:
roleRef:
kind: Role
name: argocd
apiGroup: rbac.authorization.k8s.io
apiGroup: rbac.authorization.k8s.io
2 changes: 1 addition & 1 deletion scripts/init-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,4 @@ function echoHightlighted() {
fi
}

main "$@"
main "$@"
2 changes: 1 addition & 1 deletion scripts/jenkins/init-jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi

function initJenkins() {
if [[ ${INTERNAL_JENKINS} == true ]]; then
setExternalHostnameIfNecessary "JENKINS" "jenkins" "default"
setExternalHostnameIfNecessary "JENKINS" "jenkins" "${NAME_PREFIX}jenkins"
fi

installPlugins
Expand Down
2 changes: 1 addition & 1 deletion scripts/scm-manager/init-scmm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function initSCMM() {

echo "SCM provider: ${SCM_PROVIDER}"
if [[ ${INTERNAL_SCMM} == true ]]; then
setExternalHostnameIfNecessary 'SCMM' 'scmm-scm-manager' 'default'
setExternalHostnameIfNecessary 'SCMM' 'scmm-scm-manager' "${NAME_PREFIX}scm-manager"
fi

[[ "${SCMM_URL}" != *scm ]] && SCMM_URL=${SCMM_URL}/scm
Expand Down
21 changes: 5 additions & 16 deletions src/main/groovy/com/cloudogu/gitops/Application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ class Application {
final Config config

Application(Config config,
List<Feature> features
List<Feature> features
) {
this.config=config
this.config = config
// Order is important. Enforced by @Order-Annotation on the Singletons
this.features = features

}

def start() {
Expand All @@ -36,15 +35,10 @@ class Application {

void setNamespaceListToConfig(Config config) {
Set<String> namespaces = new HashSet<>()
String namePrefix = config.application.namePrefix;
String namePrefix = config.application.namePrefix

if(config.registry.internal || config.scmm.internal || config.jenkins.internal){
namespaces.add(namePrefix + "default")
}

if (config.features.argocd.active) {
namespaces.addAll(Arrays.asList(
namePrefix + "argocd",
namePrefix + "example-apps-staging",
namePrefix + "example-apps-production"
))
Expand All @@ -55,14 +49,9 @@ class Application {
.collect { it.activeNamespaceFromFeature }
.findAll { it }
.unique()
.collect { "${namePrefix}${it}".toString() })

//TODO remove after Jenkins/SCMM/Registry got their own namespaces
if(config.application.openshift){
namespaces.remove(namePrefix + "default")
}
.collect { "${it}".toString() })

log.debug("Active namespaces retrieved: {}", namespaces);
config.application.activeNamespaces = namespaces.toList()
}
}
}
4 changes: 2 additions & 2 deletions src/main/groovy/com/cloudogu/gitops/FeatureWithImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ trait FeatureWithImage {
void createImagePullSecret() {
if (config.registry.createImagePullSecrets) {

log.trace("Creating image pull secret 'proxy-registry' in namespace ${namespace}")
log.trace("Creating image pull secret 'proxy-registry' in namespace ${this.namespace}")
String url = config.registry.proxyUrl ?: config.registry.url
String user = config.registry.proxyUsername ?: config.registry.readOnlyUsername ?: config.registry.username
String password = config.registry.proxyPassword ?: config.registry.readOnlyPassword ?: config.registry.password

k8sClient.createNamespace(namespace)
k8sClient.createNamespace(this.namespace)
k8sClient.createImagePullSecret('proxy-registry', namespace, url, user, password)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if "this" is neccessary for usage this.namespace, it should be used here, too.

Suggested change
k8sClient.createImagePullSecret('proxy-registry', namespace, url, user, password)
k8sClient.createImagePullSecret('proxy-registry', this.namespace, url, user, password)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import com.cloudogu.gitops.scmm.ScmmRepoProvider
import com.cloudogu.gitops.utils.*
import groovy.util.logging.Slf4j
import io.micronaut.context.ApplicationContext
import jakarta.inject.Provider
import jakarta.inject.Provider

/**
* Micronaut's dependency injection relies on statically compiled class files with seems incompatible with groovy
* scripting/interpretation (without prior compilation).
Expand Down Expand Up @@ -52,7 +53,7 @@ class GitopsPlaygroundCliMainScripted {
def helmClient = new HelmClient(executor)

def httpClientFactory = new HttpClientFactory()

def scmmRepoProvider = new ScmmRepoProvider(config, fileSystemUtils)
def retrofitFactory = new RetrofitFactory()

Expand All @@ -72,7 +73,7 @@ class GitopsPlaygroundCliMainScripted {
httpClientFactory.okHttpClient(httpClientFactory.createLoggingInterceptor(), jenkinsConfiguration, insecureSslContextProvider))

context.registerSingleton(k8sClient)

if (config.application.destroy) {
context.registerSingleton(new Destroyer([
new ArgoCDDestructionHandler(config, k8sClient, scmmRepoProvider, helmClient, fileSystemUtils),
Expand All @@ -86,9 +87,9 @@ class GitopsPlaygroundCliMainScripted {

def airGappedUtils = new AirGappedUtils(config, scmmRepoProvider, repoApi, fileSystemUtils, helmClient)

context.registerSingleton(new Application(config,[
context.registerSingleton(new Application(config, [
new Registry(config, fileSystemUtils, k8sClient, helmStrategy),
new ScmManager(config, executor, fileSystemUtils, helmStrategy),
new ScmManager(config, executor, fileSystemUtils, helmStrategy, k8sClient),
new Jenkins(config, executor, fileSystemUtils, new GlobalPropertyManager(jenkinsApiClient),
new JobManager(jenkinsApiClient), new UserManager(jenkinsApiClient),
new PrometheusConfigurator(jenkinsApiClient), helmStrategy, k8sClient),
Expand All @@ -104,4 +105,4 @@ class GitopsPlaygroundCliMainScripted {
}
}
}
}
}
Loading