Fixed bug when k8s profile is created for default k8s version 96/119696/1
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Wed, 24 Mar 2021 18:01:34 +0000 (19:01 +0100)
committerLukasz Rajewski <lukasz.rajewski@orange.com>
Wed, 24 Mar 2021 23:41:58 +0000 (23:41 +0000)
Fixed bug when k8s profile is created for default k8s version

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

components/model-catalog/definition-type/starter-type/node_type/component-k8s-profile-upload.json
components/model-catalog/resource-dictionary/starter-dictionary/k8s-rb-profile-k8s-version.json [new file with mode: 0644]
ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/profile/K8sProfile.kt
ms/blueprintsprocessor/functions/k8s-connection-plugin/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/definition/profile/K8sProfileUploadComponent.kt

index d7b4bb9..f98fd4e 100644 (file)
                 "required": false,
                 "type": "string"
             },
+            "k8s-rb-profile-k8s-version": {
+              "description": "a K8s cluster version for the profile",
+              "required": false,
+              "type": "string"
+            },
             "k8s-rb-profile-source": {
                 "description": "Source (tgz/folder) for the template in CBA",
                 "required": false,
diff --git a/components/model-catalog/resource-dictionary/starter-dictionary/k8s-rb-profile-k8s-version.json b/components/model-catalog/resource-dictionary/starter-dictionary/k8s-rb-profile-k8s-version.json
new file mode 100644 (file)
index 0000000..2b8eef5
--- /dev/null
@@ -0,0 +1,39 @@
+{
+    "tags": "k8s, cnf, profile, k8s version, k8s-rb-profile-k8s-version",
+    "name": "k8s-rb-profile-k8s-version",
+    "property": {
+        "description": "Profile k8s version used in multicloud/k8s plugin",
+        "type": "string"
+    },
+    "group": "default",
+    "updated-by": "Rajewski, Lukasz <lukasz.rajewski@orange.com>",
+    "sources": {
+        "input": {
+            "type": "source-input"
+        },
+        "default": {
+            "type": "source-default",
+            "properties": {}
+        },
+        "sdnc": {
+            "type": "source-rest",
+            "properties": {
+                "verb": "GET",
+                "type": "JSON",
+                "url-path": "/restconf/config/GENERIC-RESOURCE-API:services/service/$service-instance-id/service-data/vnfs/vnf/$vnf-id/vnf-data/vnf-topology/vnf-parameters-data/param/k8s-rb-profile-k8s-version",
+                "path": "/param/0/value",
+                "input-key-mapping": {
+                    "service-instance-id": "service-instance-id",
+                    "vnf-id": "vnf-id"
+                },
+                "output-key-mapping": {
+                    "k8s-rb-profile-k8s-version": "value"
+                },
+                "key-dependencies": [
+                    "service-instance-id",
+                    "vnf-id"
+                ]
+            }
+        }
+    }
+}
index 201895c..5e853d0 100644 (file)
@@ -65,6 +65,7 @@ open class K8sProfileUploadComponent(
         const val INPUT_K8S_DEFINITION_NAME = "k8s-rb-definition-name"
         const val INPUT_K8S_DEFINITION_VERSION = "k8s-rb-definition-version"
         const val INPUT_K8S_PROFILE_NAMESPACE = "k8s-rb-profile-namespace"
+        const val INPUT_K8S_PROFILE_K8S_VERSION = "k8s-rb-profile-k8s-version"
         const val INPUT_K8S_PROFILE_SOURCE = "k8s-rb-profile-source"
         const val INPUT_RESOURCE_ASSIGNMENT_MAP = "resource-assignment-map"
         const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
@@ -85,6 +86,7 @@ open class K8sProfileUploadComponent(
             INPUT_K8S_DEFINITION_NAME,
             INPUT_K8S_DEFINITION_VERSION,
             INPUT_K8S_PROFILE_NAMESPACE,
+            INPUT_K8S_PROFILE_K8S_VERSION,
             INPUT_K8S_PROFILE_SOURCE,
             INPUT_ARTIFACT_PREFIX_NAMES
         )
@@ -130,7 +132,7 @@ open class K8sProfileUploadComponent(
             if ((profileName == null) || (definitionName == null) || (definitionVersion == null)) {
                 log.warn("Prefix $prefix does not have required data for us to continue.")
             } else if (!api.hasDefinition(definitionName, definitionVersion)) {
-                log.warn("K8s RB Definition ($definitionName/$definitionVersion) not found ")
+                throw BlueprintProcessorException("K8s RB Definition ($definitionName/$definitionVersion) not found ")
             } else if (profileName == "") {
                 log.warn("K8s rb profile name is empty! Either define profile name to use or choose default")
             } else if (api.hasProfile(definitionName, definitionVersion, profileName)) {
@@ -139,6 +141,7 @@ open class K8sProfileUploadComponent(
                 log.info("Uploading K8s Profile..")
                 outputPrefixStatuses.put(prefix, OUTPUT_ERROR)
                 val profileNamespace: String? = prefixInputParamsMap[INPUT_K8S_PROFILE_NAMESPACE]?.returnNullIfMissing()?.asText()
+                val profileK8sVersion: String? = prefixInputParamsMap[INPUT_K8S_PROFILE_K8S_VERSION]?.returnNullIfMissing()?.asText()
                 var profileSource: String? = prefixInputParamsMap[INPUT_K8S_PROFILE_SOURCE]?.returnNullIfMissing()?.asText()
                 if (profileNamespace == null)
                     throw BlueprintProcessorException("Profile $profileName namespace is missing")
@@ -158,6 +161,8 @@ open class K8sProfileUploadComponent(
                 profile.rbName = definitionName
                 profile.rbVersion = definitionVersion
                 profile.namespace = profileNamespace
+                if (profileK8sVersion != null)
+                    profile.kubernetesVersion = profileK8sVersion
                 val profileFilePath: Path = prepareProfileFile(profileName, profileSource, artifact.file)
                 api.createProfile(definitionName, definitionVersion, profile)
                 api.uploadProfileContent(definitionName, definitionVersion, profile, profileFilePath)