Merge pull request #115254 from dims/do-not-use-global-variable-for-etcd-url

Do not use a global variable for etcdURL
This commit is contained in:
Kubernetes Prow Robot 2023-01-22 15:26:15 -08:00 committed by GitHub
commit bec431642e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,8 +36,6 @@ import (
"k8s.io/kubernetes/pkg/util/env" "k8s.io/kubernetes/pkg/util/env"
) )
var etcdURL = ""
const installEtcd = ` const installEtcd = `
Cannot find etcd, cannot run integration tests 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. 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") 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://")) conn, err := net.Dial("tcp", strings.TrimPrefix(etcdURL, "http://"))
if err == nil { if err == nil {
klog.Infof("etcd already running at %s", etcdURL) klog.Infof("etcd already running at %s", etcdURL)
@ -84,8 +82,7 @@ func startEtcd() (func(), error) {
return nil, err return nil, err
} }
etcdURL = currentURL os.Setenv("KUBE_INTEGRATION_ETCD_URL", currentURL)
os.Setenv("KUBE_INTEGRATION_ETCD_URL", etcdURL)
return stop, nil return stop, nil
} }
@ -221,5 +218,5 @@ func EtcdMain(tests func() int) {
// GetEtcdURL returns the URL of the etcd instance started by EtcdMain. // GetEtcdURL returns the URL of the etcd instance started by EtcdMain.
func GetEtcdURL() string { func GetEtcdURL() string {
return etcdURL return env.GetEnvAsStringOrFallback("KUBE_INTEGRATION_ETCD_URL", "http://127.0.0.1:2379")
} }