Merge pull request #720 from michelleN/add-default-repo

ref(helm): add default repository on init step
pull/762/head
Michelle Noorali 8 years ago
commit a971769e85

@ -15,10 +15,12 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he
`
var (
tillerImg string
tillerNamespace string
clientOnly bool
initSkipNamespace bool
tillerImg string
tillerNamespace string
clientOnly bool
initSkipNamespace bool
defaultRepository = "kubernetes-charts"
defaultRepositoryURL = "http://storage.googleapis.com/kubernetes-charts"
)
func init() {
@ -96,7 +98,7 @@ func ensureHome() error {
if _, err := os.Create(repoFile); err != nil {
return err
}
if err := insertRepoLine("local", "http://localhost:8879/charts"); err != nil {
if err := addRepository(defaultRepository, defaultRepositoryURL); err != nil {
return err
}
} else if fi.IsDir() {

@ -1,12 +1,21 @@
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestEnsureHome(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, "OK")
}))
defaultRepositoryURL = ts.URL
home := createTmpHome()
helmHome = home
if err := ensureHome(); err != nil {

@ -55,15 +55,11 @@ func runRepoAdd(cmd *cobra.Command, args []string) error {
}
name, url := args[0], args[1]
if err := repo.DownloadIndexFile(name, url, cacheDirectory(name, "-index.yaml")); err != nil {
return errors.New("Oops! Looks like " + url + " is not a valid chart repository or cannot be reached\n")
}
if err := insertRepoLine(name, url); err != nil {
if err := addRepository(name, url); err != nil {
return err
}
fmt.Println(args[0] + " has been added to your repositories")
fmt.Println(name + " has been added to your repositories")
return nil
}
@ -114,6 +110,14 @@ func index(dir, url string) error {
return chartRepo.Index()
}
func addRepository(name, url string) error {
if err := repo.DownloadIndexFile(name, url, cacheDirectory(name+"-index.yaml")); err != nil {
return errors.New("Looks like " + url + " is not a valid chart repository or cannot be reached: " + err.Error())
}
return insertRepoLine(name, url)
}
func removeRepoLine(name string) error {
r, err := repo.LoadRepositoriesFile(repositoriesFile())
if err != nil {

@ -1,6 +1,12 @@
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"github.com/kubernetes/helm/pkg/repo"
@ -12,13 +18,21 @@ var (
)
func TestRepoAdd(t *testing.T) {
home := createTmpHome()
helmHome = home
if err := ensureHome(); err != nil {
t.Errorf("%s", err)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, "OK")
}))
helmHome, _ = ioutil.TempDir("", "helm_home")
defer os.Remove(helmHome)
os.Mkdir(filepath.Join(helmHome, repositoryDir), 0755)
os.Mkdir(cacheDirectory(), 0755)
if err := ioutil.WriteFile(repositoriesFile(), []byte("example-repo: http://exampleurl.com"), 0666); err != nil {
t.Errorf("%#v", err)
}
if err := insertRepoLine(testName, testURL); err != nil {
if err := addRepository(testName, ts.URL); err != nil {
t.Errorf("%s", err)
}
@ -31,7 +45,7 @@ func TestRepoAdd(t *testing.T) {
t.Errorf("%s was not successfully inserted into %s", testName, repositoriesFile())
}
if err := insertRepoLine(testName, testURL); err == nil {
if err := insertRepoLine(testName, ts.URL); err == nil {
t.Errorf("Duplicate repository name was added")
}

@ -28,7 +28,7 @@ type ChartRef struct {
}
// DownloadIndexFile uses
func DownloadIndexFile(repoName, url, indexFileName string) error {
func DownloadIndexFile(repoName, url, indexFilePath string) error {
var indexURL string
indexURL = strings.TrimSuffix(url, "/") + "/index.yaml"
@ -49,11 +49,7 @@ func DownloadIndexFile(repoName, url, indexFileName string) error {
return err
}
if err := ioutil.WriteFile(indexFileName, b, 0644); err != nil {
return err
}
return nil
return ioutil.WriteFile(indexFilePath, b, 0644)
}
// UnmarshalYAML unmarshals the index file

Loading…
Cancel
Save