Set object lifecycle policy for storage buckets

This page shows you how to set object lifecycle policy for Google Distributed Cloud (GDC) air-gapped storage buckets.

Before you begin

A project namespace manages bucket resources in the Management API server. You must have a project to work with buckets and objects.

You must also have the appropriate bucket permissions to perform the following operation. See Grant bucket access.

Set object lifecycle policy on bucket

You can use object lifecycle policy to automatically manage objects in your buckets. This helps you store data more efficiently throughout its lifespan. A lifecycle configuration is a list of rules to expire a group of objects based on certain matching criteria.

You can create a bucket with or without object lifecycle policy. And you can apply new, update existing or remove existing lifecycle policy after the bucket is created.

For unversioned buckets, expiration means permanently removing the object asynchronously.

For versioned buckets, if the current object version is not a deletion marker, expiration makes the current version noncurrent and then adds a delete marker to the current version.

To set and modify the object lifecycle policy, update the Bucket.spec.bucketPolicy.lifecyclePolicy field.

CLI

The following are few examples of bucket resources with different object lifecycle policy configured:

apiVersion: object.gdc.goog/v1 kind: Bucket metadata:  name: BUCKET_NAME  namespace: NAMESPACE_NAME spec:  description: "Bucket with lifecycle rule to expire all objects after 2000 days"  storageClass: Standard  bucketPolicy:  lifecyclePolicy:  enable: true  lifecycleRules:  - expiration:  days: 2000  id: expire-all-after-2000-days  status: Enabled ---------- apiVersion: object.gdc.goog/v1 kind: Bucket metadata:  name: BUCKET_NAME  namespace: NAMESPACE_NAME spec:  description: "Bucket with lifecycle rule to expire objects having name start with abc after 500 days"  storageClass: Standard  bucketPolicy:  lifecyclePolicy:  enable: true  lifecycleRules:  - expiration:  days: 500  id: expire-all-start-with-abc-after-500-days  status: Enabled  filter:  prefixFilter: "abc" ---------- apiVersion: object.gdc.goog/v1 kind: Bucket metadata:  name: BUCKET_NAME  namespace: NAMESPACE_NAME spec:  description: "Bucket with lifecycle rule to expire objects having specific tag after 300 days"  storageClass: Standard  bucketPolicy:  lifecyclePolicy:  enable: true  lifecycleRules:  - expiration:  days: 300  id: expire-all-objects-with-specific-tag-after-300-days  status: Enabled  filter:  tagFilters:  - key: testKey  value: testValue 

Any updates to the lifecycle policy applies to the existing objects and objects uploaded after the update.

When the bucket also has object locking configured, objects are being protected from expiration before the retention days end.