Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/e2e-k8s-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@ on:
rwx_enabled:
type: string
default: ""
backup_enabled:
type: string
default: ""
kubernetes_versions:
type: string
default: '["1.34.3", "1.33.7", "1.32.11"]'
ginkgo_flags:
type: string
default: ""
secrets:
BACKUP_S3_ENDPOINT:
required: false
BACKUP_S3_BUCKET:
required: false
BACKUP_S3_ACCESS_KEY:
required: false
BACKUP_S3_SECRET_KEY:
required: false
BACKUP_RESTIC_PASSWORD:
required: false

jobs:
e2e-k8s:
Expand All @@ -28,6 +42,13 @@ jobs:
TEST_SCHEDULER_EXTENDER_TYPE: ${{ inputs.test_scheduler_extender_type }}
TEST_LEGACY: ${{ inputs.test_legacy }}
RWX_ENABLED: ${{ inputs.rwx_enabled }}
BACKUP_ENABLED: ${{ inputs.backup_enabled }}
BACKUP_S3_ENDPOINT: ${{ secrets.BACKUP_S3_ENDPOINT }}
BACKUP_S3_BUCKET: ${{ secrets.BACKUP_S3_BUCKET }}
BACKUP_S3_ACCESS_KEY: ${{ secrets.BACKUP_S3_ACCESS_KEY }}
BACKUP_S3_SECRET_KEY: ${{ secrets.BACKUP_S3_SECRET_KEY }}
BACKUP_RESTIC_PASSWORD: ${{ secrets.BACKUP_RESTIC_PASSWORD }}
BACKUP_S3_PREFIX: ci/${{ github.run_id }}-${{ github.run_attempt }}
GINKGO_FLAGS: ${{ inputs.ginkgo_flags }}
steps:
- id: check
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/e2e-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,22 @@ jobs:
rwx_enabled: "1"
kubernetes_versions: '["1.34.3"]'
ginkgo_flags: "--focus=rwx"

backup:
needs: build
uses: ./.github/workflows/e2e-k8s-workflow.yaml
# Skip on forks: PRs from forks cannot access repo secrets, so the backup
# job would always skip. Running only on same-repo events avoids the noise.
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push'
with:
test_scheduler_extender_type: "daemonset"
test_legacy: "false"
backup_enabled: "1"
kubernetes_versions: '["1.34.3"]'
ginkgo_flags: "--focus=backup"
secrets:
BACKUP_S3_ENDPOINT: ${{ secrets.BACKUP_S3_ENDPOINT }}
BACKUP_S3_BUCKET: ${{ secrets.BACKUP_S3_BUCKET }}
BACKUP_S3_ACCESS_KEY: ${{ secrets.BACKUP_S3_ACCESS_KEY }}
BACKUP_S3_SECRET_KEY: ${{ secrets.BACKUP_S3_SECRET_KEY }}
BACKUP_RESTIC_PASSWORD: ${{ secrets.BACKUP_RESTIC_PASSWORD }}
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ When you use AI assistance on this project, the AI reads this file to understand
- [docs/lvmd-protocol.md](./docs/lvmd-protocol.md) - gRPC protocol (auto-generated)
- **Advanced Topics**:
- [docs/snapshot-and-restore.md](./docs/snapshot-and-restore.md) - Snapshot/clone support
- [docs/backup-restore.md](./docs/backup-restore.md) - restic-based backup/restore to S3 (opt-in)
- [docs/advanced-setup.md](./docs/advanced-setup.md) - Advanced configurations
- [docs/limitations.md](./docs/limitations.md) - Known limitations
- [docs/faq.md](./docs/faq.md) - Frequently asked questions
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ manifests: generate-legacy-api ## Generate WebhookConfiguration, ClusterRole and
output:crd:artifacts:config=config/crd/bases
cat config/crd/bases/topolvm.io_logicalvolumes.yaml | xargs -d" " printf "$$CRD_TEMPLATE" > charts/topolvm/templates/crds/topolvm.io_logicalvolumes.yaml
cat config/crd/bases/topolvm.cybozu.com_logicalvolumes.yaml | xargs -d" " printf "$$LEGACY_CRD_TEMPLATE" > charts/topolvm/templates/crds/topolvm.cybozu.com_logicalvolumes.yaml
cat config/crd/bases/topolvm.io_backupconfigs.yaml | xargs -d" " printf "$$CRD_TEMPLATE" > charts/topolvm/templates/crds/topolvm.io_backupconfigs.yaml
cat config/crd/bases/topolvm.io_pvcbackups.yaml | xargs -d" " printf "$$CRD_TEMPLATE" > charts/topolvm/templates/crds/topolvm.io_pvcbackups.yaml
cat config/crd/bases/topolvm.io_restores.yaml | xargs -d" " printf "$$CRD_TEMPLATE" > charts/topolvm/templates/crds/topolvm.io_restores.yaml
cat config/crd/bases/topolvm.cybozu.com_backupconfigs.yaml | xargs -d" " printf "$$LEGACY_CRD_TEMPLATE" > charts/topolvm/templates/crds/topolvm.cybozu.com_backupconfigs.yaml
cat config/crd/bases/topolvm.cybozu.com_pvcbackups.yaml | xargs -d" " printf "$$LEGACY_CRD_TEMPLATE" > charts/topolvm/templates/crds/topolvm.cybozu.com_pvcbackups.yaml
cat config/crd/bases/topolvm.cybozu.com_restores.yaml | xargs -d" " printf "$$LEGACY_CRD_TEMPLATE" > charts/topolvm/templates/crds/topolvm.cybozu.com_restores.yaml

