diff options
author | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2020-02-28 15:24:52 +0100 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2020-03-03 11:20:41 +0100 |
commit | 7d44d14b86dd4858afadb55c9ca38a4251e13dac (patch) | |
tree | 98400bf1750b9090f7bcb3bb9b4c53197d241625 /heat/vFW_CNF_CDS/templates/cba/Scripts | |
parent | 39fd16c1871136565aa464d097aa9e21856a1dfb (diff) |
K8s Profile mod on demand
This change provides an example of
modificatioin of k8s profile on demand.
In here the ssh service of vPGN is
created on demand and user can decide
about the number of ssh exposed port
Change-Id: Ie734e4f832d6a07ff53a0f108aed74a43d325b22
Issue-ID: INT-1458
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Diffstat (limited to 'heat/vFW_CNF_CDS/templates/cba/Scripts')
-rw-r--r-- | heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt index 22e4b33a..d47b476a 100644 --- a/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt +++ b/heat/vFW_CNF_CDS/templates/cba/Scripts/kotlin/KotlinK8sProfileUpload.kt @@ -42,6 +42,7 @@ import org.springframework.web.client.RestTemplate import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty import java.util.ArrayList +import java.util.LinkedHashMap import java.io.IOException import java.io.File import java.nio.file.Files @@ -52,6 +53,7 @@ import org.springframework.http.MediaType import java.nio.charset.Charset import java.util.Base64 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.yaml.snakeyaml.Yaml open class K8sProfileUpload : AbstractScriptComponentFunction() { @@ -102,7 +104,7 @@ open class K8sProfileUpload : AbstractScriptComponentFunction() { if (api.hasProfile(k8sRbProfileName)) { log.info("Profile Already Existing - skipping upload") } else { - val profileFilePath: Path = prepareProfileFile(k8sRbProfileName) + val profileFilePath: Path = prepareProfileFile(k8sRbProfileName, prefix.equals("vpkg")) var profile = K8sProfile() profile.profileName = k8sRbProfileName @@ -118,7 +120,7 @@ open class K8sProfileUpload : AbstractScriptComponentFunction() { } } - fun prepareProfileFile(k8sRbProfileName: String): Path { + fun prepareProfileFile(k8sRbProfileName: String, profileModificationAllowed: Boolean): Path { val bluePrintContext = bluePrintRuntimeService.bluePrintContext() val bluePrintBasePath: String = bluePrintContext.rootPath var profileFilePath: Path = Paths.get(bluePrintBasePath.plus(File.separator).plus("Templates").plus(File.separator).plus("k8s-profiles").plus(File.separator).plus("${k8sRbProfileName}.tar.gz")) @@ -138,7 +140,40 @@ open class K8sProfileUpload : AbstractScriptComponentFunction() { log.info("${profileFilePath.toString()} decompression completed") - //Here we can add extra files inside the archive + if (profileModificationAllowed) { + //Here we can add extra files inside the archive + val profileModificationDecisionData = getDynamicProperties("profile-modification-decision-data") + log.info("Profile modification decision data: ${profileModificationDecisionData}") + if (profileModificationDecisionData != null && profileModificationDecisionData.asText().toInt() > 0) { + log.info("Modification of profile content") + + val profileArtifacts = getDynamicProperties("profile-artifacts") + val sshServiceFileContent = profileArtifacts.get("ssh-service").asText() + val sshServiceFileName = "ssh-service.yaml" + val serviceFilePath = tempProfilePath.toString().plus(File.separator).plus(sshServiceFileName) + File(serviceFilePath).bufferedWriter().use { out -> out.write(sshServiceFileContent) } + val manifestFileName = tempProfilePath.toString().plus(File.separator).plus("manifest.yaml") + var finalManifest = "" + File(manifestFileName).bufferedReader().use { inr -> + val manifestYaml = Yaml() + val manifestObject: Map<String, Any> = manifestYaml.load(inr) + val typeObject: MutableMap<String, Any> = manifestObject.get("type") as MutableMap<String, Any> + if (!typeObject.containsKey("configresource")) + typeObject.put("configresource", ArrayList<LinkedHashMap<String, Any>>()) + val configFiles: MutableList<LinkedHashMap<String, Any>> = typeObject.get("configresource") as MutableList<LinkedHashMap<String, Any>> + val sshConfigFile = LinkedHashMap<String, Any>() + sshConfigFile.put("filepath", sshServiceFileName) + sshConfigFile.put("chartpath", "vpkg/templates/${sshServiceFileName}") + configFiles.add(sshConfigFile) + finalManifest = manifestYaml.dump(manifestObject) + } + File(manifestFileName).bufferedWriter().use { out -> out.write(finalManifest) } + log.info("Modified K8s profile manifest file") + log.info(finalManifest) + log.info("Modification of profile completed") + } + } + profileFilePath = Paths.get(tempMainPath.toString().plus(File.separator).plus("${k8sRbProfileName}.tar.gz")) if (!BluePrintArchiveUtils.compress(decompressedProfile, profileFilePath.toFile(), |