@@ -22,6 +22,7 @@ import (
22
22
"io"
23
23
"os"
24
24
"path/filepath"
25
+ "strings"
25
26
26
27
"github.com/golang/glog"
27
28
"google.golang.org/grpc/codes"
@@ -127,12 +128,42 @@ func NewHostPathDriver(driverName, nodeID, endpoint string, ephemeral bool, maxV
127
128
}, nil
128
129
}
129
130
131
+ func discoverExistingSnapshots () {
132
+ glog .V (4 ).Infof ("discovering existing snapshots in %s" , dataRoot )
133
+ snapshots := []string {}
134
+ err := filepath .Walk (dataRoot , func (path string , info os.FileInfo , err error ) error {
135
+ glog .V (6 ).Infof ("path: %s" , path )
136
+ if filepath .Ext (path ) == ".tgz" {
137
+ snapshots = append (snapshots , path )
138
+ }
139
+ return nil
140
+ })
141
+
142
+ if err != nil {
143
+ glog .Errorf ("failed to discover snapshots under %s" , dataRoot )
144
+ return
145
+ }
146
+
147
+ for _ , snap := range snapshots {
148
+ pathSplit := strings .Split (snap , "." )[0 ]
149
+ split := strings .Split (pathSplit , "/" )
150
+ id := split [len (split )- 1 ]
151
+ glog .V (4 ).Infof ("snapshot: %s, id: %s" , snap , id )
152
+ hostPathVolumeSnapshots [id ] = hostPathSnapshot {
153
+ Id : id ,
154
+ Path : snap ,
155
+ ReadyToUse : true ,
156
+ }
157
+ }
158
+ }
159
+
130
160
func (hp * hostPath ) Run () {
131
161
// Create GRPC servers
132
162
hp .ids = NewIdentityServer (hp .name , hp .version )
133
163
hp .ns = NewNodeServer (hp .nodeID , hp .ephemeral , hp .maxVolumesPerNode )
134
164
hp .cs = NewControllerServer (hp .ephemeral , hp .nodeID )
135
165
166
+ discoverExistingSnapshots ()
136
167
s := NewNonBlockingGRPCServer ()
137
168
s .Start (hp .endpoint , hp .ids , hp .cs , hp .ns )
138
169
s .Wait ()
0 commit comments