-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add disabled PV re-provisioning by StorageClasses option on restore #8287
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add disabled PV re-provisioning by StorageClasses option on restore |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -129,6 +129,13 @@ type RestoreSpec struct { | |||||
// +optional | ||||||
// +nullable | ||||||
UploaderConfig *UploaderConfigForRestore `json:"uploaderConfig,omitempty"` | ||||||
|
||||||
// DisabledPVReprovisioningStorageClasses is a slice of StorageClasses names. | ||||||
// PV without snaptshot and having one of these StorageClass will not be | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// re-provisionned (even when ReclaimPolicy is Delete). | ||||||
// +optional | ||||||
// +nullable | ||||||
DisabledPVReprovisioningStorageClasses []string `json:"disabledPVReprovisioningStorageClasses,omitempty"` | ||||||
} | ||||||
|
||||||
// UploaderConfigForRestore defines the configuration for the restore. | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1235,7 +1235,19 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso | |||||
// When the PV data is skipped from backup, it's BackupVolumeInfo BackupMethod | ||||||
// is not set, and it will fall into the default case. | ||||||
default: | ||||||
if hasDeleteReclaimPolicy(obj.Object) { | ||||||
hasDisabledStorageClass, err := hasDisabledPVReprovisioningStorageClass(obj, ctx) | ||||||
if err != nil { | ||||||
errs.Add(namespace, err) | ||||||
return warnings, errs, itemExists | ||||||
} | ||||||
|
||||||
if hasDisabledStorageClass { | ||||||
obj, err = ctx.handleSkippedPVHasDisabledReprovisioningStorageClass(obj, restoreLogger) | ||||||
if err != nil { | ||||||
errs.Add(namespace, err) | ||||||
return warnings, errs, itemExists | ||||||
} | ||||||
} else if hasDeleteReclaimPolicy(obj.Object) { | ||||||
restoreLogger.Infof("Dynamically re-provisioning persistent volume because it doesn't have a snapshot and its reclaim policy is Delete.") | ||||||
ctx.pvsToProvision.Insert(name) | ||||||
|
||||||
|
@@ -2527,3 +2539,36 @@ func (ctx *restoreContext) handleSkippedPVHasRetainPolicy( | |||||
obj = resetVolumeBindingInfo(obj) | ||||||
return obj, nil | ||||||
} | ||||||
|
||||||
func hasDisabledPVReprovisioningStorageClass(unstructuredPV *unstructured.Unstructured, ctx *restoreContext) (bool, error) { | ||||||
disabledStorageClasses := ctx.restore.Spec.DisabledPVReprovisioningStorageClasses | ||||||
|
||||||
// Converting Unstructured to PV object. | ||||||
pv := new(v1.PersistentVolume) | ||||||
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredPV.Object, pv); err != nil { | ||||||
return false, errors.Wrapf(err, "error converting persistent volume to structured") | ||||||
} | ||||||
|
||||||
// Checking if PV StorageClass is in the DisabledPVReprovisioningStorageClasses list. | ||||||
for _, disabledStorageClass := range disabledStorageClasses { | ||||||
if disabledStorageClass == pv.Spec.StorageClassName { | ||||||
return true, nil | ||||||
} | ||||||
} | ||||||
return false, nil | ||||||
} | ||||||
|
||||||
func (ctx *restoreContext) handleSkippedPVHasDisabledReprovisioningStorageClass( | ||||||
obj *unstructured.Unstructured, | ||||||
logger logrus.FieldLogger, | ||||||
) (*unstructured.Unstructured, error) { | ||||||
logger.Infof("Restoring persistent volume as-is because it doesn't have a snapshot and it's storage class has re-provisionning disabled.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// Check to see if the claimRef.namespace field needs to be remapped, and do so if necessary. | ||||||
if _, err := remapClaimRefNS(ctx, obj); err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
obj = resetVolumeBindingInfo(obj) | ||||||
return obj, nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.