From 04a1cdfa966121bc3dfba99aeac9f353396f5d44 Mon Sep 17 00:00:00 2001 From: Black-Hole1 Date: Wed, 21 Jun 2023 18:46:30 +0800 Subject: [PATCH] refactor(machine): remove hard code Use exported variables instead of hard-coded strings. Ref: https://github.com/containers/common/pull/1516 Signed-off-by: Black-Hole1 --- pkg/machine/ignition.go | 6 +++--- pkg/machine/qemu/machine_test.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/machine/ignition.go b/pkg/machine/ignition.go index c937a5be44..4b5bdf521c 100644 --- a/pkg/machine/ignition.go +++ b/pkg/machine/ignition.go @@ -12,6 +12,7 @@ import ( "path/filepath" "strings" + "github.com/containers/common/libnetwork/etchosts" "github.com/containers/common/pkg/config" "github.com/sirupsen/logrus" ) @@ -618,9 +619,8 @@ func GetProxyVariables() map[string]string { continue } - // TODO: use constants for host.containers.internal - v := strings.ReplaceAll(value, "127.0.0.1", "host.containers.internal") - v = strings.ReplaceAll(v, "localhost", "host.containers.internal") + v := strings.ReplaceAll(value, "127.0.0.1", etchosts.HostContainersInternal) + v = strings.ReplaceAll(v, "localhost", etchosts.HostContainersInternal) proxyOpts[variable] = v } } diff --git a/pkg/machine/qemu/machine_test.go b/pkg/machine/qemu/machine_test.go index 20fa7f274c..18cb21f921 100644 --- a/pkg/machine/qemu/machine_test.go +++ b/pkg/machine/qemu/machine_test.go @@ -9,6 +9,7 @@ import ( "strings" "testing" + "github.com/containers/common/libnetwork/etchosts" "github.com/containers/podman/v4/pkg/machine" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -55,11 +56,11 @@ func TestPropagateHostEnv(t *testing.T) { }, "http_proxy": { "127.0.0.1:8888", - "host.containers.internal:8888", + fmt.Sprintf("%s:8888", etchosts.HostContainersInternal), }, "https_proxy": { "localhost:8888", - "host.containers.internal:8888", + fmt.Sprintf("%s:8888", etchosts.HostContainersInternal), }, "SSL_CERT_FILE": { "/some/f=oo.cert",