vmware-tanzu / velero-plugin-for-vsphere

Plugin to support Velero on vSphere
Other
58 stars 50 forks source link

Fail the Restore if the StorageClass is associated with WaitForFirstConsumer volumeBindingMode #568

Closed deepakkinni closed 4 months ago

deepakkinni commented 4 months ago

What this PR does / why we need it: Fail the Restore if the StorageClass is associated with WaitForFirstConsumer volumeBindingMode

Which issue(s) this PR fixes: Fixes #

Special notes for your reviewer:

Testing Done

  1. Basic Regression: Backup and Restore with no VolumeBindingMode specified in the StorageClass(implying Immediate)
    
    ❯ velero backup create rest-warn-test-1 --include-namespaces=test-ns --snapshot-volumes
    ❯ velero backup describe rest-warn-test-1
    Name:         rest-warn-test-1
    Namespace:    velero
    Labels:       velero.io/storage-location=default
    Annotations:  velero.io/source-cluster-k8s-gitversion=v1.29.1
              velero.io/source-cluster-k8s-major-version=1
              velero.io/source-cluster-k8s-minor-version=29

Phase: Completed

Errors: 0 Warnings: 0

Namespaces: Included: test-ns Excluded:

Resources: Included: * Excluded: Cluster-scoped: auto

Label selector:

Storage Location: default

Velero-Native Snapshot PVs: true

TTL: 720h0m0s

CSISnapshotTimeout: 10m0s

Hooks:

Backup Format Version: 1.1.0

Started: 2024-02-29 11:08:03 -0800 PST Completed: 2024-02-29 11:08:11 -0800 PST

Expiration: 2024-03-30 12:08:03 -0700 PDT

Total items to be backed up: 8 Items backed up: 8

Velero-Native Snapshots:

❯ velero restore create --from-backup rest-warn-test-1 ❯ velero restore describe rest-warn-test-1-20240229111117 Name: rest-warn-test-1-20240229111117 Namespace: velero Labels: Annotations:

Phase: Completed Total items to be restored: 5 Items restored: 5

Started: 2024-02-29 11:11:17 -0800 PST Completed: 2024-02-29 11:12:21 -0800 PST

Backup: rest-warn-test-1

Namespaces: Included: all namespaces found in the backup Excluded:

Resources: Included: * Excluded: nodes, events, events.events.k8s.io, backups.velero.io, restores.velero.io, resticrepositories.velero.io, csinodes.storage.k8s.io, volumeattachments.storage.k8s.io, backuprepositories.velero.io Cluster-scoped: auto

Namespace mappings:

Label selector:

Restore PVs: auto

Existing Resource Policy:

Preserve Service NodePorts: auto

❯ kubectl get pv,pvc -A NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE persistentvolume/pvc-7350c4ea-02a5-4806-ac11-76d992cb0eb3 1Gi RWO Delete Bound test-ns/example-vanilla-block-pvc example-vanilla-block-sc 93s

NAMESPACE NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE test-ns persistentvolumeclaim/example-vanilla-block-pvc Bound pvc-7350c4ea-02a5-4806-ac11-76d992cb0eb3 1Gi RWO example-vanilla-block-sc 96s


2. Restore into a setup with a StorageClass with volumeBindingMode as WaitForFirstConsumer marked as default
Expectation: Restore should fail 

❯ kubectl get sc NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE example-vanilla-block-sc (default) csi.vsphere.vmware.com Delete WaitForFirstConsumer false 6s

❯ velero restore create --from-backup rest-warn-test-1 Restore request "rest-warn-test-1-20240229112130" submitted successfully. Run velero restore describe rest-warn-test-1-20240229112130 or velero restore logs rest-warn-test-1-20240229112130 for more details. ❯ velero restore describe rest-warn-test-1-20240229112130 Name: rest-warn-test-1-20240229112130 Namespace: velero Labels: Annotations:

Phase: PartiallyFailed (run 'velero restore logs rest-warn-test-1-20240229112130' for more information) Total items to be restored: 5 Items restored: 5

