Skip to content

Commit

Permalink
Merge pull request #5289 from n0npax/skip-http-proxy-localhost-for-do…
Browse files Browse the repository at this point in the history
…cker-env

Skip http proxy localhost for docker env
  • Loading branch information
tstromberg authored Sep 11, 2019
2 parents 52b1395 + ee8d4b7 commit f36c5d8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,12 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string) (cfg.Config, er
// 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
}
}
dockerEnv = append(dockerEnv, fmt.Sprintf("%s=%s", k, v))
}
}
Expand Down
60 changes: 60 additions & 0 deletions cmd/minikube/cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ limitations under the License.
package cmd

import (
"os"
"testing"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/constants"
)

func Test_extractVMDriverVersion(t *testing.T) {
Expand All @@ -43,3 +48,58 @@ func Test_extractVMDriverVersion(t *testing.T) {
t.Errorf("Expected version: %s, got: %s", expectedVersion, v)
}
}

func TestGenerateCfgFromFlagsHTTPProxyHandling(t *testing.T) {
viper.SetDefault(memory, constants.DefaultMemorySize)
viper.SetDefault(humanReadableDiskSize, constants.DefaultDiskSize)
originalEnv := os.Getenv("HTTP_PROXY")
defer func() {
err := os.Setenv("HTTP_PROXY", originalEnv)
if err != nil {
t.Fatalf("Error reverting env HTTP_PROXY to it's original value. Got err: %s", err)
}
}()
k8sVersion := constants.NewestKubernetesVersion
var tests = []struct {
description string
proxy string
proxyIgnored bool
}{

{
description: "http_proxy=127.0.0.1:3128",
proxy: "127.0.0.1:3128",
proxyIgnored: true,
},
{
description: "http_proxy=localhost:3128",
proxy: "localhost:3128",
proxyIgnored: true,
},
{
description: "http_proxy=1.2.3.4:3128",
proxy: "1.2.3.4:3128",
},
{
description: "no http_proxy",
},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
cmd := &cobra.Command{}
if err := os.Setenv("HTTP_PROXY", test.proxy); err != nil {
t.Fatalf("Unexpected error setting HTTP_PROXY: %v", err)
}
config, err := generateCfgFromFlags(cmd, k8sVersion)
if err != nil {
t.Fatalf("Got unexpected error %v during config generation", err)
}
// ignored proxy should not be in config
for _, v := range config.MachineConfig.DockerEnv {
if v == test.proxy && test.proxyIgnored {
t.Fatalf("Value %v not expected in dockerEnv but occurred", v)
}
}
})
}
}

0 comments on commit f36c5d8

Please sign in to comment.