self.log.debug("Returning kdu_instance {}".format(kdu_instance))
return True
+ async def migrate(self, nsr_id, target):
+ db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
+
+ # check if it has k8s deployed kdus
+ if len(db_nsr["_admin"]["deployed"]["K8s"]) < 1:
+ err_msg = "INFO: No deployed KDUs"
+ self.log.error(err_msg)
+ raise K8sException(err_msg)
+
+ kdu_id = target["vdu"]["vduId"]
+ for index, kdu in enumerate(db_nsr["_admin"]["deployed"]["K8s"]):
+ if kdu["kdu-instance"] == kdu_id:
+ namespace = kdu["namespace"]
+ cluster_uuid = kdu["k8scluster-uuid"]
+ kdu_model = kdu["kdu-model"]
+ db_dict = {
+ "collection": "nsrs",
+ "filter": {"_id": nsr_id},
+ "path": "_admin.deployed.K8s.{}".format(index),
+ }
+
+ await self.upgrade(
+ cluster_uuid,
+ kdu_instance=kdu_id,
+ kdu_model=kdu_model,
+ namespace=namespace,
+ targetHostK8sLabels=target["targetHostK8sLabels"],
+ atomic=True,
+ db_dict=db_dict,
+ force=True,
+ )
+
+ return True
+
+ self.log.debug("ERROR: Unable to retrieve kdu from the database")
+
async def inspect_kdu(self, kdu_model: str, repo_url: str = None) -> str:
self.log.debug(
"inspect kdu_model {} from (optional) repo: {}".format(kdu_model, repo_url)
atomic: bool,
timeout: float,
kubeconfig: str,
+ targetHostK8sLabels: dict = None,
reset_values: bool = False,
reuse_values: bool = True,
reset_then_reuse_values: bool = False,
)
)
+ # migration
+ if targetHostK8sLabels and self.nodeSelector_post_renderer_path:
+ post_renderer_args.append(
+ "{}={}".format(
+ self.nodeSelector_post_renderer_path,
+ " ".join(
+ [
+ "{}:{}".format(key, value)
+ for key, value in targetHostK8sLabels.items()
+ ]
+ ),
+ )
+ )
+
if len(post_renderer_args) > 0 and self.main_post_renderer_path:
post_renderer_str = "--post-renderer {}".format(
self.main_post_renderer_path,
filename=self.podLabels_post_renderer_path, exception_if_not_exists=True
)
+ # exception if nodeSelector post renderer executable is not present
+ self.nodeSelector_post_renderer_path = EnvironConfig(prefixes=["OSMLCM_"]).get(
+ "nodeselectorpostrendererpath"
+ )
+ if self.nodeSelector_post_renderer_path:
+ self._check_file_exists(
+ filename=self.nodeSelector_post_renderer_path,
+ exception_if_not_exists=True,
+ )
+
# obtain stable repo url from config or apply default
self._stable_repo_url = self.config.get("stablerepourl")
if self._stable_repo_url == "None":
params: dict = None,
db_dict: dict = None,
namespace: str = None,
+ targetHostK8sLabels: dict = None,
reset_values: bool = False,
reuse_values: bool = True,
reset_then_reuse_values: bool = False,
atomic,
timeout,
paths["kube_config"],
+ targetHostK8sLabels,
reset_values,
reuse_values,
reset_then_reuse_values,
atomic,
timeout,
kubeconfig,
+ targetHostK8sLabels,
reset_values,
reuse_values,
reset_then_reuse_values,
--- /dev/null
+#!/bin/bash
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+# Default values for osm.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+resources:
+- all.yaml
+patches:
+- path: nodeSelector-deployment-patch.yaml
+ target:
+ kind: Deployment
\ No newline at end of file
--- /dev/null
+#!/bin/bash
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+# Default values for osm.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+
+dirname="nodeSelector-"$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13)
+
+mkdir /tmp/$dirname && cd /tmp/$dirname
+
+cp /usr/lib/python3/dist-packages/n2vc/post-renderer-scripts/nodeSelector/kustomization.yaml .
+
+cp /usr/lib/python3/dist-packages/n2vc/post-renderer-scripts/nodeSelector/nodeSelector-deployment-patch.yaml .
+
+cat <&0 > all.yaml
+
+IFS=' ' read -r -a labels <<< "$1"
+content=""
+for label in "${labels[@]}"; do
+ key=$(echo "$label" | cut -d':' -f1)
+ value=$(echo "$label" | cut -d':' -f2)
+ content="$content
+ $key: $value"
+done
+
+echo -e "$content" >> nodeSelector-deployment-patch.yaml
+
+kubectl kustomize && cd .. && rm -r /tmp/$dirname
\ No newline at end of file
--- /dev/null
+#!/bin/bash
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+# Default values for osm.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+
+apiVersion: v1
+kind: Deployment
+metadata:
+ name: nodeSelectors-deployment
+spec:
+ template:
+ spec:
+ nodeSelector:
\ No newline at end of file