I am using glog flag log_dir in my project. Recently I imported kubernetes library and started getting this runtime panic
panic: ./aaa.test flag redefined: log_dir
May 16 23:51:35 ecmdev03-core01 docker[26867]: goroutine 1 [running]:
May 16 23:51:35 ecmdev03-core01 docker[26867]: panic(0x15ebc60, 0xc8201aae90)
May 16 23:51:35 ecmdev03-core01 docker[26867]: /usr/local/go/src/runtime/panic.go:464 +0x3e6
May 16 23:51:35 ecmdev03-core01 docker[26867]: flag.(*FlagSet).Var(0xc8200160c0, 0x7f561118c1c0, 0xc8201aae40, 0x1bddd70, 0x7, 0x1d75860, 0x2f)
May 16 23:51:35 ecmdev03-core01 docker[26867]: /usr/local/go/src/flag/flag.go:776 +0x454
May 16 23:51:35 ecmdev03-core01 docker[26867]: flag.(*FlagSet).StringVar(0xc8200160c0, 0xc8201aae40, 0x1bddd70, 0x7, 0x0, 0x0, 0x1d75860, 0x2f)
May 16 23:51:35 ecmdev03-core01 docker[26867]: /usr/local/go/src/flag/flag.go:679 +0xc7
May 16 23:51:35 ecmdev03-core01 docker[26867]: flag.(*FlagSet).String(0xc8200160c0, 0x1bddd70, 0x7, 0x0, 0x0, 0x1d75860, 0x2f, 0xc8201aae30)
May 16 23:51:35 ecmdev03-core01 docker[26867]: /usr/local/go/src/flag/flag.go:692 +0x83
May 16 23:51:35 ecmdev03-core01 docker[26867]: flag.String(0x1bddd70, 0x7, 0x0, 0x0, 0x1d75860, 0x2f, 0xba3950)
May 16 23:51:35 ecmdev03-core01 docker[26867]: /usr/local/go/src/flag/flag.go:699 +0x5f
May 16 23:51:35 ecmdev03-core01 docker[26867]: k8s.io/kubernetes/vendor/github.com/golang/glog.init()
May 16 23:51:35 ecmdev03-core01 docker[26867]: /src/ecm_infra/go/src/k8s.io/kubernetes/vendor/github.com/golang/glog/glog_file.go:41 +0x13e
May 16 23:51:35 ecmdev03-core01 docker[26867]: k8s.io/kubernetes/pkg/labels.init()
May 16 23:51:35 ecmdev03-core01 docker[26867]: /src/ecm_infra/go/src/k8s.io/kubernetes/pkg/labels/selector.go:810 +0x6b
May 16 23:51:35 ecmdev03-core01 docker[26867]: k8s.io/kubernetes/pkg/api/unversioned.init()
May 16 23:51:35 ecmdev03-core01 docker[26867]: /src/ecm_infra/go/src/k8s.io/kubernetes/pkg/api/unversioned/well_known_labels.go:30 +0x6f
May 16 23:51:35 ecmdev03-core01 docker[26867]: k8s.io/kubernetes/pkg/api.init()
May 16 23:51:35 ecmdev03-core01 docker[26867]: /src/ecm_infra/go/src/k8s.io/kubernetes/pkg/api/types.go:2731 +0x64
It looks like glog library which is vendored by k8s is conflicting with the one that I am using. Is introducing vendor directory a solution for this problem? Should I use vendoring libraries like glide, govendor, gb etc? If yes, which one is preferred?
That error doesn't have to do with conflicting libraries, it is a conflicting flag (log_dir
). It means you're adding a "--log_dir" flag, and the glog library used by kubernetes also has a log_dir
flag. This is a problem with adding flags in libraries during package init. Unfortunately vendoring won't change anything. You might be able to work around this by manipulating the flag.CommandLine
global variable to point to a different flag.FlagSet
when you import your log library or kubernetes, but that will be tricky since it depends on import ordering.