Skip to content

Commit 4235b0a

Browse files
discover existing snapshots on disk
Signed-off-by: Ashish Amarnath <[email protected]>
1 parent 49cddb8 commit 4235b0a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pkg/hostpath/hostpath.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"os"
2424
"path/filepath"
25+
"strings"
2526

2627
"github.com/golang/glog"
2728
"google.golang.org/grpc/codes"
@@ -127,12 +128,42 @@ func NewHostPathDriver(driverName, nodeID, endpoint string, ephemeral bool, maxV
127128
}, nil
128129
}
129130

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+
130160
func (hp *hostPath) Run() {
131161
// Create GRPC servers
132162
hp.ids = NewIdentityServer(hp.name, hp.version)
133163
hp.ns = NewNodeServer(hp.nodeID, hp.ephemeral, hp.maxVolumesPerNode)
134164
hp.cs = NewControllerServer(hp.ephemeral, hp.nodeID)
135165

166+
discoverExistingSnapshots()
136167
s := NewNonBlockingGRPCServer()
137168
s.Start(hp.endpoint, hp.ids, hp.cs, hp.ns)
138169
s.Wait()

0 commit comments

Comments
 (0)