Skip to content

Commit

Permalink
Update RestoreCSISnapshot function's argument check to fail on zero r…
Browse files Browse the repository at this point in the history
…estoreSize (#1553)

Signed-off-by: Ivan Sim <ivan.sim@kasten.io>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
ihcsim and mergify[bot] committed Jul 20, 2022
1 parent 58d1f50 commit a90fa3c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ Arguments:
`pvc`, Yes, `string`, name of the new PVC
`namespace`, Yes, `string`, namespace of the VolumeSnapshot and resultant PersistentVolumeClaim
`storageClass`, Yes, `string`, name of the StorageClass
`restoreSize`, Yes, `string`, required memory size to restore PVC
`restoreSize`, Yes, `string`, required memory size to restore PVC. Must be greater than zero.
`accessModes`, No, `[]string`, access modes for the underlying PV (Default is ``[]{"ReadWriteOnce"}```)
`volumeMode`, No, `string`, mode of volume (Default is ``"Filesystem"```)
`labels`, No, `map[string]string`, optional labels for the PersistentVolumeClaim
Expand Down
4 changes: 4 additions & 0 deletions pkg/function/restore_csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package function
import (
"context"
"errors"
"fmt"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -113,6 +114,9 @@ func (*restoreCSISnapshotFunc) Exec(ctx context.Context, tp param.TemplateParams
if err != nil {
return nil, err
}
if size.IsZero() {
return nil, fmt.Errorf("Failed to restore CSI snapshot. restoreSize argument cannot be zero")
}
restoreArgs.RestoreSize = &size

kubeCli, err := getClient()
Expand Down

0 comments on commit a90fa3c

Please sign in to comment.