From: garciadeblas Date: Wed, 8 Jun 2022 11:13:13 +0000 (+0200) Subject: Update create_execution_environment to pass the chart_model X-Git-Tag: release-v13.0-start~12 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=1d8aa81e353f6a9a1921d1efb0bd96b4719ec576;p=osm%2FLCM.git Update create_execution_environment to pass the chart_model The function create_execution_environment has been updated to allow the deployment from a file or from a reference (repo/name:version). This will call to the N2VC Helm connector to install the execution environment in the local environment. Change-Id: I03c8e95bf0f6a55d3f62bc7a55dabe3a9b348cde Signed-off-by: garciadeblas --- diff --git a/osm_lcm/lcm_helm_conn.py b/osm_lcm/lcm_helm_conn.py index 6fd3374..0c88abe 100644 --- a/osm_lcm/lcm_helm_conn.py +++ b/osm_lcm/lcm_helm_conn.py @@ -167,32 +167,41 @@ class LCMHelmConn(N2VCConnector, LcmBase): total_timeout: float = None, config: dict = None, artifact_path: str = None, + chart_model: str = None, vca_type: str = None, *kargs, **kwargs, ) -> (str, dict): """ Creates a new helm execution environment deploying the helm-chat indicated in the - attifact_path + artifact_path :param str namespace: This param is not used, all helm charts are deployed in the osm system namespace :param dict db_dict: where to write to database when the status changes. It contains a dictionary with {collection: str, filter: {}, path: str}, e.g. {collection: "nsrs", filter: {_id: , path: "_admin.deployed.VCA.3"} - :param str reuse_ee_id: ee id from an older execution. TODO - right now this params is not used + :param str reuse_ee_id: ee id from an older execution. TODO - right now this param is not used :param float progress_timeout: :param float total_timeout: :param dict config: General variables to instantiate KDU - :param str artifact_path: path of package content + :param str artifact_path: path of package content + :param str chart_model: helm chart/reference (string), which can be either + of these options: + - a name of chart available via the repos known by OSM + (e.g. stable/openldap, stable/openldap:1.2.4) + - a path to a packaged chart (e.g. mychart.tgz) + - a path to an unpacked chart directory or a URL (e.g. mychart) :param str vca_type: Type of vca, must be type helm or helm-v3 :returns str, dict: id of the new execution environment including namespace.helm_id and credentials object set to None as all credentials should be osm kubernetes .kubeconfig """ self.log.info( - "create_execution_environment: namespace: {}, artifact_path: {}, db_dict: {}, " - "reuse_ee_id: {}".format(namespace, artifact_path, db_dict, reuse_ee_id) + "create_execution_environment: namespace: {}, artifact_path: {}, " + "chart_model: {}, db_dict: {}, reuse_ee_id: {}".format( + namespace, artifact_path, db_dict, chart_model, reuse_ee_id + ) ) # Validate artifact-path is provided @@ -224,6 +233,13 @@ class LCMHelmConn(N2VCConnector, LcmBase): while full_path.find("//") >= 0: full_path = full_path.replace("//", "/") + # By default, the KDU is expected to be a file + kdu_model = full_path + # If the chart_model includes a "/", then it is a reference: + # e.g. (stable/openldap; stable/openldap:1.2.4) + if chart_model.find("/") >= 0: + kdu_model = chart_model + try: # Call helm conn install # Obtain system cluster id from database @@ -238,11 +254,11 @@ class LCMHelmConn(N2VCConnector, LcmBase): if vca_type == "helm": helm_id = self._k8sclusterhelm2.generate_kdu_instance_name( db_dict=db_dict, - kdu_model=full_path, + kdu_model=kdu_model, ) await self._k8sclusterhelm2.install( system_cluster_uuid, - kdu_model=full_path, + kdu_model=kdu_model, kdu_instance=helm_id, namespace=self._KUBECTL_OSM_NAMESPACE, params=config, @@ -252,11 +268,11 @@ class LCMHelmConn(N2VCConnector, LcmBase): else: helm_id = self._k8sclusterhelm2.generate_kdu_instance_name( db_dict=db_dict, - kdu_model=full_path, + kdu_model=kdu_model, ) await self._k8sclusterhelm3.install( system_cluster_uuid, - kdu_model=full_path, + kdu_model=kdu_model, kdu_instance=helm_id, namespace=self._KUBECTL_OSM_NAMESPACE, params=config, diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index d267065..a6ef52e 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -1905,6 +1905,7 @@ class NsLcm(LcmBase): db_dict=db_dict, config=osm_config, artifact_path=artifact_path, + chart_model=vca_name, vca_type=vca_type, ) else: @@ -2181,6 +2182,8 @@ class NsLcm(LcmBase): # STEP 7 Configure metrics if vca_type == "helm" or vca_type == "helm-v3": + # TODO: review for those cases where the helm chart is a reference and + # is not part of the NF package prometheus_jobs = await self.extract_prometheus_scrape_jobs( ee_id=ee_id, artifact_path=artifact_path, diff --git a/osm_lcm/tests/test_lcm_helm_conn.py b/osm_lcm/tests/test_lcm_helm_conn.py index 89ca891..7116517 100644 --- a/osm_lcm/tests/test_lcm_helm_conn.py +++ b/osm_lcm/tests/test_lcm_helm_conn.py @@ -63,6 +63,7 @@ class TestLcmHelmConn(asynctest.TestCase): namespace = "testnamespace" db_dict = {} artifact_path = "helm_sample_charm" + chart_model = "helm_sample_charm" helm_chart_id = "helm_sample_charm_0001" self.helm_conn._k8sclusterhelm3.install = asynctest.CoroutineMock( return_value=None @@ -78,7 +79,8 @@ class TestLcmHelmConn(asynctest.TestCase): self.db.get_one.return_value = {"_admin": {"helm-chart-v3": {"id": "myk8s_id"}}} ee_id, _ = await self.helm_conn.create_execution_environment( - namespace, db_dict, artifact_path=artifact_path, vca_type="helm-v3" + namespace, db_dict, artifact_path=artifact_path, + chart_model=chart_model, vca_type="helm-v3" ) self.assertEqual( ee_id,