<p>I am using glog flag log_dir in my project. Recently I imported kubernetes library and started getting this runtime panic</p>

<p>panic: ./aaa.test flag redefined: log_dir</p>

<pre><code>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
</code></pre>

<p>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? </p>

<p>That error doesn't have to do with conflicting libraries, it is a conflicting flag (<code>log_dir</code>). It means you're adding a "--log_dir" flag, and the glog library used by kubernetes also has a <code>log_dir</code> 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 <code>flag.CommandLine</code> global variable to point to a different <code>flag.FlagSet</code> when you import your log library or kubernetes, but that will be tricky since it depends on import ordering.</p>
