标志重定义:两个组件可以有相同的标志变量吗?

huangapple go评论83阅读模式
英文:

flag redefined: Can two components have same flag variable

问题

我有一个包含5个容器的部署。其中两个容器的--endpoint参数的值是从ENV中设置的。

所以在部署后我看到了以下错误:

/home/xxx-csi-drivers/xxx-vpc-block-csi-driver flag redefined: endpoint
panic: /home/xxx-csi-drivers/xxx-vpc-block-csi-driver flag redefined: endpoint

容器A的构建代码中有以下内容:

endpoint = flag.String("endpoint", "/tmp/storage-secret-sidecar.sock", "Storage secret sidecar endpoint")

而容器B的构建代码中也有以下内容:

endpoint       = flag.String("endpoint", "unix:/tmp/csi.sock", "CSI endpoint")

在代码中定义相同的变量endpoint是导致上述错误的原因吗?

我尝试过更改deployment文件中的参数名称和其他选项,但没有帮助。但是更改代码中的flag名称修复了问题,但需要更多了解其工作原理。所以我发布了这个问题。

英文:

I have a deployment with 5 containers.
Among them two of them have --endpoint as argument for which value is set from ENV

So I see this error after deployment

/home/xxx-csi-drivers/xxx-vpc-block-csi-driver flag redefined: endpoint
panic: /home/xxx-csi-drivers/xxx-vpc-block-csi-driver flag redefined: endpoint

The code from which container A is build has

endpoint = flag.String("endpoint", "/tmp/storage-secret-sidecar.sock", "Storage secret sidecar endpoint")

also
The code from which container B is build also has

endpoint       = flag.String("endpoint", "unix:/tmp/csi.sock", "CSI endpoint")

Is defining the same var endpoint in the code reason for the above bug.

I have tried changing arg names in deployment file. and other options which didnt help. But changing flag name in code fixed the issue but need to undersatnd more on working. So posted this question

答案1

得分: 3

这与不同的容器无关。无论哪个进程崩溃,都只是出现了问题,代码中有一个错误,它注册了相同的标志两次,这是不允许的。

英文:

It has nothing to do with the different containers. Whichever process is crashing is just broken, the code has a bug where it registers the same flag twice which isn't allowed.

huangapple
  • 本文由 发表于 2021年6月7日 12:50:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/67866087.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定