Skip to content

Commit

Permalink
Merge remote-tracking branch 'base/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ielgnaw committed Aug 4, 2020
2 parents 686a8a7 + af44d4f commit 63c585b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
9 changes: 9 additions & 0 deletions bcs-app/backend/apps/metric/views/performance.py
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions bcs-app/backend/apps/metric/views/servicemonitor.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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:
Expand All @@ -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 = [
{
Expand Down Expand Up @@ -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":
Expand Down
8 changes: 5 additions & 3 deletions bcs-app/backend/bcs_k8s/helm/tasks.py
Expand Up @@ -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:
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions bcs-app/backend/components/prometheus.py
Expand Up @@ -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总使用率
"""
Expand Down
2 changes: 1 addition & 1 deletion bcs-app/backend/resources/namespace/utils.py
Expand Up @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -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应用的部署和管理。

Expand Down
2 changes: 1 addition & 1 deletion readme_en.md
Expand Up @@ -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.

Expand Down

0 comments on commit 63c585b

Please sign in to comment.