10.2. Setting a bucket class replication policy
It is possible to set up a replication policy that automatically applies to all the buckets created under a certain bucket class. You can do this in two ways:
You can set a replication policy for Multicloud Object Gateway (MCG) data bucket at the time of creation of bucket class. You must define the replication-policy parameter in a JSON file. You can set a bucket class replication policy for the Placement and Namespace bucket classes.
You can set a bucket class replication policy for the Placement and Namespace bucket classes.
Procedure
From the MCG command-line interface, run the following command:
noobaa -n openshift-storage bucketclass create placement-bucketclass <bucketclass-name> --backingstores <backingstores> --replication-policy=/path/to/json-file.json<bucketclass-name>- Specify the name of the bucket class.
<backingstores>- Specify the name of a backingstore. You can pass many backingstores separated by commas.
/path/to/json-file.jsonIs the path to a JSON file which defines the replication policy.
Example JSON file:
[{ "rule_id": "rule-1", "destination_bucket": "first.bucket", "filter": {"prefix": "repl"}}]"prefix"Is optional. The prefix of the object keys gets replicated. You can leave it empty, for example,
{"prefix": ""}.For example:
noobaa -n openshift-storage bucketclass create placement-bucketclass bc --backingstores azure-blob-ns --replication-policy=/path/to/json-file.jsonThis example creates a placement bucket class with a specific replication policy defined in the JSON file.
You can set a replication policy for Multicloud Object Gateway (MCG) data bucket at the time of creation of bucket class or you can edit their YAML later. You must provide the policy as a JSON-compliant string that adheres to the format shown in the following procedure.
Procedure
Apply the following YAML:
apiVersion: noobaa.io/v1alpha1 kind: BucketClass metadata: labels: app: <desired-app-label> name: <desired-bucketclass-name> namespace: <desired-namespace> spec: placementPolicy: tiers: - backingstores: - <backingstore> placement: Spread replicationPolicy: [{ "rule_id": "<rule id>", "destination_bucket": "first.bucket", "filter": {"prefix": "<object name prefix>"}}]This YAML is an example that creates a placement bucket class. Each Object bucket claim (OBC) object that is uploaded to the bucket is filtered based on the prefix and is replicated to
first.bucket.<desired-app-label>- Specify a label for the app.
<desired-bucketclass-name>- Specify the bucket class name.
<desired-namespace>- Specify the namespace in which the bucket class gets created.
<backingstore>- Specify the name of a backingstore. You can pass many backingstores.
"rule_id"-
Specify the ID number of the rule, for example,
`{"rule_id": "rule-1"}. "destination_bucket"-
Specify the name of the destination bucket, for example,
{"destination_bucket": "first.bucket"}. "prefix"-
Is optional. The prefix of the object keys gets replicated. You can leave it empty, for example,
{"prefix": ""}.