@@ -18,6 +18,7 @@ package hostpath
1818
1919import (
2020 "fmt"
21+ "os"
2122
2223 "github.com/golang/glog"
2324
@@ -33,6 +34,10 @@ const (
3334 tib100 int64 = tib * 100
3435)
3536
37+ const (
38+ volumeRoot = "/tmp"
39+ )
40+
3641type hostPath struct {
3742 name string
3843 nodeID string
@@ -102,13 +107,10 @@ func NewHostPathDriver(driverName, nodeID, endpoint string, ephemeral bool) (*ho
102107func (hp * hostPath ) Run () {
103108 s := NewNonBlockingGRPCServer ()
104109
105- hp .ids = nil
106- hp .cs = nil
110+ hp .ids = NewIdentityServer (hp .name , hp .version )
107111 hp .ns = NewNodeServer (hp .nodeID , hp .ephemeral )
108- if ! hp .ephemeral {
109- hp .ids = NewIdentityServer (hp .name , hp .version )
110- hp .cs = NewControllerServer ()
111- }
112+ hp .cs = NewControllerServer (hp .ephemeral )
113+
112114 s .Start (hp .endpoint , hp .ids , hp .cs , hp .ns )
113115 s .Wait ()
114116}
@@ -137,3 +139,29 @@ func getSnapshotByName(name string) (hostPathSnapshot, error) {
137139 }
138140 return hostPathSnapshot {}, fmt .Errorf ("snapshot name %s does not exit in the snapshots list" , name )
139141}
142+
143+ // getVolumePath returs the canonical path for hostpath volume
144+ func getVolumePath (volID string ) string {
145+ return fmt .Sprintf ("%s/%s" , volumeRoot , volID )
146+ }
147+
148+ // createVolume create the directory for the hostpath volume.
149+ // It returns the volume path or err if one occurs.
150+ func createVolumeDir (volID string ) (string , error ) {
151+ path := getVolumePath (volID )
152+ err := os .MkdirAll (path , 0777 )
153+ if err != nil {
154+ return "" , err
155+ }
156+
157+ return path , nil
158+ }
159+
160+ // deleteVolume deletes the directory for the hostpath volume.
161+ func deleteVolumeDir (volID string ) error {
162+ path := getVolumePath (volID )
163+ if err := os .RemoveAll (path ); err != nil {
164+ return err
165+ }
166+ return nil
167+ }
0 commit comments