updated dependencies to 9.x-0 and added ServiceAccount.nameOverride substitution...
[dcaegen2/platform.git] / mod2 / helm-generator / helmchartgenerator-core / src / main / java / org / onap / dcaegen2 / platform / helmchartgenerator / chartbuilder / KeyValueMerger.java
index 8a28871..fe6ff32 100644 (file)
@@ -78,6 +78,7 @@ public class KeyValueMerger {
         Map<String, Object> valuesYamlKv;
         try {
             valuesYamlKv = yaml.load(new FileInputStream(valuesYamlFilePath));
+            changeNameOverrideUnderServiceAccount(valuesYamlKv, chartInfo);
             valuesYamlKv.putAll(chartInfo.getValues());
             yaml.dump(valuesYamlKv, new PrintWriter(valuesYamlFilePath));
         } catch (FileNotFoundException e) {
@@ -85,6 +86,18 @@ public class KeyValueMerger {
         }
     }
 
+    private void changeNameOverrideUnderServiceAccount(Map<String, Object> valuesYamlKv, ChartInfo chartInfo) {
+        if(valuesYamlKv.containsKey("serviceAccount")){
+            Map<String,Object> serviceAccount = (Map<String, Object>) valuesYamlKv.get("serviceAccount");
+            if(serviceAccount.containsKey("nameOverride")){
+                serviceAccount.put("nameOverride", chartInfo.getMetadata().getName());
+            }
+        }
+        else{
+            log.warn("No serviceAccount section found in the values.yaml file. Skipping nameOverride substitution.");
+        }
+    }
+
     private void checkIfFIleExists(String filePath, String message) {
         File valuesYaml = new File(filePath);
         if (!valuesYaml.exists()) {