-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (61 loc) · 1.8 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
72
73
74
package main
import (
"cni-wrapper-plugin/lib"
"flag"
"io/ioutil"
"os"
"path/filepath"
"strings"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/silk/lib/adapter"
)
func main() {
logger := lager.NewLogger("cni-teardown")
sink := lager.NewWriterSink(os.Stdout, lager.INFO)
logger.RegisterSink(sink)
logger.Info("starting")
netlinkAdapter := &adapter.NetlinkAdapter{}
links, err := netlinkAdapter.LinkList()
if err != nil {
logger.Error("failed-to-list-network-devices", err) // not tested
}
for _, link := range links {
if link.Type() == "ifb" && strings.HasPrefix(link.Attrs().Name, "i") {
err = netlinkAdapter.LinkDel(link)
if err != nil {
logger.Error("failed-to-remove-ifb", err)
}
}
}
configFilePath := flag.String("config", "", "path to config file")
flag.Parse()
configBytes, err := ioutil.ReadFile(*configFilePath)
if err != nil {
logger.Error("load-config-file", err)
os.Exit(1)
}
cfg, err := lib.LoadWrapperConfig(configBytes)
if err != nil {
logger.Error("read-config-file", err)
os.Exit(1)
}
containerMetadataDir := filepath.Dir(cfg.Datastore)
err = os.RemoveAll(containerMetadataDir)
if err != nil {
logger.Info("failed-to-remove-datastore-path", lager.Data{"path": containerMetadataDir, "err": err})
}
if delegateDataDirPath, ok := cfg.Delegate["dataDir"].(string); ok {
err = os.RemoveAll(delegateDataDirPath)
if err != nil {
logger.Info("failed-to-remove-delegate-datastore-path", lager.Data{"path": delegateDataDirPath, "err": err})
}
}
if delegateDataStorePath, ok := cfg.Delegate["datastore"].(string); ok {
silkDir := filepath.Dir(delegateDataStorePath)
err = os.RemoveAll(silkDir)
if err != nil {
logger.Info("failed-to-remove-delegate-data-dir-path", lager.Data{"path": silkDir, "err": err})
}
}
logger.Info("complete")
}