Started: 2024-02-29 11:21:30 -0800 PST Completed: 2024-02-29 11:21:32 -0800 PST

Errors: Velero: Cluster: Namespaces: test-ns: error preparing persistentvolumeclaims/test-ns/example-vanilla-block-pvc: rpc error: code = Unknown desc = The PVC to be restored is a associated with StorageClass with WaitForFirstConsumer VolumeBindingMode, this is currently not supported

Backup: rest-warn-test-1

Namespaces: Included: all namespaces found in the backup Excluded:

Resources: Included: * Excluded: nodes, events, events.events.k8s.io, backups.velero.io, restores.velero.io, resticrepositories.velero.io, csinodes.storage.k8s.io, volumeattachments.storage.k8s.io, backuprepositories.velero.io Cluster-scoped: auto

Namespace mappings:

Label selector:

Restore PVs: auto

Existing Resource Policy:

Preserve Service NodePorts: auto

time="2024-02-29T19:21:32Z" level=error msg="Namespace test-ns, resource restore error: error preparing persistentvolumeclaims/test-ns/example-vanilla-block-pvc: rpc error: code = Unknown desc = The PVC to be restored is a associated with StorageClass with WaitForFirstConsumer VolumeBindingMode, this is currently not supported" logSource="pkg/controller/restore_controller.go:531" restore=velero/rest-warn-test-1-20240229112130


3. Restore with StorageClass mapping, mapping from a StorageClass with Immediate VolumeBindingMode to a StorageClass with WaitForFirstConsumer VolumeBindingMode
Expectation: Restore should fail

❯ kubectl get sc NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE example-vanilla-block-sc csi.vsphere.vmware.com Delete Immediate false 43s example-vanilla-block-sc-2 csi.vsphere.vmware.com Delete WaitForFirstConsumer false 7s

❯ velero restore create --from-backup rest-warn-test-1 Restore request "rest-warn-test-1-20240229113221" submitted successfully. Run velero restore describe rest-warn-test-1-20240229113221 or velero restore logs rest-warn-test-1-20240229113221 for more details. ❯ velero restore describe rest-warn-test-1-20240229113221 Name: rest-warn-test-1-20240229113221 Namespace: velero Labels: Annotations:

Phase: PartiallyFailed (run 'velero restore logs rest-warn-test-1-20240229113221' for more information) Total items to be restored: 5 Items restored: 5

Started: 2024-02-29 11:32:21 -0800 PST Completed: 2024-02-29 11:32:22 -0800 PST

Errors: Velero: Cluster: Namespaces: test-ns: error preparing persistentvolumeclaims/test-ns/example-vanilla-block-pvc: rpc error: code = Unknown desc = The PVC to be restored is a associated with StorageClass with WaitForFirstConsumer VolumeBindingMode, this is currently not supported

Backup: rest-warn-test-1

Namespaces: Included: all namespaces found in the backup Excluded:

Resources: Included: * Excluded: nodes, events, events.events.k8s.io, backups.velero.io, restores.velero.io, resticrepositories.velero.io, csinodes.storage.k8s.io, volumeattachments.storage.k8s.io, backuprepositories.velero.io Cluster-scoped: auto

Namespace mappings:

Label selector:

Restore PVs: auto

Existing Resource Policy:

Preserve Service NodePorts: auto

time="2024-02-29T19:32:22Z" level=error msg="Namespace test-ns, resource restore error: error preparing persistentvolumeclaims/test-ns/example-vanilla-block-pvc: rpc error: code = Unknown desc = The PVC to be restored is a associated with StorageClass with WaitForFirstConsumer VolumeBindingMode, this is currently not supported" logSource="pkg/controller/restore_controller.go:531" restore=velero/rest-warn-test-1-20240229113221


**Does this PR introduce a user-facing change?**:
```release-note
Prevents Restore when the target Restore StorageClass has WaitForFirstConsumer volumeBindingMode
xing-yang commented 4 months ago

Need rebase?

lipingxue commented 4 months ago

Change looks good to me.

lipingxue commented 4 months ago

/approve

varunsrinivasan2 commented 4 months ago

lgtm