Skip to content
Documentation menu

Docs / Reference / Workers and storage

R2Bucket

R2Bucket represents a Cloudflare R2 bucket. Deleting it deletes the bucket, unless the retain deletion policy is set; kflare never deletes objects, so a bucket that still holds any is kept and reported as BucketNotEmpty.

API version
kflare.dev/v1alpha1
Scope
Namespaced
Short name
cfr2
Token permission
Account · Workers R2 Storage · Edit

Example

Every field, with the sample's values. The live lines are the repository's sample, which applies as it is; the commented ones are the other fields, filled from other samples where one sets them. Some exclude each other, so check the rules before you uncomment several.

r2bucket.yaml
apiVersion: kflare.dev/v1alpha1
kind: R2Bucket
metadata:
  name: example-r2bucket
  namespace: default
  annotations:
    kflare.dev/deletion-policy: retain
spec:
  accountRef:
    name: my-account
  name: example-bucket
  # jurisdiction: default  # one of: default, eu, us, fedramp, fedramp-high
  # locationHint: apac  # one of: apac, eeur, enam, weur, wnam, oc
  # storageClass: Standard  # one of: Standard, InfrequentAccess

Spec

What you set, with the limits the API server enforces.

FieldDescription
accountRef
objectrequiredimmutable

AccountRef references the CloudflareAccount that owns the R2 bucket. Immutable after creation.

accountRef.name
string

Name of the referent. This field is effectively required, but due to backwards compatibility is allowed to be empty. Instances of this type with an empty value here are almost certainly wrong. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names

Default: ""

jurisdiction
stringimmutable

Jurisdiction is where Cloudflare keeps the bucket's objects: default, or eu or us, which keep them in the European Union or the United States (fedramp and fedramp-high need a FedRAMP account). Each jurisdiction has buckets of its own, so two R2Buckets can name buckets with the same name in different jurisdictions. WorkerScript binds only buckets in the default jurisdiction. Immutable after creation.

Default: default

One of: default, eu, us, fedramp, fedramp-high

locationHint
stringimmutable

LocationHint asks Cloudflare to place a new bucket near a region: wnam, enam, weur, eeur, apac or oc. It is only a hint, and only used when kflare creates the bucket: an adopted bucket stays where it is, and so does a bucket in the eu or us jurisdiction. status.cloudflareMetadata.location shows where the bucket is. Immutable after creation.

One of: apac, eeur, enam, weur, wnam, oc

name
stringrequiredimmutable

Name is the bucket's name in Cloudflare, unique within the account and its jurisdiction: 3 to 63 lowercase letters, digits and hyphens, starting and ending with a letter or digit. Buckets cannot be renamed, so it is immutable.

Limits: matches ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$

storageClass
string

StorageClass is the class of the objects uploaded to the bucket without one of their own: Standard, or InfrequentAccess, which costs less to keep and more to read. Changing it changes the bucket in place; the objects already in it keep their class.

Default: Standard

One of: Standard, InfrequentAccess

Rules

Checked across fields when the resource is applied.

  • locationHint is immutable

Status

What kflare reports. conditions holds the Ready condition, whose reason says why a resource isn't ready.

FieldDescription
cloudflareMetadata
object

CloudflareMetadata holds identifiers and metadata returned by the Cloudflare API.

cloudflareMetadata.bucketName
string

BucketName is the name of the bucket kflare created or adopted, which a WorkerScript's R2 binding names.

cloudflareMetadata.creationDate
string

CreationDate is when Cloudflare created the bucket. It changes if the bucket is deleted outside kflare and created again.

cloudflareMetadata.location
string

Location is the region Cloudflare placed the bucket in, for example WEUR.

conditions
[]object

Conditions represent the latest available observations of the R2 bucket state.

kubectl get

The columns kubectl get r2buckets prints.

ColumnSource
JURISDICTION.spec.jurisdiction
BUCKET.status.cloudflareMetadata.bucketName
LOCATION.status.cloudflareMetadata.location
READY.status.conditions[?(@.type=="Ready")].status
AGE.metadata.creationTimestamp

Samples

From the repository's config/samples, comments included.

cloudflare_v1alpha1_r2bucket.yaml
# Generated by kflare-gen from generator/generator.yaml. DO NOT EDIT.
#
# R2Bucket is the Schema for the r2buckets API.
# It represents a Cloudflare R2 bucket. Deleting it deletes the bucket,
# unless the retain deletion policy is set; kflare never deletes objects,
# so a bucket that still holds any is kept and reported as BucketNotEmpty.
apiVersion: kflare.dev/v1alpha1
kind: R2Bucket
metadata:
  name: example-r2bucket
  namespace: default
  annotations:
    # The retain policy keeps the R2 bucket in Cloudflare when this resource is
    # deleted. Without it, deleting the resource deletes the R2 bucket.
    kflare.dev/deletion-policy: retain
spec:
  accountRef:
    name: my-account
  # Name is the bucket's name in Cloudflare, unique within the account
  # and its jurisdiction: 3 to 63 lowercase letters, digits and hyphens,
  # starting and ending with a letter or digit. Buckets cannot be
  # renamed, so it is immutable.
  name: example-bucket

On GitHub