Skip to content

Allow overriding the vtbackup data volume per tablet pool (#661) - #798

Open
mcrauwel wants to merge 7 commits into
mainfrom
mcrauwel/vtbackup-data-volume-override
Open

Allow overriding the vtbackup data volume per tablet pool (#661)#798
mcrauwel wants to merge 7 commits into
mainfrom
mcrauwel/vtbackup-data-volume-override

Conversation

@mcrauwel

@mcrauwel mcrauwel commented Jun 30, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #661.

This change adds an optional, shard-scoped vtbackup block to VitessShardTemplate. The block is a sibling of tabletPools and controls the scratch data volume used by vtbackup Pods for that shard.

Historically, vtbackup Pods inherited the first tablet pool's dataVolumeClaimTemplate. That behavior allocates a PVC and an underlying disk per shard, even for the initial backup of an empty database. Large clusters can therefore allocate substantial unused storage or fail to bootstrap when those PVCs cannot bind.

Configuration

An empty vtbackup block lets the initial backup use ephemeral scratch space while tablet Pods retain their normal PVCs:

spec:
  keyspaces:
  - name: commerce
    partitionings:
    - equal:
        parts: 2
        shardTemplate:
          vtbackup: {}
          tabletPools:
          - cell: zone1
            type: replica
            replicas: 3
            dataVolumeClaimTemplate:
              accessModes: [ReadWriteOnce]
              resources:
                requests:
                  storage: 100Gi
            vttablet: {}
            mysqld: {}

A shard can instead provide a dedicated PVC template for vtbackup Pods:

vtbackup:
  dataVolumeClaimTemplate:
    storageClassName: cheap-disk
    accessModes: [ReadWriteOnce]
    resources:
      requests:
        storage: 10Gi

Semantics

vtbackup configuration Initial backup Scheduled backup
Block omitted Inherits the first tablet pool's PVC template Inherits the first tablet pool's PVC template
Block present, template omitted Uses ephemeral emptyDir scratch space Inherits the first tablet pool's PVC template
dataVolumeClaimTemplate set Uses the vtbackup-specific PVC template Uses the vtbackup-specific PVC template

Scheduled backups keep persistent scratch storage when the block is empty because vtbackup restores the latest full database before taking a new backup. Using an unbounded emptyDir for that workload could cause node disk pressure or eviction.

Omitting the block preserves the historical behavior. Tablet Pod storage is unaffected.

Storage reconciliation

The operator records a hash of the effective vtbackup PVC template on the initial-backup Pod and PVC. When the storage configuration changes, it:

  1. Preserves a running initial-backup Pod.
  2. Recreates a non-running initial-backup Pod.
  3. Replaces its PVC only after the old Pod is gone.

This allows the controller to converge across PVC-to-emptyDir, emptyDir-to-PVC, and custom-PVC-template changes. In particular, adding vtbackup: {} can recover an initial backup that is Pending because its inherited PVC cannot bind.

Scope

This change only separates vtbackup data-volume configuration from tablet storage. Broader vtbackup Pod overrides can build on the shard-scoped vtbackup block in follow-up work.

Tests

  • Unit coverage for inherited, empty, and custom templates on initial and scheduled backups.
  • Scheduled-backup coverage confirming that an empty vtbackup block still creates and mounts a PVC.
  • Reconciliation coverage for PVC-to-emptyDir, emptyDir-to-PVC, and custom-template transitions.
  • Coverage confirming that storage changes do not interrupt a running initial backup.
  • Integration coverage confirming that vtbackup: {} removes the initial-backup PVC while tablet Pods retain theirs.
  • Generated CRDs, deepcopy code, and API reference documentation are updated.

Local verification:

  • make unit-test
  • Changed-line golangci-lint: 0 issues
  • VitessCluster integration test package compiled successfully

vtbackup Pods (the initial backup taken at shard creation and any
periodic/scheduled backups) inherit their spec from the tablet pool,
including DataVolumeClaimTemplate. That forces a PVC and disk allocation
per shard just to bootstrap an empty backup, which is wasteful and
sometimes unschedulable in large clusters.

Add an optional `vtbackup` block on VitessShardTabletPool with a
`dataVolumeClaimTemplate` override:

  - block omitted        -> inherit the pool's data volume (unchanged).
  - block present, empty -> vtbackup Pods run with no PVC (ephemeral
                            emptyDir scratch space).
  - template set         -> vtbackup Pods use that template (e.g. a
                            smaller disk or a different storageClass).

Both vtbackup code paths funnel through MakeVtbackupSpec, so the override
applies consistently to initial and scheduled backups. Tablet Pods are
unaffected.

Tests: unit coverage of all three states, plus an integration assertion
that an empty override yields a vtbackup-init Pod with no PVC-backed
volume while the tablets keep their PVCs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Matthias Crauwels <matthias.crauwels@planetscale.com>
@mattlord
mattlord requested review from frouioui and mattlord July 18, 2026 19:23
mattlord added 2 commits July 18, 2026 19:24
Signed-off-by: Matt Lord <mattalord@gmail.com>
Comment thread pkg/controller/vitessshard/reconcile_backup_job.go
Comment thread pkg/apis/planetscale/v2/vitessshard_types.go Outdated
mattlord added 2 commits July 22, 2026 01:31
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord
mattlord requested review from frouioui July 22, 2026 22:46
…a-volume-override

# Conflicts:
#	test/endtoend/operator/operator-latest.yaml
#	test/integration/vitesscluster/vitesscluster_test.go
Signed-off-by: Matt Lord <mattalord@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Allow vtbackup pod spec to be override-able.

3 participants