2 * # ============LICENSE_START=======================================================
3 * # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
4 * # ================================================================================
5 * # Licensed under the Apache License, Version 2.0 (the "License");
6 * # you may not use this file except in compliance with the License.
7 * # You may obtain a copy of the License at
9 * # http://www.apache.org/licenses/LICENSE-2.0
11 * # Unless required by applicable law or agreed to in writing, software
12 * # distributed under the License is distributed on an "AS IS" BASIS,
13 * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * # See the License for the specific language governing permissions and
15 * # limitations under the License.
16 * # ============LICENSE_END=========================================================
19 package org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder;
21 import lombok.extern.slf4j.Slf4j;
22 import org.onap.dcaegen2.platform.helmchartgenerator.Utils;
23 import org.onap.dcaegen2.platform.helmchartgenerator.models.chartinfo.ChartInfo;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Component;
30 * ChartGenerator interacts with HelmClient and generates a packaged helm chart
31 * @author Dhrumin Desai
35 public class ChartGenerator {
38 private HelmClient helmClient;
41 private KeyValueMerger merger;
47 private AddOnsManager addOnsManager;
50 * Constructor for ChartGenerator
51 * @param helmClient HelmClient implementation
52 * @param merger KeyValueMerger implementation
54 * @param addOnsManager
56 public ChartGenerator(HelmClient helmClient, KeyValueMerger merger, Utils utils, AddOnsManager addOnsManager) {
57 this.helmClient = helmClient;
60 this.addOnsManager = addOnsManager;
64 * Merges the key-values from the helm base template and parsed spec file and generates a new packaged helm chart
65 * @param chartBlueprintLocation location of the base helm chart template
66 * @param chartInfo chartInfo object with key-values parsed from the specfile.
67 * @param outputLocation location to store the helm chart
68 * @param specFileLocation
69 * @return generated helm chart tgz file
71 public File generate(String chartBlueprintLocation, ChartInfo chartInfo, String outputLocation, String specFileLocation) {
72 File newChartDir = utils.cloneFileToTempLocation(chartBlueprintLocation + "/base");
73 addOnsManager.includeAddons(specFileLocation, newChartDir, chartBlueprintLocation);
74 merger.mergeValuesToChart(chartInfo, newChartDir);
75 helmClient.lint(newChartDir);
76 final File chartLocation = helmClient.packageChart(newChartDir, outputLocation);
77 utils.deleteTempFileLocation(newChartDir);