-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy Mailhog and Prometheus stack imperatively
Advantage: * Can be used from all GitOps operators in playground * Uniform way, sam method of deployment as for Jenkins, SCMM, Registry, External Secrets, Vault
- Loading branch information
1 parent
517b0e4
commit ef07e1c
Showing
15 changed files
with
256 additions
and
263 deletions.
There are no files selected for viewing
91 changes: 0 additions & 91 deletions
91
argocd/control-app/applications/system/application-kube-prometheus-stack-helm.yaml
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
argocd/control-app/applications/system/application-mailhog-helm.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 21 additions & 8 deletions
29
...ogu/gitops/features/argocd/Mailhog.groovy → ...m/cloudogu/gitops/features/Mailhog.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,60 @@ | ||
package com.cloudogu.gitops.features.argocd | ||
package com.cloudogu.gitops.features | ||
|
||
import com.cloudogu.gitops.Feature | ||
import com.cloudogu.gitops.utils.FileSystemUtils | ||
import com.cloudogu.gitops.utils.HelmClient | ||
import groovy.util.logging.Slf4j | ||
import org.springframework.security.crypto.bcrypt.BCrypt | ||
|
||
@Slf4j | ||
class Mailhog extends Feature { | ||
|
||
static final String MAILHOG_YAML_PATH = "applications/system/application-mailhog-helm.yaml" | ||
static final String HELM_VALUES_PATH = "system/mailhog-helm-values.yaml" | ||
|
||
private Map config | ||
private boolean remoteCluster | ||
private String username | ||
private String password | ||
private String tmpGitRepoDir | ||
private FileSystemUtils fileSystemUtils | ||
HelmClient helmClient | ||
|
||
Mailhog(Map config, String tmpGitRepoDir, FileSystemUtils fileSystemUtils = new FileSystemUtils()) { | ||
Mailhog(Map config, FileSystemUtils fileSystemUtils = new FileSystemUtils(), | ||
HelmClient helmClient = new HelmClient()) { | ||
this.config = config | ||
this.remoteCluster = config.application["remote"] | ||
this.username = config.application["username"] | ||
this.password = config.application["password"] | ||
this.tmpGitRepoDir = tmpGitRepoDir | ||
this.fileSystemUtils = fileSystemUtils | ||
this.helmClient = helmClient | ||
} | ||
|
||
@Override | ||
boolean isEnabled() { | ||
config.features["argocd"]["active"] | ||
true | ||
} | ||
|
||
@Override | ||
void enable() { | ||
def tmpHelmValues = fileSystemUtils.copyToTempDir(HELM_VALUES_PATH) | ||
def tmpHelmValuesFolder = tmpHelmValues.parent.toString() | ||
def tmpHelmValuesFile = tmpHelmValues.fileName.toString() | ||
|
||
if (!remoteCluster) { | ||
log.debug("Setting mailhog service.type to NodePort since it is not running in a remote cluster") | ||
fileSystemUtils.replaceFileContent(tmpGitRepoDir, MAILHOG_YAML_PATH, "LoadBalancer", "NodePort") | ||
fileSystemUtils.replaceFileContent(tmpHelmValuesFolder, tmpHelmValuesFile, | ||
"LoadBalancer", "NodePort") | ||
} | ||
|
||
log.debug("Setting new mailhog credentials") | ||
String bcryptMailhogPassword = BCrypt.hashpw(password, BCrypt.gensalt(4)) | ||
String from = "fileContents: \"admin:\$2a\$04\$bM4G0jXB7m7mSv4UT8IuIe3.Bj6i6e2A13ryA0ln.hpyX7NeGQyG.\"" | ||
String to = "fileContents: \"$username:$bcryptMailhogPassword\"" | ||
fileSystemUtils.replaceFileContent(tmpGitRepoDir, MAILHOG_YAML_PATH, from, to) | ||
|
||
fileSystemUtils.replaceFileContent(tmpHelmValuesFolder, tmpHelmValuesFile, from, to) | ||
|
||
helmClient.addRepo('codecentric', 'https://codecentric.github.io/helm-charts') | ||
helmClient.upgrade('mailhog', 'codecentric/mailhog', '5.0.1', | ||
[namespace: 'monitoring', | ||
values: "${tmpHelmValues.toString()}"]) | ||
} | ||
} |
36 changes: 19 additions & 17 deletions
36
...ps/features/argocd/PrometheusStack.groovy → ...gu/gitops/features/PrometheusStack.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,65 @@ | ||
package com.cloudogu.gitops.features.argocd | ||
package com.cloudogu.gitops.features | ||
|
||
import com.cloudogu.gitops.Feature | ||
import com.cloudogu.gitops.utils.HelmClient | ||
import com.cloudogu.gitops.utils.K8sClient | ||
import com.cloudogu.gitops.utils.FileSystemUtils | ||
import groovy.util.logging.Slf4j | ||
|
||
@Slf4j | ||
class PrometheusStack extends Feature { | ||
|
||
static final String STACK_YAML_PATH = "applications/system/application-kube-prometheus-stack-helm.yaml" | ||
static final String HELM_VALUES_PATH = "system/monitoring/prometheus-stack-helm-values.yaml" | ||
|
||
private Map config | ||
private boolean remoteCluster | ||
private String username | ||
private String password | ||
private String tmpGitRepoDir | ||
private FileSystemUtils fileSystemUtils | ||
private K8sClient k8sClient | ||
HelmClient helmClient | ||
|
||
PrometheusStack(Map config, String tmpGitRepoDir, FileSystemUtils fileSystemUtils = new FileSystemUtils(), | ||
K8sClient k8sClient = new K8sClient()) { | ||
PrometheusStack(Map config, FileSystemUtils fileSystemUtils = new FileSystemUtils(), | ||
K8sClient k8sClient = new K8sClient(), HelmClient helmClient = new HelmClient()) { | ||
this.config = config | ||
this.username = config.application["username"] | ||
this.password = config.application["password"] | ||
this.remoteCluster = config.application["remote"] | ||
this.tmpGitRepoDir = tmpGitRepoDir | ||
this.fileSystemUtils = fileSystemUtils | ||
this.k8sClient = k8sClient | ||
this.helmClient = helmClient | ||
} | ||
|
||
@Override | ||
boolean isEnabled() { | ||
return config.features["metrics"] && config.features["argocd"]["active"] | ||
return config.features["metrics"] | ||
} | ||
|
||
@Override | ||
void enable() { | ||
def tmpHelmValues = fileSystemUtils.copyToTempDir(HELM_VALUES_PATH) | ||
def tmpHelmValuesFolder = tmpHelmValues.parent.toString() | ||
def tmpHelmValuesFile = tmpHelmValues.fileName.toString() | ||
|
||
if (remoteCluster) { | ||
log.debug("Setting grafana service.type to LoadBalancer since it is running in a remote cluster") | ||
fileSystemUtils.replaceFileContent(tmpGitRepoDir, STACK_YAML_PATH, "NodePort", "LoadBalancer") | ||
fileSystemUtils.replaceFileContent(tmpHelmValuesFolder, tmpHelmValuesFile, "NodePort", "LoadBalancer") | ||
} | ||
|
||
k8sClient.applyYaml(fileSystemUtils.rootDir + "/system/metrics/grafana/dashboards/") | ||
|
||
if (username != null && username != "admin") { | ||
log.debug("Setting grafana username") | ||
fileSystemUtils.replaceFileContent(tmpGitRepoDir, STACK_YAML_PATH, | ||
fileSystemUtils.replaceFileContent(tmpHelmValuesFolder, tmpHelmValuesFile, | ||
'adminUser: admin', "adminUser: $username") | ||
} | ||
if (password != null && password != "admin") { | ||
log.debug("Setting grafana password") | ||
fileSystemUtils.replaceFileContent(tmpGitRepoDir, STACK_YAML_PATH, | ||
fileSystemUtils.replaceFileContent(tmpHelmValuesFolder, tmpHelmValuesFile, | ||
"adminPassword: admin", "adminPassword: $password") | ||
} | ||
} | ||
|
||
@Override | ||
void disable() { | ||
String prometheusStack = tmpGitRepoDir + '/' + STACK_YAML_PATH | ||
new File(prometheusStack).delete() | ||
helmClient.addRepo('prometheus-community', 'https://prometheus-community.github.io/helm-charts') | ||
helmClient.upgrade('kube-prometheus-stack', 'prometheus-community/kube-prometheus-stack', '19.2.2', | ||
[namespace: 'monitoring', | ||
values: "${tmpHelmValues.toString()}"]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.