+ log.debug("Dashboard already exists")
+
+ # Read existing k8s cluster list and creates a dashboard for each
+ k8sclusters = self.common_db.get_k8sclusters()
+ for k8scluster in k8sclusters:
+ k8scluster_id = k8scluster["_id"]
+ k8scluster_name = k8scluster["name"]
+ osm_resource_uids.append(k8scluster_id)
+ osm_datasource_names.append(
+ "{}-{}".format(datasource_name_substr, k8scluster_name)
+ )
+ if k8scluster_id not in dashboard_uids:
+ projects_read = k8scluster["_admin"]["projects_read"]
+ if len(projects_read) and projects_read[0] == project_id:
+ # Collect K8S Cluster IDs for periodical dashboard clean-up
+ k8scluster_address = k8scluster["credentials"]["clusters"][0][
+ "cluster"
+ ]["server"]
+ # Extract K8S Cluster ip from url
+ k8scluster_ip = re.findall(
+ r"://([\w\-\.]+)", k8scluster_address
+ )[0]
+
+ # prometheus-operator url
+ datasource_url = "http://{}:{}".format(
+ k8scluster_ip, prom_operator_port
+ )
+
+ # Create datsource for prometheus-operator in grafana
+ datasource_type = "prometheus"
+ datasource_name = "{}-{}".format(
+ datasource_name_substr, k8scluster_name
+ )
+ if datasource_name not in datasource_names:
+ self.grafana.create_datasource(
+ datasource_name, datasource_type, datasource_url
+ )
+ log.debug(
+ "Created datasource for k8scluster: %s", k8scluster_id
+ )
+
+ if project["name"] != "admin":
+ self.grafana.create_dashboard(
+ k8scluster_id,
+ k8scluster_name,
+ cnf_dashboard_path,
+ project_name=project["name"],
+ datasource_name=datasource_name,
+ )
+ else:
+ self.grafana.create_dashboard(
+ k8scluster_id,
+ k8scluster_name,
+ cnf_dashboard_path,
+ datasource_name=datasource_name,
+ )
+ log.debug("Created dashboard for k8scluster: %s", k8scluster_id)
+ else:
+ log.debug(
+ "Dashboard already exist for k8scluster: %s", k8scluster_id
+ )