diff --git a/bcs-app/backend/apps/metric/views/performance.py b/bcs-app/backend/apps/metric/views/performance.py index fe5e4b209..69ad5b909 100644 --- a/bcs-app/backend/apps/metric/views/performance.py +++ b/bcs-app/backend/apps/metric/views/performance.py @@ -75,12 +75,21 @@ def overview(self, request, project_id, cluster_id): memory_usage = prometheus.get_node_memory_usage(cluster_id, ip) disk_usage = prometheus.get_node_disk_usage(cluster_id, ip) diskio_usage = prometheus.get_node_diskio_usage(cluster_id, ip) + container_pod_count = prometheus.get_container_pod_count(cluster_id, ip) + data = { "cpu_usage": cpu_usage, "memory_usage": memory_usage, "disk_usage": disk_usage, "diskio_usage": diskio_usage, + "container_count": "0", + "pod_count": "0", } + + for count in container_pod_count.get("result") or []: + for k, v in count["metric"].items(): + if k == "metric_name" and count["value"]: + data[v] = count["value"][1] return response.Response(data) def info(self, request, project_id, cluster_id): diff --git a/bcs-app/backend/apps/metric/views/servicemonitor.py b/bcs-app/backend/apps/metric/views/servicemonitor.py index d93fa7c02..5f072239f 100644 --- a/bcs-app/backend/apps/metric/views/servicemonitor.py +++ b/bcs-app/backend/apps/metric/views/servicemonitor.py @@ -113,7 +113,7 @@ def _handle_items(self, cluster_id, cluster_map, namespace_map, manifest): item["metadata"] = {k: v for k, v in item["metadata"].items() if k not in FILTERED_METADATA} item["cluster_id"] = cluster_id item["namespace"] = item["metadata"]["namespace"] - item["namespace_id"] = namespace_map.get(item["metadata"]["namespace"]) + item["namespace_id"] = namespace_map.get((cluster_id, item["metadata"]["namespace"])) item["name"] = item["metadata"]["name"] item["instance_id"] = f"{item['namespace']}/{item['name']}" item["service_name"] = labels.get(self.SERVICE_NAME_LABEL) @@ -145,7 +145,7 @@ def filter_no_perm(self, data): def _validate_namespace_use_perm(self, request, project_id, namespace_list): """检查是否有命名空间的使用权限 """ - namespace_map = self._get_cluster_map(project_id) + namespace_map = self._get_namespace_map(project_id) for namespace in namespace_list: if namespace in self.NO_PERM_NS: raise error_codes.APIError(_("namespace operation is not allowed")) @@ -180,12 +180,12 @@ def _get_namespace_map(self, project_id): """ resp = paas_cc.get_namespace_list(self.request.user.token.access_token, project_id, limit=ALL_LIMIT) namespace_list = resp.get("data", {}).get("results") or [] - namespace_map = {i["name"]: i["id"] for i in namespace_list} + namespace_map = {(i["cluster_id"], i["name"]): i["id"] for i in namespace_list} return namespace_map def list(self, request, project_id, cluster_id): cluster_map = self._get_cluster_map(project_id) - namespace_map = self._get_cluster_map(project_id) + namespace_map = self._get_namespace_map(project_id) data = [] if cluster_id not in cluster_map: @@ -210,7 +210,7 @@ def create(self, request, project_id, cluster_id=None): if cluster_id is None: cluster_id = data["cluster_id"] - self._validate_namespace_use_perm(request, project_id, [data["namespace"]]) + self._validate_namespace_use_perm(request, project_id, [(cluster_id, data["namespace"])]) endpoints = [ { @@ -274,7 +274,7 @@ def get(self, request, project_id, cluster_id, namespace, name): def delete(self, request, project_id, cluster_id, namespace, name): """删除servicemonitor """ - self._validate_namespace_use_perm(request, project_id, [namespace]) + self._validate_namespace_use_perm(request, project_id, [(cluster_id, namespace)]) client = self._get_client(request, project_id, cluster_id) result = client.delete_service_monitor(namespace, name) if result.get("status") == "Failure": diff --git a/bcs-app/backend/bcs_k8s/helm/tasks.py b/bcs-app/backend/bcs_k8s/helm/tasks.py index aaf87d47c..349eb2a33 100644 --- a/bcs-app/backend/bcs_k8s/helm/tasks.py +++ b/bcs-app/backend/bcs_k8s/helm/tasks.py @@ -248,8 +248,6 @@ def _do_helm_repo_charts_update(repo, sign, charts, index_hash, force=False): continue else: chart_version = ChartVersion() - current_chart_version_ids.append(chart_version.id) - full_chart_versions[chart_version.id] = chart_version # 2.3 do update try: @@ -266,9 +264,13 @@ def _do_helm_repo_charts_update(repo, sign, charts, index_hash, force=False): icon_url = version.get("icon") if not chart.icon and icon_url: chart.update_icon(icon_url) + # 针对新创建的chart version,记录chart全量版本,便于后续针对版本的处理 + if not chart_version_id: + current_chart_version_ids.append(chart_version.id) + full_chart_versions[chart_version.id] = chart_version if chart_changed: - chart.changed_at = datetime.datetime.now() # update chart's updated_at whenever a chartversion changed + chart.changed_at = timezone.now() chart.save(update_fields=["changed_at"]) # 3. chartVersion sync delete diff --git a/bcs-app/backend/components/prometheus.py b/bcs-app/backend/components/prometheus.py index 4a4d1d153..567c75464 100644 --- a/bcs-app/backend/components/prometheus.py +++ b/bcs-app/backend/components/prometheus.py @@ -229,6 +229,17 @@ def get_node_info(cluster_id, ip): return resp.get("data") or {} +def get_container_pod_count(cluster_id, ip): + """获取K8S节点容器/Pod数量 + """ + prom_query = f""" + label_replace(sum by (instance) ({{__name__="kubelet_running_container_count", cluster_id="{cluster_id}", instance=~"{ip}:\\\\d+"}}), "metric_name", "container_count", "instance", ".*") or + label_replace(sum by (instance) ({{__name__="kubelet_running_pod_count", cluster_id="{cluster_id}", instance=~"{ip}:\\\\d+"}}), "metric_name", "pod_count", "instance", ".*") + """ # noqa + resp = query(prom_query) + return resp.get("data") or {} + + def get_node_cpu_usage(cluster_id, ip): """获取CPU总使用率 """ diff --git a/bcs-app/backend/resources/namespace/utils.py b/bcs-app/backend/resources/namespace/utils.py index d18ec3b42..7b6347cc0 100644 --- a/bcs-app/backend/resources/namespace/utils.py +++ b/bcs-app/backend/resources/namespace/utils.py @@ -65,7 +65,7 @@ def get_namespace_by_id(access_token, project_id, namespace_id): def get_k8s_namespaces(access_token, project_id, cluster_id): """获取集群中实时的namespace """ - client = K8SClient(access_token, project_id, cluster_id) + client = K8SClient(access_token, project_id, cluster_id, env=None) return client.get_namespace() diff --git a/readme.md b/readme.md index 510bc9e29..01a2e6ab6 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ > **重要提示**: `master` 分支是开发分支,可能处于 *不稳定或者不可用状态* 。请通过[releases](https://github.com/tencent/bk-bcs-saas/releases) 而非 `master` 去获取稳定的软件包 -蓝鲸智云容器管理平台(BCS,Blueking Container Service)是高度可扩展、灵活易用的容器管理服务。蓝鲸容器管理平台支持两种不同的集群模式,分别为原生Kubernetes模式和基于Mesos自研的模式。使用该平台,用户无需关注基础设施的安装、运维和管理,只需要调用简单的API,或者在页面上进行简单的配置,便可对容器进行启动、停止等操作,查看集群、容器及服务的状态,以及使用各种组件服务。用户可以依据自身的需要选择集群模式和容器编排的方式,以满足业务的特定要求。 +蓝鲸智云容器管理平台(BCS,BlueKing Container Service)是高度可扩展、灵活易用的容器管理服务。蓝鲸容器管理平台支持两种不同的集群模式,分别为原生Kubernetes模式和基于Mesos自研的模式。使用该平台,用户无需关注基础设施的安装、运维和管理,只需要调用简单的API,或者在页面上进行简单的配置,便可对容器进行启动、停止等操作,查看集群、容器及服务的状态,以及使用各种组件服务。用户可以依据自身的需要选择集群模式和容器编排的方式,以满足业务的特定要求。 本次开源的是蓝鲸智云容器管理平台的SaaS,它提供了友好的操作界面,支持对项目集群、节点、命名空间、部署配置、仓库镜像、应用等进行可视化界面操作管理,并提供了WebConsole可快捷查看集群状态的命令行服务,针对K8S集群模式支持使用Helm进行K8S应用的部署和管理。 diff --git a/readme_en.md b/readme_en.md index 70801ae7b..627e5ebc8 100644 --- a/readme_en.md +++ b/readme_en.md @@ -6,7 +6,7 @@ [(Chinese Documents Available)](README.md) -Blueking Container Service(BCS)is a highly scalable, flexible and easy-to-use container management service. BCS supports two different cluster modes, the native Kubernetes mode and the Mesos self-developed mode. With this platform, users do not need to pay attention to the installation, operation and maintenance of the infrastructure, just call a simple API, or simply configure the page to start, stop, etc. the container, view clusters, containers and services. The state, as well as the use of various component services. Users can choose the cluster mode and container orchestration according to their own needs to meet the specific requirements of the business. +BlueKing Container Service(BCS)is a highly scalable, flexible and easy-to-use container management service. BCS supports two different cluster modes, the native Kubernetes mode and the Mesos self-developed mode. With this platform, users do not need to pay attention to the installation, operation and maintenance of the infrastructure, just call a simple API, or simply configure the page to start, stop, etc. the container, view clusters, containers and services. The state, as well as the use of various component services. Users can choose the cluster mode and container orchestration according to their own needs to meet the specific requirements of the business. This open source is the SaaS of BCS, which is the BCS product layer service. It provides a friendly interface for visualizing the project cluster, nodes, namespaces, deployment configuration, docker registry, application, etc. Operation management, and provides a command line service that WebConsole can quickly view the status of the cluster. It supports the deployment and management of K8S applications using Helm for K8S cluster mode.