.PHONY: generate-api ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
generate-api:
Expand Down
160 changes: 160 additions & 0 deletions api/legacy/v1/backupconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// S3Spec describes the remote S3-compatible object store used as the restic repository backend.
type S3Spec struct {
// Endpoint is the S3 endpoint URL, e.g. "https://s3.us-east-1.amazonaws.com"
// or a MinIO endpoint. Required.
Endpoint string `json:"endpoint"`

// Bucket is the target bucket name. One restic repository per PVC is
// created under the key prefix "<namespace>/<pvc-name>/".
Bucket string `json:"bucket"`

// Region is the S3 region. Optional for providers that do not require it.
//+kubebuilder:validation:Optional
Region string `json:"region,omitempty"`

// CredentialsSecretRef references a Secret containing AWS_ACCESS_KEY_ID and
// AWS_SECRET_ACCESS_KEY keys. The secret must live in the same namespace as
// the topolvm-controller.
CredentialsSecretRef corev1.SecretReference `json:"credentialsSecretRef"`

// InsecureTLS disables TLS verification against the S3 endpoint. Use only
// for self-signed endpoints during testing.
//+kubebuilder:validation:Optional
InsecureTLS bool `json:"insecureTLS,omitempty"`

// Prefix is an optional key prefix prepended under the bucket root before
// the per-PVC "<namespace>/<pvc>" path. Useful for isolating CI runs that
// share a bucket, e.g. prefix="ci/<run-id>".
//+kubebuilder:validation:Optional
Prefix string `json:"prefix,omitempty"`
}

// RetentionSpec mirrors the restic forget --keep-* flags.
type RetentionSpec struct {
//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Optional
KeepLast int32 `json:"keepLast,omitempty"`

//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Optional
KeepHourly int32 `json:"keepHourly,omitempty"`

//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Optional
KeepDaily int32 `json:"keepDaily,omitempty"`

//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Optional
KeepWeekly int32 `json:"keepWeekly,omitempty"`

//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Optional
KeepMonthly int32 `json:"keepMonthly,omitempty"`

//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Optional
KeepYearly int32 `json:"keepYearly,omitempty"`
}

// BackupConfigSpec defines the cluster-wide backup configuration. A single
// BackupConfig named "default" is expected; additional BackupConfigs are
// ignored by the controller.
type BackupConfigSpec struct {
// S3 is the remote object store configuration.
S3 S3Spec `json:"s3"`

// ResticPasswordSecretRef references a Secret with a single "password" key
// used as the restic repository password. Losing this secret makes existing
// backups unreadable.
ResticPasswordSecretRef corev1.SecretReference `json:"resticPasswordSecretRef"`

// Schedule is the default cron schedule applied to every backed-up PVC.
// When empty, no backup CronJobs are created unless a PVC sets its own
// schedule via the "topolvm.io/backup-schedule" annotation.
//+kubebuilder:validation:Optional
Schedule string `json:"schedule,omitempty"`

// Retention is the default retention policy. Per-PVC annotations of the
// form "topolvm.io/backup-retention-<bucket>" override individual buckets.
//+kubebuilder:validation:Optional
Retention RetentionSpec `json:"retention,omitempty"`

// Selector restricts which PVCs are backed up. An empty selector matches
// every PVC bound to a TopoLVM StorageClass. PVCs annotated
// "topolvm.io/backup=false" are always skipped.
//+kubebuilder:validation:Optional
Selector *metav1.LabelSelector `json:"selector,omitempty"`

// KeepSnapshotAfterBackup controls whether the VolumeSnapshot created for
// the backup is preserved after restic completes. When false (default) the
// snapshot is deleted once the backup finishes, regardless of outcome.
// Can be overridden per-PVC via "topolvm.io/backup-keep-snapshot".
//+kubebuilder:default=false
KeepSnapshotAfterBackup bool `json:"keepSnapshotAfterBackup,omitempty"`

// VolumeSnapshotClassName is the VolumeSnapshotClass used to snapshot
// PVCs prior to backup. If empty the controller falls back to the default
// VolumeSnapshotClass for the topolvm driver.
//+kubebuilder:validation:Optional
VolumeSnapshotClassName string `json:"volumeSnapshotClassName,omitempty"`

// Suspend pauses creation of new backup Jobs without deleting existing
// CronJobs or previously taken backups.
//+kubebuilder:validation:Optional
Suspend bool `json:"suspend,omitempty"`
}

// BackupConfigStatus reports the observed state of the backup fleet.
type BackupConfigStatus struct {
// ObservedGeneration matches BackupConfig.metadata.generation when the
// status was last updated.
//+kubebuilder:validation:Optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// ManagedPVCs is the number of PVCs the controller currently has a
// backup CronJob for.
//+kubebuilder:validation:Optional
ManagedPVCs int32 `json:"managedPVCs,omitempty"`

// Conditions is the list of conditions for this BackupConfig. Typical
// condition types: "Ready", "CredentialsValid".
//+kubebuilder:validation:Optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster

// BackupConfig is the cluster-scoped configuration for TopoLVM backup/restore
// via restic.
type BackupConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BackupConfigSpec `json:"spec,omitempty"`
Status BackupConfigStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// BackupConfigList contains a list of BackupConfig.
type BackupConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BackupConfig `json:"items"`
}

func init() {
SchemeBuilder.Register(&BackupConfig{}, &BackupConfigList{})
}
Loading
Loading