Skip to content

Commit

Permalink
Don't panic when storageClassName is not set in stateful sets
Browse files Browse the repository at this point in the history
Signed-off-by: divolgin <[email protected]>
  • Loading branch information
divolgin committed Aug 25, 2022
1 parent e849441 commit ad4e733
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/5247-divolgin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix nil pointer panic when restoring StatefulSets
12 changes: 6 additions & 6 deletions pkg/restore/change_storageclass_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (a *ChangeStorageClassAction) Execute(input *velero.RestoreItemActionExecut

if len(sts.Spec.VolumeClaimTemplates) > 0 {
for index, pvc := range sts.Spec.VolumeClaimTemplates {
exists, newStorageClass, err := a.isStorageClassExist(log, *pvc.Spec.StorageClassName, config)
exists, newStorageClass, err := a.isStorageClassExist(log, pvc.Spec.StorageClassName, config)
if err != nil {
return nil, err
} else if !exists {
Expand All @@ -124,7 +124,7 @@ func (a *ChangeStorageClassAction) Execute(input *velero.RestoreItemActionExecut
return nil, errors.Wrap(err, "error getting item's spec.storageClassName")
}

exists, newStorageClass, err := a.isStorageClassExist(log, storageClass, config)
exists, newStorageClass, err := a.isStorageClassExist(log, &storageClass, config)
if err != nil {
return nil, err
} else if !exists {
Expand All @@ -140,15 +140,15 @@ func (a *ChangeStorageClassAction) Execute(input *velero.RestoreItemActionExecut
return velero.NewRestoreItemActionExecuteOutput(obj), nil
}

func (a *ChangeStorageClassAction) isStorageClassExist(log *logrus.Entry, storageClass string, cm *corev1.ConfigMap) (exists bool, newStorageClass string, err error) {
if storageClass == "" {
func (a *ChangeStorageClassAction) isStorageClassExist(log *logrus.Entry, storageClass *string, cm *corev1.ConfigMap) (exists bool, newStorageClass string, err error) {
if storageClass == nil || *storageClass == "" {
log.Debug("Item has no storage class specified")
return false, "", nil
}

newStorageClass, ok := cm.Data[storageClass]
newStorageClass, ok := cm.Data[*storageClass]
if !ok {
log.Debugf("No mapping found for storage class %s", storageClass)
log.Debugf("No mapping found for storage class %s", *storageClass)
return false, "", nil
}

Expand Down

0 comments on commit ad4e733

Please sign in to comment.