mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

The following PR is the leading PR for refactoring podman machine with the following goals: * less duplication/more re-use * common configuration file between providers * more consistentency in how machines are handled by providers The goal of this PR is the rough refactor. There are still rough spots for sure, specifically around the podman socket and pipe. This implemention is only for Linux. All other providers are still present but will not compile or work. This is why tests for them have been temporarily suspended. The ready socket code is another area that needs to be smoothed over. Right now, the ready socket code is still in QEMU. Preferably it would be moved to a generic spot where all three approaches to readiness socket use can be defined. It should also be noted: * all machine related tests pass. * make validate for Linux passes * Apple QEMU was largely removed * More code pruning is possible; will become clearer when other providers are complete. the dir pkg/machine/p5 is not permanent. i had to seperate this from machine initially due to circular import problems. i think when all providers are done (or nearly done), it can be placed and named properly. Signed-off-by: Brent Baude <bbaude@redhat.com>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package command
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/containers/common/libnetwork/etchosts"
|
|
"github.com/containers/common/pkg/config"
|
|
"github.com/containers/podman/v4/pkg/machine/define"
|
|
)
|
|
|
|
func GetProxyVariables() map[string]string {
|
|
proxyOpts := make(map[string]string)
|
|
for _, variable := range config.ProxyEnv {
|
|
if value, ok := os.LookupEnv(variable); ok {
|
|
if value == "" {
|
|
continue
|
|
}
|
|
|
|
v := strings.ReplaceAll(value, "127.0.0.1", etchosts.HostContainersInternal)
|
|
v = strings.ReplaceAll(v, "localhost", etchosts.HostContainersInternal)
|
|
proxyOpts[variable] = v
|
|
}
|
|
}
|
|
return proxyOpts
|
|
}
|
|
|
|
// PropagateHostEnv is here for providing the ability to propagate
|
|
// proxy and SSL settings (e.g. HTTP_PROXY and others) on a start
|
|
// and avoid a need of re-creating/re-initiating a VM
|
|
func PropagateHostEnv(cmdLine QemuCmd) QemuCmd {
|
|
varsToPropagate := make([]string, 0)
|
|
|
|
for k, v := range GetProxyVariables() {
|
|
varsToPropagate = append(varsToPropagate, fmt.Sprintf("%s=%q", k, v))
|
|
}
|
|
|
|
if sslCertFile, ok := os.LookupEnv("SSL_CERT_FILE"); ok {
|
|
pathInVM := filepath.Join(define.UserCertsTargetPath, filepath.Base(sslCertFile))
|
|
varsToPropagate = append(varsToPropagate, fmt.Sprintf("%s=%q", "SSL_CERT_FILE", pathInVM))
|
|
}
|
|
|
|
if _, ok := os.LookupEnv("SSL_CERT_DIR"); ok {
|
|
varsToPropagate = append(varsToPropagate, fmt.Sprintf("%s=%q", "SSL_CERT_DIR", define.UserCertsTargetPath))
|
|
}
|
|
|
|
if len(varsToPropagate) > 0 {
|
|
prefix := "name=opt/com.coreos/environment,string="
|
|
envVarsJoined := strings.Join(varsToPropagate, "|")
|
|
fwCfgArg := prefix + base64.StdEncoding.EncodeToString([]byte(envVarsJoined))
|
|
return append(cmdLine, "-fw_cfg", fwCfgArg)
|
|
}
|
|
|
|
return cmdLine
|
|
}
|