- db_k8cluster = self.db.get_one("k8sclusters", {"name": self._KUBECTL_OSM_CLUSTER_NAME})
- k8s_hc_id = deep_get(db_k8cluster, ("_admin", "helm-chart", "id"))
+ db_k8cluster = self.db.get_one(
+ "k8sclusters", {"name": self._KUBECTL_OSM_CLUSTER_NAME}
+ )
+ k8s_hc_id = deep_get(db_k8cluster, ("_admin", "helm-chart-v3", "id"))
+ if not k8s_hc_id:
+ try:
+ # backward compatibility for existing clusters that have not been initialized for helm v3
+ cluster_id = db_k8cluster.get("_id")
+ k8s_credentials = yaml.safe_dump(db_k8cluster.get("credentials"))
+ k8s_hc_id, uninstall_sw = await self._k8sclusterhelm3.init_env(
+ k8s_credentials, reuse_cluster_uuid=cluster_id
+ )
+ db_k8scluster_update = {
+ "_admin.helm-chart-v3.error_msg": None,
+ "_admin.helm-chart-v3.id": k8s_hc_id,
+ "_admin.helm-chart-v3}.created": uninstall_sw,
+ "_admin.helm-chart-v3.operationalState": "ENABLED",
+ }
+ self.update_db_2("k8sclusters", cluster_id, db_k8scluster_update)
+ except Exception as e:
+ self.log.error(
+ "error initializing helm-v3 cluster: {}".format(str(e))
+ )
+ raise N2VCException(
+ "K8s system cluster '{}' has not been initialized for helm-chart-v3".format(
+ cluster_id
+ )
+ )