From e2fa03fb7ba1d65ddf1c83b3ea856b754afbcec6 Mon Sep 17 00:00:00 2001
From: Ayumu Ueha <ueha.ayumu@fujitsu.com>
Date: Tue, 7 Dec 2021 10:03:01 +0000
Subject: [PATCH] Set default namespace when caling k8s scale API

The error is occur on calling read/patch_xxx_scale API of kubernetes
python client when using manifest that has no namespace in Helm chart.
This patch fixes this problem by setting namespace to "default" if it
is an empty string or None.

Closes-Bug: #1953477
Change-Id: I5f5bc38c023bbe7674c7513e4a0609c217936595
---
 tacker/vnfm/infra_drivers/kubernetes/kubernetes_driver.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tacker/vnfm/infra_drivers/kubernetes/kubernetes_driver.py b/tacker/vnfm/infra_drivers/kubernetes/kubernetes_driver.py
index aa055edbc..844f409b8 100644
--- a/tacker/vnfm/infra_drivers/kubernetes/kubernetes_driver.py
+++ b/tacker/vnfm/infra_drivers/kubernetes/kubernetes_driver.py
@@ -1229,6 +1229,8 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
                         if name == vdu_properties.get('name'):
                             namespace = vnf_resource.resource_name.\
                                 split(COMMA_CHARACTER)[0]
+                            if not namespace:
+                                namespace = "default"
                             kind = vnf_resource.resource_type.\
                                 split(COMMA_CHARACTER)[1]
                             if kind in target_kinds:
@@ -1384,6 +1386,8 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
                         if name == vdu_properties.get('name'):
                             namespace = vnf_resource.resource_name.\
                                 split(COMMA_CHARACTER)[0]
+                            if not namespace:
+                                namespace = "default"
                             kind = vnf_resource.resource_type.\
                                 split(COMMA_CHARACTER)[1]
                             if kind in target_kinds:
@@ -2128,6 +2132,8 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
                     vnfc_resource.metadata.get(info['kind']))
                 info['name'] = rsc_metadata.get('name')
                 info['namespace'] = rsc_metadata.get('namespace')
+                if not info['namespace']:
+                    info['namespace'] = "default"
                 k8s_resources.append(info)
             # exclude duplicate entries
             k8s_resources = list(map(jsonutils.loads,