K8sPlugin integration changes for Istanbul APIs 04/127104/1
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Mon, 14 Feb 2022 15:39:09 +0000 (16:39 +0100)
committerLukasz Rajewski <lukasz.rajewski@orange.com>
Mon, 14 Feb 2022 15:39:09 +0000 (16:39 +0100)
- k8sconfigteamplate component accepts empty source
  what means that template is the same like definition
- fix of the query API namespace param

Issue-ID: CCSDK-3537
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Change-Id: I86c6b7e0fd98cd34a1ee89dd183732b113439a23

ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/template/K8sConfigTemplateComponent.kt
ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/query/K8sPluginQueryApi.kt

index 9692777..cd58baf 100644 (file)
@@ -135,23 +135,27 @@ open class K8sConfigTemplateComponent(
                 log.info("Uploading K8s template..")
                 outputPrefixStatuses[prefix] = OUTPUT_ERROR
                 var templateSource: String? = prefixInputParamsMap[INPUT_K8S_TEMPLATE_SOURCE]?.returnNullIfMissing()?.asText()
-                if (templateSource == null) {
-                    templateSource = templateName
-                    log.info("Template name used instead of template source")
+
+                var templateFilePath: Path? = null
+                if (templateSource != null && templateSource != "") {
+                    val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+                    val artifact: ArtifactDefinition = bluePrintContext.nodeTemplateArtifact(nodeTemplateName, templateSource)
+                    if (artifact.type != BluePrintConstants.MODEL_TYPE_ARTIFACT_K8S_CONFIG)
+                        throw BluePrintProcessorException(
+                            "Unexpected template artifact type for template source $templateSource. Expecting: $artifact.type"
+                        )
+                    templateFilePath = prepareTemplateFile(templateName, templateSource, artifact.file)
+                } else {
+                    templateSource = ""
+                    log.info("Configuration template without content. RB definition content will be used instead")
                 }
-                val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
-                val artifact: ArtifactDefinition = bluePrintContext.nodeTemplateArtifact(nodeTemplateName, templateSource)
-                if (artifact.type != BluePrintConstants.MODEL_TYPE_ARTIFACT_K8S_CONFIG)
-                    throw BluePrintProcessorException(
-                        "Unexpected template artifact type for template source $templateSource. Expecting: $artifact.type"
-                    )
                 val template = K8sTemplate()
                 template.templateName = templateName
                 template.description = templateSource
 
-                val templateFilePath: Path = prepareTemplateFile(templateName, templateSource, artifact.file)
                 api.createTemplate(definitionName, definitionVersion, template)
-                api.uploadConfigTemplateContent(definitionName, definitionVersion, template, templateFilePath)
+                if (templateFilePath != null)
+                    api.uploadConfigTemplateContent(definitionName, definitionVersion, template, templateFilePath)
 
                 log.info("K8s Config Upload Completed")
                 outputPrefixStatuses[prefix] = OUTPUT_UPLOADED
index 170f295..9a5051f 100644 (file)
@@ -26,7 +26,7 @@ public class K8sPluginQueryApi(
             if (name != null)
                 path = path.plus("&Name=$name")
             if (namespace != null)
-                path = path.plus("&Namespace=$name")
+                path = path.plus("&Namespace=$namespace")
             if (labels != null && labels.isNotEmpty()) {
                 path = path.plus("&Labels=")
                 for ((name, value) in labels)