Search code examples
gokubernetesgo-flag

flag redefined: Can two components have same flag variable


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


Solution

  • 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.