-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (66 loc) · 1.73 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"flag"
"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc"
"k8s.io/klog"
"os"
)
var (
endpoint = flag.String("endpoint", "unix:///tmp/csi.sock", "CSI endpoint")
)
func main() {
klog.InitFlags(nil)
flag.Parse()
conn, err := grpc.Dial(*endpoint,
grpc.WithInsecure())
// grpc.WithKeepaliveParams(keepalive.ClientParameters{PermitWithoutStream: true}))
if err != nil{
klog.Errorf("error connecting to CSI driver: %v", err)
os.Exit(1)
}
defer conn.Close()
DeleteSnapshot(csi.NewControllerClient(conn))
}
func DeleteSnapshot(cc csi.ControllerClient){
volReq:=&csi.CreateVolumeRequest{
Name: "csi-client",
VolumeCapabilities: []*csi.VolumeCapability{
&csi.VolumeCapability{
AccessType: nil,
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
}
volResp, err := cc.CreateVolume(context.Background(),volReq)
if err != nil{
klog.Error(err)
}
snapReq := &csi.CreateSnapshotRequest{
SourceVolumeId: volResp.Volume.VolumeId,
Name: "csi-client",
}
snapResp, err := cc.CreateSnapshot(context.Background(), snapReq)
if err != nil{
klog.Error(err)
}
snapDelReq := &csi.DeleteSnapshotRequest{
SnapshotId: snapResp.Snapshot.SnapshotId,
}
snapDelResp, err := cc.DeleteSnapshot(context.Background(), snapDelReq)
if err != nil{
klog.Error(err)
}
klog.Info(snapDelResp)
volDelReq := &csi.DeleteVolumeRequest{
VolumeId: volResp.Volume.GetVolumeId(),
}
volDelResp, err := cc.DeleteVolume(context.Background(), volDelReq)
if err != nil{
klog.Error(err)
}
klog.Info(volDelResp)
}