diff --git a/pkg/manager/service.go b/pkg/manager/service.go index 36ba789d..e1b9f667 100644 --- a/pkg/manager/service.go +++ b/pkg/manager/service.go @@ -500,9 +500,9 @@ func (m *Manager) PrepareDownload(ctx context.Context, req *rpc.PrepareDownloadR return nil, status.Errorf(codes.FailedPrecondition, "invalid backing image state %v for the download", bi.Status.State) } - address, err := util.ConvertToStorageAddress(m.syncAddress) + address, err := util.GetSyncServiceAddressWithPodIP(m.syncAddress) if err != nil { - return nil, status.Errorf(codes.Unknown, "failed to detect the storage address of the sync server for the download: %v", err) + return nil, status.Errorf(codes.Internal, "failed to get sync service address: %v", err) } srcFilePath := types.GetBackingImageFilePath(m.diskPath, req.Name, req.Uuid) diff --git a/pkg/util/http_util.go b/pkg/util/http_util.go index ae13c693..38b6491d 100644 --- a/pkg/util/http_util.go +++ b/pkg/util/http_util.go @@ -96,33 +96,11 @@ func GetLocalIPv4fromInterface(name string) (ip string, err error) { return ipv4.String(), nil } -func IsLoopbackHost(host string) bool { - if host == "localhost" || host == "127.0.0.1" || host == "0.0.0.0" || host == "::1" || host == "" { - return true - } - // Check for loopback network. - ips, err := net.LookupIP(host) - if err != nil { - return false - } - for _, ip := range ips { - if !ip.IsLoopback() { - return false - } - } - return true -} - -func ConvertToStorageAddress(address string) (string, error) { - host, port, err := net.SplitHostPort(address) +func GetSyncServiceAddressWithPodIP(address string) (string, error) { + _, port, err := net.SplitHostPort(address) if err != nil { return "", err } - if IsLoopbackHost(host) { - host, err = GetIPForPod() - if err != nil { - return "", err - } - } - return net.JoinHostPort(host, port), nil + podIP := os.Getenv(EnvPodIP) + return net.JoinHostPort(podIP, port), nil }