Skip to content

Commit

Permalink
Merge pull request #143 from aleofreddi/master
Browse files Browse the repository at this point in the history
Add source-volume and source-snapshot flags to the create volume command
  • Loading branch information
codenrhoden authored Mar 4, 2021
2 parents 5caed9b + c0f7fc9 commit 632c7b6
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions csc/cmd/controller_create_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"errors"
"os"

log "github.com/sirupsen/logrus"
Expand All @@ -11,10 +12,12 @@ import (
)

var createVolume struct {
reqBytes int64
limBytes int64
caps volumeCapabilitySliceArg
params mapOfStringArg
reqBytes int64
limBytes int64
caps volumeCapabilitySliceArg
params mapOfStringArg
sourceVol string
sourceSnap string
}

var createVolumeCmd = &cobra.Command{
Expand Down Expand Up @@ -52,6 +55,28 @@ CREATING MULTIPLE VOLUMES
}
}

if createVolume.sourceVol != "" && createVolume.sourceSnap != "" {
return errors.New(
"--source-volume and --source-snapshot are mutually exclusive")
}
if createVolume.sourceVol != "" {
req.VolumeContentSource = &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Volume{
Volume: &csi.VolumeContentSource_VolumeSource{
VolumeId: createVolume.sourceVol,
},
},
}
} else if createVolume.sourceSnap != "" {
req.VolumeContentSource = &csi.VolumeContentSource{
Type: &csi.VolumeContentSource_Snapshot{
Snapshot: &csi.VolumeContentSource_SnapshotSource{
SnapshotId: createVolume.sourceSnap,
},
},
}
}

for i := range args {
ctx, cancel := context.WithTimeout(root.ctx, root.timeout)
defer cancel()
Expand Down Expand Up @@ -84,6 +109,18 @@ func init() {

flagVolumeCapabilities(createVolumeCmd.Flags(), &createVolume.caps)

createVolumeCmd.Flags().StringVar(
&createVolume.sourceVol,
"source-volume",
"",
"Pre-populate data using a source volume")

createVolumeCmd.Flags().StringVar(
&createVolume.sourceSnap,
"source-snapshot",
"",
"Pre-populate data using a source snapshot")

flagWithRequiresVolContext(
createVolumeCmd.Flags(),
&root.withRequiresVolContext,
Expand Down

0 comments on commit 632c7b6

Please sign in to comment.