6.9. 使用 Red Hat Quay API 建立配额


您可以为机构或用户建立配额,并定制配额策略以满足您的 registry 的需求。

以下小节演示了如何为机构、用户以及修改这些设置建立配额。

6.9.1. 使用 Red Hat Quay API 管理机构配额

首次创建机构时,它没有建立的配额。您可以使用 API 检查、创建、更改或删除机构的配额限制。

先决条件

  • 您已生成了 OAuth 访问令牌。

流程

  1. 要为机构设置配额,您可以使用 POST /api/v1/organization/{orgname}/quota 端点:

    $ curl -X POST "https://<quay-server.example.com>/api/v1/organization/<orgname>/quota" \
         -H "Authorization: Bearer <access_token>" \
         -H "Content-Type: application/json" \
         -d '{
             "limit_bytes": 10737418240,
             "limits": "10 Gi"
         }'

    输出示例

    "Created"

  2. 使用 GET /api/v1/organization/{orgname}/quota 命令返回有关策略的信息,包括其他机构配额端点所需的 ID 号。例如:

    $ curl -k -X GET -H "Authorization: Bearer <token>" -H 'Content-Type: application/json'  https://example-registry-quay-quay-enterprise.apps.docs.gcp.quaydev.org/api/v1/organization/testorg/quota  | jq

    输出示例

    [{"id": 1, "limit_bytes": 10737418240, "limit": "10.0 GiB", "default_config": false, "limits": [], "default_config_exists": false}]

    获取 ID 号后,您可以使用 GET /api/v1/organization/{orgname}/quota/{quota_id} 命令列出配额策略。例如:

    $ curl -X GET "https://<quay-server.example.com>/api/v1/organization/<orgname>/quota/<quota_id>" \
         -H "Authorization: Bearer <access_token>"

    输出示例

    {"id": 1, "limit_bytes": 10737418240, "limit": "10.0 GiB", "default_config": false, "limits": [], "default_config_exists": false}

  3. 您可以使用 PUT /api/v1/organization/{orgname}/quota/{quota_id} 命令修改现有的配额限制。请注意,这需要策略 ID。例如:

    $ curl -X PUT "https://<quay-server.example.com>/api/v1/organization/<orgname>/quota/<quota_id>" \
         -H "Authorization: Bearer <access_token>" \
         -H "Content-Type: application/json" \
         -d '{
             "limit_bytes": <limit_in_bytes>
         }'

    输出示例

    {"id": 1, "limit_bytes": 21474836480, "limit": "20.0 GiB", "default_config": false, "limits": [], "default_config_exists": false}

  4. 可以通过 DELETE /api/v1/organization/{orgname}/quota/{quota_id} 命令删除机构的配额。例如:

    $ curl -X DELETE "https://<quay-server.example.com>/api/v1/organization/<orgname>/quota/<quota_id>" \
         -H "Authorization: Bearer <access_token>"

    此命令不返回输出。

6.9.2. 使用 Red Hat Quay API 为机构设置配额限制

您可以为机构设置特定的配额限制,以便在超过、返回警告时,或者推送的镜像会被完全拒绝。

流程

  1. 使用 POST /api/v1/organization/{orgname}/quota/{quota_id}/limit 命令创建配额策略,以便在超过分配的配额时拒绝镜像。例如:

    $ curl -X POST "https://<quay-server.example.com>/api/v1/organization/<orgname>/quota/<quota_id>/limit" \
         -H "Authorization: Bearer <access_token>" \
         -H "Content-Type: application/json" \
         -d '{
               "limit_bytes": 21474836480,
               "type": "Reject", 1
               "threshold_percent": 90 2
             }'
    1
    拒绝或警告 之一
    2
    配额阈值,以百分比表示。

    输出示例

    "Created"

  2. 使用 GET /api/v1/organization/{orgname}/quota/{quota_id}/limit 获取配额限制的 ID。例如:

    $ curl -X GET "https://<quay-server.example.com>/api/v1/organization/<orgname>/quota/<quota_id>/limit" \
         -H "Authorization: Bearer <access_token>"

    输出示例

    [{"id": 2, "type": "Reject", "limit_percent": 90}]

  1. 使用 PUT /api/v1/organization/{orgname}/quota/{quota_id}/limit/{limit_id} 端点更新策略。例如:

    $ curl -X PUT "https://<quay-server.example.com>/api/v1/organization/<orgname>/quota/<quota_id>/limit/<limit_id>" \
         -H "Authorization: Bearer <access_token>" \
         -H "Content-Type: application/json" \
         -d '{
               "type": "<type>",
               "threshold_percent": <threshold_percent>
             }'

    输出示例

    {"id": 3, "limit_bytes": 10737418240, "limit": "10.0 GiB", "default_config": false, "limits": [{"id": 2, "type": "Warning", "limit_percent": 80}], "default_config_exists": false}

  2. 您可以使用 DELETE /api/v1/organization/{orgname}/quota/{quota_id}/limit/{limit_id} 端点删除配额限制:

    $ curl -X DELETE "https://<quay-server.example.com>/api/v1/organization/<orgname>/quota/<quota_id>/limit/<limit_id>" \
         -H "Authorization: Bearer <access_token>"

    此命令不返回输出。

6.9.3. 使用 Red Hat Quay API 为用户获取配额限制

您可以为用户指定配额和限制,以便在超过时返回警告,或者推送的镜像被完全拒绝。必须在 Red Hat Quay UI 上设置用户的配额限制。以下 API 可用于查看登录的用户的配额限值。

流程

  1. 使用 GET /api/v1/user/quota 命令返回有关配额限制的信息:

    $ curl -X GET "https://<quay-server.example.com>/api/v1/user/quota" \
      -H "Authorization: Bearer <access_token>"

    输出示例

    [{"id": 4, "limit_bytes": 2199023255552, "limit": "2.0 TiB", "default_config": false, "limits": [], "default_config_exists": false}]

  2. 收到配额 ID 后,您可以使用 GET /api/v1/user/quota/{quota_id} 端点传递该端点,以返回有关限制的信息:

    $ curl -X GET "https://<quay-server.example.com>/api/v1/user/quota/{quota_id}" \
      -H "Authorization: Bearer <access_token>"

    输出示例

    {"id": 4, "limit_bytes": 2199023255552, "limit": "2.0 TiB", "default_config": false, "limits": [], "default_config_exists": false}

  3. 可以使用 GET /api/v1/user/quota/{quota_id}/limit 端点来查看这些限制。例如:

    $ curl -X GET "https://<quay-server.example.com>/api/v1/user/quota/{quota_id}/limit" \
      -H "Authorization: Bearer <access_token>"

    输出示例

    [{"id": 3, "type": "Reject", "limit_percent": 100}]

  4. 可以使用 GET /api/v1/user/quota/{quota_id}/limit/{limit_id} 端点来返回有关整个策略的附加信息:

    $ curl -X GET "https://<quay-server.example.com>/api/v1/user/quota/{quota_id}/limit/{limit_id}" \
      -H "Authorization: Bearer <access_token>"

    输出示例

    {"id": 4, "limit_bytes": 2199023255552, "limit": "2.0 TiB", "default_config": false, "limits": [{"id": 3, "type": "Reject", "limit_percent": 100}], "default_config_exists": false}

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.