@@ -2,6 +2,7 @@ package cmd
22
33import (
44 "context"
5+ "errors"
56 "os"
67
78 log "github.com/sirupsen/logrus"
@@ -11,10 +12,12 @@ import (
1112)
1213
1314var createVolume struct {
14- reqBytes int64
15- limBytes int64
16- caps volumeCapabilitySliceArg
17- params mapOfStringArg
15+ reqBytes int64
16+ limBytes int64
17+ caps volumeCapabilitySliceArg
18+ params mapOfStringArg
19+ sourceVol string
20+ sourceSnap string
1821}
1922
2023var createVolumeCmd = & cobra.Command {
@@ -52,6 +55,28 @@ CREATING MULTIPLE VOLUMES
5255 }
5356 }
5457
58+ if createVolume .sourceVol != "" && createVolume .sourceSnap != "" {
59+ return errors .New (
60+ "--source-volume and --source-snapshot are mutually exclusive" )
61+ }
62+ if createVolume .sourceVol != "" {
63+ req .VolumeContentSource = & csi.VolumeContentSource {
64+ Type : & csi.VolumeContentSource_Volume {
65+ Volume : & csi.VolumeContentSource_VolumeSource {
66+ VolumeId : createVolume .sourceVol ,
67+ },
68+ },
69+ }
70+ } else if createVolume .sourceSnap != "" {
71+ req .VolumeContentSource = & csi.VolumeContentSource {
72+ Type : & csi.VolumeContentSource_Snapshot {
73+ Snapshot : & csi.VolumeContentSource_SnapshotSource {
74+ SnapshotId : createVolume .sourceSnap ,
75+ },
76+ },
77+ }
78+ }
79+
5580 for i := range args {
5681 ctx , cancel := context .WithTimeout (root .ctx , root .timeout )
5782 defer cancel ()
@@ -84,6 +109,18 @@ func init() {
84109
85110 flagVolumeCapabilities (createVolumeCmd .Flags (), & createVolume .caps )
86111
112+ createVolumeCmd .Flags ().StringVar (
113+ & createVolume .sourceVol ,
114+ "source-volume" ,
115+ "" ,
116+ "Pre-populate data using a source volume" )
117+
118+ createVolumeCmd .Flags ().StringVar (
119+ & createVolume .sourceSnap ,
120+ "source-snapshot" ,
121+ "" ,
122+ "Pre-populate data using a source snapshot" )
123+
87124 flagWithRequiresVolContext (
88125 createVolumeCmd .Flags (),
89126 & root .withRequiresVolContext ,
0 commit comments