Updated on 2024-12-02 GMT+08:00

Adding an Image Retention Policy

Function

Add an image retention policy.

URI

POST /v2/manage/namespaces/{namespace}/repos/{repository}/retentions

Table 1 describes the parameters.

Table 1 Parameter description

Parameter

Mandatory

Type

Description

namespace

Yes

String

Organization name.

repository

Yes

String

Image repository name.

Request

  • Request parameters
    Table 2 Request header parameters

    Parameter

    Mandatory

    Type

    Description

    Content-Type

    Yes

    String

    Message body type (format). The value can be application/json or charset=utf-8 application/json.

    The default value is application/json.

    X-Auth-Token

    Yes

    String

    User token.

    The token can be obtained by calling an IAM API. The value of X-Subject-Token in the response header is the user token.

    Table 3 Request body parameters

    Parameter

    Mandatory

    Type

    Description

    algorithm

    Yes

    String

    Retention policy matching rule. The value is or.

    rules

    Yes

    Array of objects

    Image retention policy.

    Table 4 rules parameter description

    Parameter

    Mandatory

    Type

    Description

    template

    Yes

    String

    Retention policy type. The value can be date_rule (number of days) or tag_rule (number of tags).

    params

    Yes

    Object

    • If template is set to date_rule, set params to {"days": "xxx"}.
    • If template is set to tag_rule, set params to {"num": "xxx"}.

    tag_selectors

    Yes

    Array of objects

    Image tags that are not counted in the retention policy.

    Table 5 tag_selectors parameter description

    Parameter

    Mandatory

    Type

    Description

    kind

    Yes

    String

    Matching rule. The value can be label or regexp.

    pattern

    Yes

    String

    • If kind is set to label, set this parameter to specific image tags.
    • If kind is set to regexp, set this parameter to a regular expression.
  • Example request
    POST https://{Endpoint}/v2/manage/namespaces/group/repos/busybox/retentions
    
    {
        "algorithm": "or",
        "rules": [
            {
                "template": "date_rule",
                "params": {
                    "days": "30"
                },
                "tag_selectors": [
                    {
                        "kind": "label",
                        "pattern": "v5"
                    },
                    {
                        "kind": "label",
                        "pattern": "1.0.1"
                    },
                    {
                        "kind": "regexp",
                        "pattern": "^123$"
                    }
                ]
            }
        ]
    }

Response

  • Response parameters
    Table 6 Response body parameter description

    Parameter

    Type

    Description

    id

    Integer

    Rule ID.

  • Example response
    Status code: 201
    {"id": 34}

Status Code

Status Code

Description

201

Creation successful.

400

Request error.

401

Authentication failed.

404

The organization does not exist.

500

Internal error.

Error Codes

For details, see Error Codes.