예제 #1
0
    def list_custom_objects(self, request, project_id, cluster_id, crd_name):
        cluster_auth = ClusterAuth(request.user.token.access_token, project_id, cluster_id)
        crd_client = CustomResourceDefinition(cluster_auth)
        crd = crd_client.get(name=crd_name, is_format=False)
        if not crd:
            raise error_codes.ResNotFoundError(_("集群({})中未注册自定义资源({})").format(cluster_id, crd_name))

        cobj_client = get_cobj_client_by_crd(cluster_auth, crd_name)
        cobj_list = cobj_client.list(namespace=request.query_params.get("namespace"))
        return Response(to_table_format(crd.to_dict(), cobj_list, cluster_id=cluster_id))
예제 #2
0
def gen_cobj_web_annotations(request, project_id, cluster_id,
                             crd_name: str) -> Dict:
    """ 构造 custom_object 相关 web_annotations """
    client = CustomResourceDefinition(request.ctx_cluster)
    crd = client.get(name=crd_name, is_format=False)
    if not crd:
        raise ResourceNotExist(
            _('集群 {} 中未注册自定义资源 {}').format(cluster_id, crd_name))
    # 先获取基础的,仅包含权限信息的 web_annotations
    web_annotations = gen_base_web_annotations(request, project_id, cluster_id)
    web_annotations.update({'additional_columns': crd.additional_columns})
    return web_annotations