-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from cloudogu/feature/argocd_helm
Feature/argocd helm
- Loading branch information
Showing
36 changed files
with
661 additions
and
475 deletions.
There are no files selected for viewing
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
42 changes: 42 additions & 0 deletions
42
src/com/cloudogu/gitopsbuildlib/deployment/helm/helmrelease/ArgoCDRelease.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.cloudogu.gitopsbuildlib.deployment.helm.helmrelease | ||
|
||
import com.cloudogu.gitopsbuildlib.docker.DockerWrapper | ||
|
||
class ArgoCDRelease extends HelmRelease{ | ||
|
||
protected DockerWrapper dockerWrapper | ||
|
||
ArgoCDRelease(def script) { | ||
super(script) | ||
dockerWrapper = new DockerWrapper(script) | ||
} | ||
|
||
@Override | ||
String create(Map helmConfig, String application, String namespace, String mergedValuesFile) { | ||
|
||
String helmRelease = "" | ||
if (helmConfig.repoType == 'GIT') { | ||
helmRelease = createResourcesFromGitRepo(helmConfig, application, mergedValuesFile) | ||
} else if (helmConfig.repoType == 'HELM') { | ||
// TODO not yet implemented | ||
} | ||
return helmRelease | ||
} | ||
|
||
private String createResourcesFromGitRepo(Map helmConfig, String application, String mergedValuesFile) { | ||
String helmRelease = "" | ||
|
||
def chartPath = '' | ||
if (helmConfig.containsKey('chartPath')) { | ||
chartPath = helmConfig.chartPath | ||
} | ||
|
||
dockerWrapper.withHelm { | ||
String templateScript = "helm template ${application} chart/${chartPath} -f ${mergedValuesFile}" | ||
helmRelease = script.sh returnStdout: true, script: templateScript | ||
} | ||
// this line removes all empty lines since helm template creates some and the helm kubeval validator will throw an error if there are emtpy lines present | ||
helmRelease = helmRelease.replaceAll("(?m)^[ \t]*\r?\n", "") | ||
return helmRelease | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/com/cloudogu/gitopsbuildlib/deployment/helm/helmrelease/FluxV1Release.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.cloudogu.gitopsbuildlib.deployment.helm.helmrelease | ||
|
||
class FluxV1Release extends HelmRelease{ | ||
|
||
FluxV1Release(def script) { | ||
super(script) | ||
} | ||
|
||
@Override | ||
String create(Map helmConfig, String application, String namespace, String mergedValuesFile) { | ||
def values = fileToInlineYaml(mergedValuesFile) | ||
def chart = getChart(helmConfig) | ||
return """apiVersion: helm.fluxcd.io/v1 | ||
kind: HelmRelease | ||
metadata: | ||
name: ${application} | ||
namespace: ${namespace} | ||
annotations: | ||
fluxcd.io/automated: "false" | ||
spec: | ||
releaseName: ${application} | ||
chart:${chart} | ||
values: | ||
${values} | ||
""" | ||
} | ||
|
||
private String gitRepoChart(Map helmConfig) { | ||
|
||
def chartPath = "." | ||
if (helmConfig.containsKey('chartPath') && helmConfig.chartPath) { | ||
chartPath = helmConfig.chartPath | ||
} | ||
|
||
return """ | ||
git: ${helmConfig.repoUrl} | ||
ref: ${helmConfig.version} | ||
path: ${chartPath}""" | ||
} | ||
|
||
private String helmRepoChart(Map helmConfig) { | ||
return """ | ||
repository: ${helmConfig.repoUrl} | ||
name: ${helmConfig.chartName} | ||
version: ${helmConfig.version}""" | ||
} | ||
|
||
private String getChart(Map helmConfig) { | ||
if (helmConfig.repoType == 'GIT') { | ||
return gitRepoChart(helmConfig) | ||
} else if (helmConfig.repoType == 'HELM') { | ||
return helmRepoChart(helmConfig) | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/com/cloudogu/gitopsbuildlib/deployment/helm/helmrelease/HelmRelease.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.cloudogu.gitopsbuildlib.deployment.helm.helmrelease | ||
|
||
abstract class HelmRelease { | ||
|
||
protected script | ||
|
||
HelmRelease(def script) { | ||
this.script = script | ||
} | ||
|
||
abstract String create(Map helmConfig, String application, String namespace, String mergedValuesFile) | ||
|
||
String fileToInlineYaml(String fileContents) { | ||
String values = "" | ||
String indent = " " | ||
String fileContent = script.readFile fileContents | ||
fileContent.split("\n").each { line -> | ||
if(line.size() > 0) { | ||
values += indent + line + "\n" | ||
} else { | ||
values += line + "\n" | ||
} | ||
} | ||
// remove unnecessary last blank line | ||
return values.substring(0, values.lastIndexOf('\n')) | ||
} | ||
} |
Oops, something went wrong.