Do not use a global variable for etcdURL

we are saving this information in an env variable `KUBE_INTEGRATION_ETCD_URL`

So just pick it up from there when needed. Currently when someone uses
framework.RunCustomEtcd directly, the global variable is *not* set and the
code that uses `GetEtcdURL` returns empty string.

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2023-01-22 14:11:21 -05:00
parent 1e3cc23b9f
commit 1671efe7a8
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59

View File

@ -36,8 +36,6 @@ import (
"k8s.io/kubernetes/pkg/util/env"
)
var etcdURL = ""
const installEtcd = `
Cannot find etcd, cannot run integration tests
Please see https://git.k8s.io/community/contributors/devel/sig-testing/integration-tests.md#install-etcd-dependency for instructions.
@ -70,7 +68,7 @@ func startEtcd() (func(), error) {
os.Setenv("ETCD_UNSUPPORTED_ARCH", "arm64")
}
etcdURL = env.GetEnvAsStringOrFallback("KUBE_INTEGRATION_ETCD_URL", "http://127.0.0.1:2379")
etcdURL := env.GetEnvAsStringOrFallback("KUBE_INTEGRATION_ETCD_URL", "http://127.0.0.1:2379")
conn, err := net.Dial("tcp", strings.TrimPrefix(etcdURL, "http://"))
if err == nil {
klog.Infof("etcd already running at %s", etcdURL)
@ -84,8 +82,7 @@ func startEtcd() (func(), error) {
return nil, err
}
etcdURL = currentURL
os.Setenv("KUBE_INTEGRATION_ETCD_URL", etcdURL)
os.Setenv("KUBE_INTEGRATION_ETCD_URL", currentURL)
return stop, nil
}
@ -221,5 +218,5 @@ func EtcdMain(tests func() int) {
// GetEtcdURL returns the URL of the etcd instance started by EtcdMain.
func GetEtcdURL() string {
return etcdURL
return env.GetEnvAsStringOrFallback("KUBE_INTEGRATION_ETCD_URL", "http://127.0.0.1:2379")
}