diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 0d52db44ac6f..3435f7a88634 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -56,7 +56,6 @@ import ( "k8s.io/minikube/pkg/minikube/node" "k8s.io/minikube/pkg/minikube/notify" "k8s.io/minikube/pkg/minikube/out" - "k8s.io/minikube/pkg/minikube/proxy" "k8s.io/minikube/pkg/minikube/registry" "k8s.io/minikube/pkg/minikube/translate" "k8s.io/minikube/pkg/util" @@ -909,24 +908,6 @@ func createNode(cc config.ClusterConfig, kubeNodeName string, existing *config.C return cc, cp, nil } -// setDockerProxy sets the proxy environment variables in the docker environment. -func setDockerProxy() { - for _, k := range proxy.EnvVars { - if v := os.Getenv(k); v != "" { - // convert https_proxy to HTTPS_PROXY for linux - // TODO (@medyagh): if user has both http_proxy & HTTPS_PROXY set merge them. - k = strings.ToUpper(k) - if k == "HTTP_PROXY" || k == "HTTPS_PROXY" { - if strings.HasPrefix(v, "localhost") || strings.HasPrefix(v, "127.0") { - out.WarningT("Not passing {{.name}}={{.value}} to docker env.", out.V{"name": k, "value": v}) - continue - } - } - config.DockerEnv = append(config.DockerEnv, fmt.Sprintf("%s=%s", k, v)) - } - } -} - // autoSetDriverOptions sets the options needed for specific driver automatically. func autoSetDriverOptions(cmd *cobra.Command, drvName string) (err error) { err = nil diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 582f85021c51..de41ab180aa3 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -36,6 +36,7 @@ import ( "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/out" + "k8s.io/minikube/pkg/minikube/proxy" pkgutil "k8s.io/minikube/pkg/util" "k8s.io/minikube/pkg/version" ) @@ -341,7 +342,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k // Feed Docker our host proxy environment by default, so that it can pull images // doing this for both new config and existing, in case proxy changed since previous start if _, ok := r.(*cruntime.Docker); ok && !cmd.Flags().Changed("docker-env") { - setDockerProxy() + proxy.SetDockerEnv() } var kubeNodeName string diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index e44ad685fd18..be0d1f84f8bd 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -39,6 +39,7 @@ import ( "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/localpath" "k8s.io/minikube/pkg/minikube/out" + "k8s.io/minikube/pkg/minikube/proxy" "k8s.io/minikube/pkg/minikube/registry" "k8s.io/minikube/pkg/minikube/vmpath" "k8s.io/minikube/pkg/util/lock" @@ -89,9 +90,28 @@ func StartHost(api libmachine.API, cfg config.ClusterConfig, n config.Node) (*ho return h, exists, err } +// engineOptions returns docker engine options for the dockerd running inside minikube func engineOptions(cfg config.ClusterConfig) *engine.Options { + // get docker env from user's proxy settings + dockerEnv := proxy.SetDockerEnv() + // get docker env from user specifiec config + dockerEnv = append(dockerEnv, cfg.DockerEnv...) + + // remove duplicates + seen := map[string]bool{} + uniqueEnvs := []string{} + for e := range dockerEnv { + if !seen[dockerEnv[e]] { + seen[dockerEnv[e]] = true + uniqueEnvs = append(uniqueEnvs, dockerEnv[e]) + } + } + + // config.DockerEnv is a global so we update that one too + config.DockerEnv = uniqueEnvs + o := engine.Options{ - Env: cfg.DockerEnv, + Env: uniqueEnvs, InsecureRegistry: append([]string{constants.DefaultServiceCIDR}, cfg.InsecureRegistry...), RegistryMirror: cfg.RegistryMirror, ArbitraryFlags: cfg.DockerOpt, diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go index e8b90a66f007..24b0fc3c3886 100644 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -410,7 +410,8 @@ func validateNetwork(h *host.Host, r command.Runner, imageRepository string) (st ipExcluded := proxy.IsIPExcluded(ip) // Skip warning if minikube ip is already in NO_PROXY k = strings.ToUpper(k) // for http_proxy & https_proxy if (k == "HTTP_PROXY" || k == "HTTPS_PROXY") && !ipExcluded && !warnedOnce { - out.WarningT("You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP ({{.ip_address}}). Please see {{.documentation_url}} for more details", out.V{"ip_address": ip, "documentation_url": "https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/"}) + out.WarningT("You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP ({{.ip_address}}).", out.V{"ip_address": ip}) + out.T(out.Documentation, "Please see {{.documentation_url}} for more details", out.V{"documentation_url": "https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/"}) warnedOnce = true } } diff --git a/pkg/minikube/proxy/proxy.go b/pkg/minikube/proxy/proxy.go index c6a539a8a38a..0c95f2325843 100644 --- a/pkg/minikube/proxy/proxy.go +++ b/pkg/minikube/proxy/proxy.go @@ -26,6 +26,8 @@ import ( "github.com/golang/glog" "github.com/pkg/errors" "k8s.io/client-go/rest" + "k8s.io/minikube/pkg/minikube/config" + "k8s.io/minikube/pkg/minikube/out" ) // EnvVars are variables we plumb through to the underlying container runtime @@ -149,3 +151,22 @@ func UpdateTransport(cfg *rest.Config) *rest.Config { } return cfg } + +// SetDockerEnv sets the proxy environment variables in the docker environment. +func SetDockerEnv() []string { + for _, k := range EnvVars { + if v := os.Getenv(k); v != "" { + // convert https_proxy to HTTPS_PROXY for linux + // TODO (@medyagh): if user has both http_proxy & HTTPS_PROXY set merge them. + k = strings.ToUpper(k) + if k == "HTTP_PROXY" || k == "HTTPS_PROXY" { + if strings.HasPrefix(v, "localhost") || strings.HasPrefix(v, "127.0") { + out.WarningT("Not passing {{.name}}={{.value}} to docker env.", out.V{"name": k, "value": v}) + continue + } + } + config.DockerEnv = append(config.DockerEnv, fmt.Sprintf("%s=%s", k, v)) + } + } + return config.DockerEnv +}