Commit 4b7e4b71 authored by Matt Butcher's avatar Matt Butcher

fix(helm): use 127.0.0.1 instead of localhost

This switches the local chart repo to use 127.0.0.1 instead of localhost
so that the net library does not negotiate localhost to an IPv6 address,
which is known to cause issues in some Docker containers.

Breaking Change: When testing on a system that does NOT have IPv4
configured, this will break 'helm serve'. We estimate this will impact
none of the current user base.

Closes #1410
parent 2eed3f04
...@@ -40,7 +40,9 @@ const ( ...@@ -40,7 +40,9 @@ const (
stableRepository = "stable" stableRepository = "stable"
localRepository = "local" localRepository = "local"
stableRepositoryURL = "http://storage.googleapis.com/kubernetes-charts" stableRepositoryURL = "http://storage.googleapis.com/kubernetes-charts"
localRepositoryURL = "http://localhost:8879/charts" // This is the IPv4 loopback, not localhost, because we have to force IPv4
// for Dockerized Helm: https://github.com/kubernetes/helm/issues/1410
localRepositoryURL = "http://127.0.0.1:8879/charts"
) )
type initCmd struct { type initCmd struct {
......
...@@ -51,7 +51,7 @@ func newServeCmd(out io.Writer) *cobra.Command { ...@@ -51,7 +51,7 @@ func newServeCmd(out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.StringVar(&srv.repoPath, "repo-path", helmpath.Home(homePath()).LocalRepository(), "local directory path from which to serve charts") f.StringVar(&srv.repoPath, "repo-path", helmpath.Home(homePath()).LocalRepository(), "local directory path from which to serve charts")
f.StringVar(&srv.address, "address", "localhost:8879", "address to listen on") f.StringVar(&srv.address, "address", "127.0.0.1:8879", "address to listen on")
return cmd return cmd
} }
......
...@@ -51,10 +51,6 @@ const indexHTMLTemplate = ` ...@@ -51,10 +51,6 @@ const indexHTMLTemplate = `
</html> </html>
` `
const indexFile = `
Welcome to the Kubernetes Package manager!\nBrowse charts on localhost:8879/charts!
`
// RepositoryServer is an HTTP handler for serving a chart repository. // RepositoryServer is an HTTP handler for serving a chart repository.
type RepositoryServer struct { type RepositoryServer struct {
RepoPath string RepoPath string
...@@ -64,10 +60,8 @@ type RepositoryServer struct { ...@@ -64,10 +60,8 @@ type RepositoryServer struct {
func (s *RepositoryServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *RepositoryServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
uri := r.URL.Path uri := r.URL.Path
switch uri { switch uri {
case "/": case "/", "/charts/", "/charts/index.html", "/charts/index":
w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprintf(w, indexFile)
case "/charts/", "/charts/index.html", "/charts/index":
s.htmlIndex(w, r) s.htmlIndex(w, r)
default: default:
file := strings.TrimPrefix(uri, "/charts/") file := strings.TrimPrefix(uri, "/charts/")
...@@ -78,7 +72,7 @@ func (s *RepositoryServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -78,7 +72,7 @@ func (s *RepositoryServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// StartLocalRepo starts a web server and serves files from the given path // StartLocalRepo starts a web server and serves files from the given path
func StartLocalRepo(path, address string) error { func StartLocalRepo(path, address string) error {
if address == "" { if address == "" {
address = ":8879" address = "127.0.0.1:8879"
} }
s := &RepositoryServer{RepoPath: path} s := &RepositoryServer{RepoPath: path}
return http.ListenAndServe(address, s) return http.ListenAndServe(address, s)
...@@ -130,7 +124,7 @@ func Reindex(ch *chart.Chart, path string) error { ...@@ -130,7 +124,7 @@ func Reindex(ch *chart.Chart, path string) error {
return err return err
} }
y.Add(ch.Metadata, name+".tgz", "http://localhost:8879/charts", "sha256:"+dig) y.Add(ch.Metadata, name+".tgz", "http://127.0.0.1:8879/charts", "sha256:"+dig)
out, err := yaml.Marshal(y) out, err := yaml.Marshal(y)
if err != nil { if err != nil {
......
...@@ -25,16 +25,20 @@ import ( ...@@ -25,16 +25,20 @@ import (
) )
func TestRepositoryServer(t *testing.T) { func TestRepositoryServer(t *testing.T) {
expectedIndexYAML, err := ioutil.ReadFile("testdata/server/index.yaml")
if err != nil {
t.Fatal(err)
}
tests := []struct { tests := []struct {
name string name string
path string path string
expect string expect string
}{ }{
{"index YAML", "/charts/index.yaml", "apiVersion: v1"}, {"index YAML", "/charts/index.yaml", string(expectedIndexYAML)},
{"index HTML", "/charts/index.html", "<html>"}, {"index HTML", "/charts/index.html", "<html>"},
{"charts root", "/charts/", "<html>"}, {"charts root", "/charts/", "<html>"},
{"root", "/", "Welcome"}, {"root", "/", "<html>"},
{"file", "/test.txt", "Hello World"}, {"file", "/test.txt", "Hello World"},
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment