Skip to content
Open
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
48 changes: 48 additions & 0 deletions src/main/groovy/com/cloudogu/gitops/Feature.groovy
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.cloudogu.gitops

import com.cloudogu.gitops.config.Config
import com.cloudogu.gitops.features.deployment.Deployer
import com.cloudogu.gitops.features.deployment.DeploymentStrategy
import com.cloudogu.gitops.features.git.GitHandler
import com.cloudogu.gitops.utils.AirGappedUtils
import com.cloudogu.gitops.utils.TemplatingEngine
import groovy.util.logging.Slf4j
import groovy.yaml.YamlSlurper

import java.nio.file.Path

import static com.cloudogu.gitops.features.deployment.DeploymentStrategy.*

/**
* A single tool to be deployed by GOP.
*
Expand Down Expand Up @@ -68,6 +76,46 @@ abstract class Feature {
return new YamlSlurper().parseText(hydratedString) as Map
}

protected void deployHelmChart(
String featureName,
String releaseName,
String namespace,
Config.HelmConfig helmConfig,
Path tempValuesPath,
Config config,
DeploymentStrategy deployer,
AirGappedUtils airGappedUtils,
GitHandler gitHandler
) {
String repoURL = helmConfig.repoURL
String chartOrPath = helmConfig.chart
String version = helmConfig.version
RepoType repoType = RepoType.HELM

if (config.application.mirrorRepos) {
log.debug("Using a local, mirrored git repo as deployment source for feature ${featureName}")

String repoNamespaceAndName = airGappedUtils.mirrorHelmRepoToGit(helmConfig)
repoURL = gitHandler.resourcesScm.repoUrl(repoNamespaceAndName)
chartOrPath = '.'
repoType = RepoType.GIT
version = new YamlSlurper()
.parse(Path.of("${config.application.localHelmChartFolder}/${helmConfig.chart}",
'Chart.yaml'))['version']
}

log.debug("Starting deployment of feature ${featureName} from ${repoURL}.")
deployer.deployFeature(
repoURL,
featureName,
chartOrPath,
version,
namespace,
releaseName,
tempValuesPath,
repoType)
}

abstract boolean isEnabled()


Expand Down
28 changes: 1 addition & 27 deletions src/main/groovy/com/cloudogu/gitops/features/CertManager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,7 @@ class CertManager extends Feature implements FeatureWithImage {
def tempValuesPath = fileSystemUtils.writeTempFile(mergedMap)

def helmConfig = config.features.certManager.helm
if (config.application.mirrorRepos) {
log.debug("Mirroring repos: Deploying certManager from local git repo")

def repoNamespaceAndName = airGappedUtils.mirrorHelmRepoToGit(config.features.certManager.helm)

String certManagerVersion =
new YamlSlurper().parse(Path.of("${config.application.localHelmChartFolder}/${helmConfig.chart}",
'Chart.yaml'))['version']

deployer.deployFeature(
gitHandler.getResourcesScm().repoUrl(repoNamespaceAndName),
'cert-manager',
'.',
certManagerVersion,
namespace,
'cert-manager',
tempValuesPath, DeploymentStrategy.RepoType.GIT)
} else {
deployer.deployFeature(
helmConfig.repoURL,
'cert-manager',
helmConfig.chart,
helmConfig.version,
namespace,
'cert-manager',
tempValuesPath
)
}
deployHelmChart('cert-manager', 'cert-manager', namespace, helmConfig, tempValuesPath, config, deployer, airGappedUtils, gitHandler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,6 @@ class ExternalSecretsOperator extends Feature implements FeatureWithImage {
def mergedMap = MapUtils.deepMerge(helmConfig.values, templatedMap)
def tempValuesPath = fileSystemUtils.writeTempFile(mergedMap)


if (config.application.mirrorRepos) {
log.debug("Mirroring repos: Deploying externalSecretsOperator from local git repo")

def repoNamespaceAndName = airGappedUtils.mirrorHelmRepoToGit(config.features.secrets.externalSecrets.helm as Config.HelmConfig)

String externalSecretsVersion =
new YamlSlurper().parse(Path.of("${config.application.localHelmChartFolder}/${helmConfig.chart}",
'Chart.yaml'))['version']

deployer.deployFeature(
this.gitHandler.resourcesScm.repoUrl(repoNamespaceAndName),
"external-secrets",
'.',
externalSecretsVersion,
namespace,
'external-secrets',
tempValuesPath, DeploymentStrategy.RepoType.GIT
)
} else {
deployer.deployFeature(
helmConfig.repoURL,
"externalsecretsoperator",
helmConfig.chart,
helmConfig.version,
namespace,
'external-secrets',
tempValuesPath
)
}
deployHelmChart('external-secrets-operator', 'external-secrets', namespace, helmConfig, tempValuesPath, config, deployer, airGappedUtils, gitHandler)
}
}
30 changes: 1 addition & 29 deletions src/main/groovy/com/cloudogu/gitops/features/Ingress.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,6 @@ class Ingress extends Feature implements FeatureWithImage {
def mergedMap = MapUtils.deepMerge(helmConfig.values, templatedMap)
def tempValuesPath = fileSystemUtils.writeTempFile(mergedMap)


if (config.application.mirrorRepos) {
log.debug("Mirroring repos: Deploying Ingress from local git repo")

def repoNamespaceAndName = airGappedUtils.mirrorHelmRepoToGit(config.features.ingress.helm as Config.HelmConfig)

String ingressVersion =
new YamlSlurper().parse(Path.of("${config.application.localHelmChartFolder}/${helmConfig.chart}",
'Chart.yaml'))['version']

deployer.deployFeature(
gitHandler.resourcesScm.repoUrl(repoNamespaceAndName),
'traefik',
'.',
ingressVersion,
namespace,
'traefik',
tempValuesPath, DeploymentStrategy.RepoType.GIT)
} else {
deployer.deployFeature(
helmConfig.repoURL as String,
'traefik',
helmConfig.chart as String,
helmConfig.version as String,
namespace,
'traefik',
tempValuesPath
)
}
deployHelmChart('traefik', 'traefik', namespace, helmConfig, tempValuesPath, config, deployer, airGappedUtils, gitHandler)
}
}
11 changes: 2 additions & 9 deletions src/main/groovy/com/cloudogu/gitops/features/Jenkins.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Jenkins extends Feature {
private K8sClient k8sClient
private NetworkingUtils networkingUtils
private GitHandler gitHandler
private AirGappedUtils airGappedUtils

Jenkins(
Config config,
Expand Down Expand Up @@ -105,15 +106,7 @@ class Jenkins extends Feature {
def tempValuesPath = fileSystemUtils.writeTempFile(mergedMap)

String releaseName = "jenkins"
deployer.deployFeature(
helmConfig.repoURL,
'jenkins',
helmConfig.chart,
helmConfig.version,
namespace,
releaseName,
tempValuesPath
)
deployHelmChart('jenkins', releaseName, namespace, helmConfig, tempValuesPath, config, deployer, airGappedUtils, gitHandler)

// Defined here: https://github.com/jenkinsci/helm-charts/blob/jenkins-5.8.1/charts/jenkins/templates/_helpers.tpl#L46-L57
String serviceName = releaseName
Expand Down
30 changes: 2 additions & 28 deletions src/main/groovy/com/cloudogu/gitops/features/Mailhog.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.cloudogu.gitops.features
import com.cloudogu.gitops.Feature
import com.cloudogu.gitops.FeatureWithImage
import com.cloudogu.gitops.config.Config
import com.cloudogu.gitops.features.deployment.Deployer
import com.cloudogu.gitops.features.deployment.DeploymentStrategy
import com.cloudogu.gitops.features.git.GitHandler
import com.cloudogu.gitops.utils.AirGappedUtils
Expand Down Expand Up @@ -79,33 +80,6 @@ class Mailhog extends Feature implements FeatureWithImage {

def tempValuesPath = fileSystemUtils.writeTempFile(mergedMap)


if (config.application.mirrorRepos) {
log.debug("Mirroring repos: Deploying mailhog from local git repo")

def repoNamespaceAndName = airGappedUtils.mirrorHelmRepoToGit(config.features.mail.helm as Config.HelmConfig)

String mailhogVersion =
new YamlSlurper().parse(Path.of("${config.application.localHelmChartFolder}/${helmConfig.chart}",
'Chart.yaml'))['version']

deployer.deployFeature(
"${this.gitHandler.resourcesScm.repoUrl(repoNamespaceAndName)}",
'mailhog',
'.',
mailhogVersion,
namespace,
'mailhog',
tempValuesPath, DeploymentStrategy.RepoType.GIT)
} else {
deployer.deployFeature(
helmConfig.repoURL,
'mailhog',
helmConfig.chart,
helmConfig.version,
namespace,
'mailhog',
tempValuesPath)
}
deployHelmChart('mailhog', 'mailhog', namespace, helmConfig, tempValuesPath, config, deployer, airGappedUtils, gitHandler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,34 +133,7 @@ class PrometheusStack extends Feature implements FeatureWithImage {

def tempValuesPath = fileSystemUtils.writeTempFile(mergedMap)

if (config.application.mirrorRepos) {
log.debug("Mirroring repos: Deploying prometheus from local git repo")

def repoNamespaceAndName = airGappedUtils.mirrorHelmRepoToGit(config.features.monitoring.helm as Config.HelmConfig)

String prometheusVersion =
new YamlSlurper().parse(Path.of("${config.application.localHelmChartFolder}/${helmConfig.chart}",
'Chart.yaml'))['version']

deployer.deployFeature(
this.gitHandler.resourcesScm.repoUrl(repoNamespaceAndName),
'prometheusstack',
'.',
prometheusVersion,
namespace,
'kube-prometheus-stack',
tempValuesPath, RepoType.GIT)
} else {

deployer.deployFeature(
helmConfig.repoURL,
'prometheusstack',
helmConfig.chart,
helmConfig.version,
namespace,
'kube-prometheus-stack',
tempValuesPath)
}
deployHelmChart('prometheusstack', 'kube-prometheus-stack', namespace, helmConfig, tempValuesPath, config, deployer, airGappedUtils, gitHandler)
}

private Map<String, Object> buildTemplateValues(Config config, String uid) {
Expand Down
24 changes: 5 additions & 19 deletions src/main/groovy/com/cloudogu/gitops/features/Registry.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.cloudogu.gitops.Feature
import com.cloudogu.gitops.config.Config
import com.cloudogu.gitops.features.deployment.DeploymentStrategy
import com.cloudogu.gitops.features.deployment.HelmStrategy
import com.cloudogu.gitops.features.git.GitHandler
import com.cloudogu.gitops.utils.AirGappedUtils
import com.cloudogu.gitops.utils.FileSystemUtils
import com.cloudogu.gitops.kubernetes.api.K8sClient
import com.cloudogu.gitops.utils.MapUtils
Expand All @@ -29,6 +31,8 @@ class Registry extends Feature {
private FileSystemUtils fileSystemUtils
private Path tmpHelmValues
private K8sClient k8sClient
private AirGappedUtils airGappedUtils
private GitHandler gitHandler

Registry(
Config config,
Expand Down Expand Up @@ -71,15 +75,7 @@ class Registry extends Feature {
log.trace("Helm yaml to be applied: ${yaml}")


deployer.deployFeature(
helmConfig.repoURL,
'registry',
helmConfig.chart,
helmConfig.version,
namespace,
'docker-registry',
tempValuesPath
)
deployHelmChart('registry', 'docker-registry', namespace, helmConfig, tempValuesPath, config, deployer, airGappedUtils, gitHandler)

if (config.registry.internalPort != Config.DEFAULT_REGISTRY_PORT) {
/* Add additional node port
Expand All @@ -101,16 +97,6 @@ class Registry extends Feature {
config.registry.internalPort,
'docker-registry-internal-port')
}

deployer.deployFeature(
helmConfig.repoURL,
'registry',
helmConfig.chart,
helmConfig.version,
namespace,
'docker-registry',
tempValuesPath
)
}
}
}
30 changes: 1 addition & 29 deletions src/main/groovy/com/cloudogu/gitops/features/Vault.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,6 @@ class Vault extends Feature implements FeatureWithImage {
log.trace("Helm yaml to be applied: ${templatedMap}")
def tempValuesPath = fileSystemUtils.writeTempFile(templatedMap)

if (config.application.mirrorRepos) {
log.debug('Mirroring repos: Deploying vault from local git repo')

def repoNamespaceAndName = airGappedUtils.mirrorHelmRepoToGit(config.features.secrets.vault.helm as Config.HelmConfig)

String vaultVersion =
new YamlSlurper().parse(Path.of(config.application.localHelmChartFolder + '/' + helmConfig.chart,
'Chart.yaml'))['version']

deployer.deployFeature(
this.gitHandler.resourcesScm.repoUrl(repoNamespaceAndName),
'vault',
'.',
vaultVersion,
namespace,
'vault',
tempValuesPath, DeploymentStrategy.RepoType.GIT
)
} else {
deployer.deployFeature(
helmConfig.repoURL,
'vault',
helmConfig.chart,
helmConfig.version,
namespace,
'vault',
tempValuesPath
)
}
deployHelmChart('vault', 'vault', namespace, helmConfig, tempValuesPath, config, deployer, airGappedUtils, gitHandler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.mockito.junit.jupiter.MockitoExtension
import java.nio.file.Files
import java.nio.file.Path

import static com.cloudogu.gitops.features.deployment.DeploymentStrategy.*
import static org.assertj.core.api.Assertions.assertThat
import static org.mockito.ArgumentMatchers.any
import static org.mockito.Mockito.verify
Expand Down Expand Up @@ -56,7 +57,7 @@ class CertManagerTest {

verify(deploymentStrategy).deployFeature('https://charts.jetstack.io', 'cert-manager',
'cert-manager', chartVersion, 'cert-manager',
'cert-manager', temporaryYamlFile)
'cert-manager', temporaryYamlFile, RepoType.HELM)
}

@Test
Expand Down Expand Up @@ -106,7 +107,7 @@ class CertManagerTest {
verify(deploymentStrategy).deployFeature(
'http://scmm.scm-manager.svc.cluster.local/scm/repo/a/b',
'cert-manager', '.', chartVersion, 'cert-manager',
'cert-manager', temporaryYamlFile, DeploymentStrategy.RepoType.GIT)
'cert-manager', temporaryYamlFile, RepoType.GIT)
}

@Test
Expand Down
Loading