ethereum / go-ethereum

Go implementation of the Ethereum protocol
https://geth.ethereum.org
GNU Lesser General Public License v3.0
46.66k stars 19.67k forks source link

Custom prefix for env vars #29779

Open exodus-justinz opened 1 month ago

exodus-justinz commented 1 month ago

Rationale

Currently, we have GETH_ prefix for all env vars. It may cause some conflicts with k8s service env vars if there's a geth service on the same namespace.

An example would be

GETH_PORT=tcp:<IP>:<PORT>

Implementation

On ./cmd/geth/main.go, we have the following

flags.AutoEnvVars(app.Flags, "GETH")

Maybe we can get the prefix from an environment variable with GETH as default?

exodus-justinz commented 1 month ago

this is also happening on BSC https://github.com/bnb-chain/bsc/issues/2456

holiman commented 1 month ago

This issue is further exacerbated by https://github.com/ethereum/go-ethereum/issues/28216, making it so that it's not actually possible to execute a geth node under such circumstances.

zzzckck commented 1 month ago

How about add a new env: "GETH_ENV_PREFIX" to solve @exodus-justinz 's issue. https://github.com/ethereum/go-ethereum/blob/master/cmd/geth/main.go#L261 like:

    gethPrefix := "GETH"
    if os.env.GETH_ENV_PREFIX != "" { // mock code
        vgethPrefix = os.env.GETH_ENV_PREFIX
    }
    flags.AutoEnvVars(app.Flags, gethPrefix)
holiman commented 1 month ago

How about add a new env: "GETH_ENV_PREFIX"

Hm, I think I'd prefer making a simple solution rather than making things even more elaborate. Let users disable it if it gets in the way. Maybe something like this:

    if os.Getenv("GETH_DISABLE_ENVVARS") == "" {
        flags.AutoEnvVars(app.Flags, "GETH")
    }
karalabe commented 1 month ago

I'm a bit reluctant to do anything here. IMO this is not a Geth issue, this is a Kubernetes "issue". The same clash happens across the entire k8s ecosystem with tons of different projects (e.g. postgres). The solution isn't to hack every project out there to cater for k8s' weird env var injection. My 2c is that if k8s clashes with guest projects through some auto-generated env vars, then the k8s environment needs to be fixed (in this case, not naming the pod geth).