@@ -5,26 +5,19 @@ import com.cloudogu.gitopsbuildlib.deployment.SourceType
55import com.cloudogu.gitopsbuildlib.deployment.helm.helmrelease.ArgoCDRelease
66import com.cloudogu.gitopsbuildlib.deployment.helm.helmrelease.FluxV1Release
77import com.cloudogu.gitopsbuildlib.deployment.helm.helmrelease.HelmRelease
8- import com.cloudogu.gitopsbuildlib.deployment.helm.repotype.GitRepo
9- import com.cloudogu.gitopsbuildlib.deployment.helm.repotype.HelmRepo
108import com.cloudogu.gitopsbuildlib.deployment.helm.repotype.RepoType
119
1210class Helm extends Deployment {
1311
14- protected RepoType chartRepo
1512 protected HelmRelease helmRelease
1613
17- private String helmChartTempDir = " .helmChartTempDir"
18- private String chartRootDir = " chart"
14+ public static final String HELM_CHART_TEMP_DIR = " .helmChartTempDir"
15+ public static final String CHART_ROOT_DIR = " chart"
1916
2017 Helm (def script , def gitopsConfig ) {
2118 super (script, gitopsConfig)
2219 this . extraResourcesFolder = " extraResources"
23- if (gitopsConfig. deployments. helm. repoType == ' GIT' ) {
24- chartRepo = new GitRepo (script)
25- } else if (gitopsConfig. deployments. helm. repoType == ' HELM' ) {
26- chartRepo = new HelmRepo (script)
27- }
20+
2821 if (gitopsConfig. gitopsTool == ' FLUX' ) {
2922 helmRelease = new FluxV1Release (script)
3023 } else if (gitopsConfig. gitopsTool == ' ARGO' ) {
@@ -37,7 +30,8 @@ class Helm extends Deployment {
3730 def sourcePath = gitopsConfig. deployments. sourcePath
3831 def destinationPath = getDestinationFolder(getFolderStructureStrategy(), stage)
3932
40- chartRepo. prepareRepo(gitopsConfig, helmChartTempDir, chartRootDir)
33+ RepoType repoType = RepoType . create(gitopsConfig. deployments. helm. repoType, script)
34+ repoType. prepareRepo(gitopsConfig, HELM_CHART_TEMP_DIR , CHART_ROOT_DIR )
4135
4236 // writing the merged-values.yaml via writeYaml into a file has the advantage, that it gets formatted as valid yaml
4337 // This makes it easier to read in and indent for the inline use in the helmRelease.
@@ -48,17 +42,17 @@ class Helm extends Deployment {
4842 if (script. fileExists(" ${ script.env.WORKSPACE} /${ sourcePath} /values-shared.yaml" )) {
4943 valueFiles. add(" ${ script.env.WORKSPACE} /${ sourcePath} /values-shared.yaml" )
5044 }
51- script. writeFile file : " ${ script.env.WORKSPACE} /${ helmChartTempDir } /mergedValues.yaml" , text : mergeValuesFiles(gitopsConfig, valueFiles as String [])
45+ script. writeFile file : " ${ script.env.WORKSPACE} /${ HELM_CHART_TEMP_DIR } /mergedValues.yaml" , text : mergeValuesFiles(gitopsConfig, valueFiles as String [], repoType )
5246
53- updateYamlValue(" ${ script.env.WORKSPACE} /${ helmChartTempDir } /mergedValues.yaml" , gitopsConfig)
47+ updateYamlValue(" ${ script.env.WORKSPACE} /${ HELM_CHART_TEMP_DIR } /mergedValues.yaml" , gitopsConfig)
5448
55- script. writeFile file : " ${ destinationPath} /applicationRelease.yaml" , text : helmRelease. create(gitopsConfig, getNamespace(stage), " ${ script.env.WORKSPACE} /${ helmChartTempDir } /mergedValues.yaml" )
49+ script. writeFile file : " ${ destinationPath} /applicationRelease.yaml" , text : helmRelease. create(gitopsConfig, getNamespace(stage), " ${ script.env.WORKSPACE} /${ HELM_CHART_TEMP_DIR } /mergedValues.yaml" )
5650 }
5751
5852 @Override
5953 def postValidation (String stage ) {
6054 // clean the helm chart folder since the validation on this helm chart is done
61- script. sh " rm -rf ${ script.env.WORKSPACE} /${ helmChartTempDir } || true"
55+ script. sh " rm -rf ${ script.env.WORKSPACE} /${ HELM_CHART_TEMP_DIR } || true"
6256 }
6357
6458 @Override
@@ -67,7 +61,7 @@ class Helm extends Deployment {
6761
6862 gitopsConfig. validators. each { validator ->
6963 validator. value. validator. validate(validator. value. enabled, getGitopsTool(), SourceType . PLAIN , " ${ destinationPath} " , validator. value. config, gitopsConfig)
70- validator. value. validator. validate(validator. value. enabled, getGitopsTool(), SourceType . HELM , " ${ script.env.WORKSPACE} /${ helmChartTempDir } " ,validator. value. config, gitopsConfig)
64+ validator. value. validator. validate(validator. value. enabled, getGitopsTool(), SourceType . HELM , " ${ script.env.WORKSPACE} /${ HELM_CHART_TEMP_DIR } " ,validator. value. config, gitopsConfig)
7165 }
7266 }
7367
@@ -89,20 +83,14 @@ class Helm extends Deployment {
8983 script. writeYaml file : yamlFilePath, data : data, overwrite : true
9084 }
9185
92- private String mergeValuesFiles (Map gitopsConfig , String [] valuesFiles ) {
93- def helmConfig = gitopsConfig. deployments. helm
86+ private String mergeValuesFiles (Map gitopsConfig , String [] valuesFiles , RepoType repoType ) {
9487
9588 String mergedValuesFile = " "
9689
97- def chartDir = ' '
98- if (helmConfig. containsKey(' chartPath' ) && helmConfig. chartPath) {
99- chartDir = helmConfig. chartPath
100- } else if ( helmConfig. containsKey(' chartName' )) {
101- chartDir = helmConfig. chartName
102- }
90+ def chartPath = repoType. getChartPath(gitopsConfig, HELM_CHART_TEMP_DIR , CHART_ROOT_DIR )
10391
10492 withDockerImage(gitopsConfig. buildImages. helm) {
105- String helmScript = " helm values ${ script.env.WORKSPACE } / ${ helmChartTempDir } / ${ chartRootDir } / ${ chartDir } ${ valuesFilesWithParameter(valuesFiles)} "
93+ String helmScript = " helm values ${ chartPath } ${ valuesFilesWithParameter(valuesFiles)} "
10694 mergedValuesFile = script. sh returnStdout : true , script : helmScript
10795 }
10896 return mergedValuesFile
0 commit comments