mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Merge pull request #3966 from adamreese/dev-v3-local-repo
ref(*): remove local repository (dead code)
This commit is contained in:
commit
7bf0cb6c46
23 changed files with 13 additions and 391 deletions
0
cmd/helm/delete.go
Executable file → Normal file
0
cmd/helm/delete.go
Executable file → Normal file
|
|
@ -99,7 +99,7 @@ func tempHelmHome(t *testing.T) (helmpath.Home, error) {
|
|||
//
|
||||
// t is used only for logging.
|
||||
func ensureTestHome(home helmpath.Home, t *testing.T) error {
|
||||
configDirectories := []string{home.String(), home.Repository(), home.Cache(), home.LocalRepository(), home.Plugins(), home.Starters()}
|
||||
configDirectories := []string{home.String(), home.Repository(), home.Cache(), home.Plugins(), home.Starters()}
|
||||
for _, p := range configDirectories {
|
||||
if fi, err := os.Stat(p); err != nil {
|
||||
if err := os.MkdirAll(p, 0755); err != nil {
|
||||
|
|
@ -117,10 +117,6 @@ func ensureTestHome(home helmpath.Home, t *testing.T) error {
|
|||
Name: "charts",
|
||||
URL: "http://example.com/foo",
|
||||
Cache: "charts-index.yaml",
|
||||
}, &repo.Entry{
|
||||
Name: "local",
|
||||
URL: "http://localhost.com:7743/foo",
|
||||
Cache: "local-index.yaml",
|
||||
})
|
||||
if err := rf.WriteFile(repoFile, 0644); err != nil {
|
||||
return err
|
||||
|
|
@ -135,19 +131,6 @@ func ensureTestHome(home helmpath.Home, t *testing.T) error {
|
|||
}
|
||||
}
|
||||
|
||||
localRepoIndexFile := home.LocalRepository(localRepositoryIndexFile)
|
||||
if fi, err := os.Stat(localRepoIndexFile); err != nil {
|
||||
i := repo.NewIndexFile()
|
||||
if err := i.WriteFile(localRepoIndexFile, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//TODO: take this out and replace with helm update functionality
|
||||
os.Symlink(localRepoIndexFile, home.CacheIndex("local"))
|
||||
} else if fi.IsDir() {
|
||||
return fmt.Errorf("%s must be a file, not a directory", localRepoIndexFile)
|
||||
}
|
||||
|
||||
t.Logf("$HELM_HOME has been configured at %s.\n", settings.Home.String())
|
||||
return nil
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ func newHomeCmd(out io.Writer) *cobra.Command {
|
|||
fmt.Fprintf(out, "Cache: %s\n", h.Cache())
|
||||
fmt.Fprintf(out, "Stable CacheIndex: %s\n", h.CacheIndex("stable"))
|
||||
fmt.Fprintf(out, "Starters: %s\n", h.Starters())
|
||||
fmt.Fprintf(out, "LocalRepository: %s\n", h.LocalRepository())
|
||||
fmt.Fprintf(out, "Plugins: %s\n", h.Plugins())
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -33,18 +33,9 @@ const initDesc = `
|
|||
This command sets up local configuration in $HELM_HOME (default ~/.helm/).
|
||||
`
|
||||
|
||||
const (
|
||||
stableRepository = "stable"
|
||||
localRepository = "local"
|
||||
localRepositoryIndexFile = "index.yaml"
|
||||
)
|
||||
const stableRepository = "stable"
|
||||
|
||||
var (
|
||||
stableRepositoryURL = "https://kubernetes-charts.storage.googleapis.com"
|
||||
// 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"
|
||||
)
|
||||
var stableRepositoryURL = "https://kubernetes-charts.storage.googleapis.com"
|
||||
|
||||
type initCmd struct {
|
||||
skipRefresh bool
|
||||
|
|
@ -71,7 +62,6 @@ func newInitCmd(out io.Writer) *cobra.Command {
|
|||
f := cmd.Flags()
|
||||
f.BoolVar(&i.skipRefresh, "skip-refresh", false, "do not refresh (download) the local repository cache")
|
||||
f.StringVar(&stableRepositoryURL, "stable-repo-url", stableRepositoryURL, "URL for stable repository")
|
||||
f.StringVar(&localRepositoryURL, "local-repo-url", localRepositoryURL, "URL for local repository")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
@ -100,7 +90,6 @@ func ensureDirectories(home helmpath.Home, out io.Writer) error {
|
|||
home.String(),
|
||||
home.Repository(),
|
||||
home.Cache(),
|
||||
home.LocalRepository(),
|
||||
home.Plugins(),
|
||||
home.Starters(),
|
||||
home.Archive(),
|
||||
|
|
@ -128,12 +117,7 @@ func ensureDefaultRepos(home helmpath.Home, out io.Writer, skipRefresh bool) err
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lr, err := initLocalRepo(home.LocalRepository(localRepositoryIndexFile), home.CacheIndex("local"), out, home)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.Add(sr)
|
||||
f.Add(lr)
|
||||
if err := f.WriteFile(repoFile, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -168,29 +152,6 @@ func initStableRepo(cacheFile string, out io.Writer, skipRefresh bool, home helm
|
|||
return &c, nil
|
||||
}
|
||||
|
||||
func initLocalRepo(indexFile, cacheFile string, out io.Writer, home helmpath.Home) (*repo.Entry, error) {
|
||||
if fi, err := os.Stat(indexFile); err != nil {
|
||||
fmt.Fprintf(out, "Adding %s repo with URL: %s \n", localRepository, localRepositoryURL)
|
||||
i := repo.NewIndexFile()
|
||||
if err := i.WriteFile(indexFile, 0644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//TODO: take this out and replace with helm update functionality
|
||||
if err := createLink(indexFile, cacheFile, home); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else if fi.IsDir() {
|
||||
return nil, fmt.Errorf("%s must be a file, not a directory", indexFile)
|
||||
}
|
||||
|
||||
return &repo.Entry{
|
||||
Name: localRepository,
|
||||
URL: localRepositoryURL,
|
||||
Cache: cacheFile,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ensureRepoFileFormat(file string, out io.Writer) error {
|
||||
r, err := repo.LoadRepositoriesFile(file)
|
||||
if err == repo.ErrRepoOutOfDate {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func TestEnsureHome(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
|
||||
expectedDirs := []string{hh.String(), hh.Repository(), hh.Cache(), hh.LocalRepository()}
|
||||
expectedDirs := []string{hh.String(), hh.Repository(), hh.Cache()}
|
||||
for _, dir := range expectedDirs {
|
||||
if fi, err := os.Stat(dir); err != nil {
|
||||
t.Errorf("%s", err)
|
||||
|
|
@ -62,10 +62,4 @@ func TestEnsureHome(t *testing.T) {
|
|||
} else if fi.IsDir() {
|
||||
t.Errorf("%s should not be a directory", fi)
|
||||
}
|
||||
|
||||
if fi, err := os.Stat(hh.LocalRepository(localRepositoryIndexFile)); err != nil {
|
||||
t.Errorf("%s", err)
|
||||
} else if fi.IsDir() {
|
||||
t.Errorf("%s should not be a directory", fi)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"k8s.io/helm/pkg/helm/helmpath"
|
||||
)
|
||||
|
||||
func createLink(indexFile, cacheFile string, home helmpath.Home) error {
|
||||
return os.Symlink(indexFile, cacheFile)
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
// +build windows
|
||||
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"k8s.io/helm/pkg/helm/helmpath"
|
||||
)
|
||||
|
||||
func createLink(indexFile, cacheFile string, home helmpath.Home) error {
|
||||
return os.Link(indexFile, cacheFile)
|
||||
}
|
||||
|
|
@ -36,7 +36,6 @@ import (
|
|||
"k8s.io/helm/pkg/hapi/chart"
|
||||
"k8s.io/helm/pkg/helm/helmpath"
|
||||
"k8s.io/helm/pkg/provenance"
|
||||
"k8s.io/helm/pkg/repo"
|
||||
)
|
||||
|
||||
const packageDesc = `
|
||||
|
|
@ -51,7 +50,6 @@ Versioned chart archives are used by Helm package repositories.
|
|||
`
|
||||
|
||||
type packageCmd struct {
|
||||
save bool
|
||||
sign bool
|
||||
path string
|
||||
valueFiles valueFiles
|
||||
|
|
@ -102,7 +100,6 @@ func newPackageCmd(out io.Writer) *cobra.Command {
|
|||
f.VarP(&pkg.valueFiles, "values", "f", "specify values in a YAML file or a URL(can specify multiple)")
|
||||
f.StringArrayVar(&pkg.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
|
||||
f.StringArrayVar(&pkg.stringValues, "set-string", []string{}, "set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
|
||||
f.BoolVar(&pkg.save, "save", true, "save packaged chart to local chart repository")
|
||||
f.BoolVar(&pkg.sign, "sign", false, "use a PGP private key to sign this package")
|
||||
f.StringVar(&pkg.key, "key", "", "name of the key to use when signing. Used if --sign is true")
|
||||
f.StringVar(&pkg.keyring, "keyring", defaultKeyring(), "location of a public keyring")
|
||||
|
|
@ -200,16 +197,6 @@ func (p *packageCmd) run() error {
|
|||
return fmt.Errorf("Failed to save: %s", err)
|
||||
}
|
||||
|
||||
// Save to $HELM_HOME/local directory. This is second, because we don't want
|
||||
// the case where we saved here, but didn't save to the default destination.
|
||||
if p.save {
|
||||
lr := p.home.LocalRepository()
|
||||
if err := repo.AddChartToLocalRepo(ch, lr); err != nil {
|
||||
return err
|
||||
}
|
||||
debug("Successfully saved %s to %s\n", name, lr)
|
||||
}
|
||||
|
||||
if p.sign {
|
||||
err = p.clearsign(name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ func TestLoadPlugins(t *testing.T) {
|
|||
hh.Repository(),
|
||||
hh.RepositoryFile(),
|
||||
hh.Cache(),
|
||||
hh.LocalRepository(),
|
||||
os.Args[0],
|
||||
}, "\n")
|
||||
|
||||
|
|
@ -173,7 +172,6 @@ func TestSetupEnv(t *testing.T) {
|
|||
{"HELM_PATH_REPOSITORY", settings.Home.Repository()},
|
||||
{"HELM_PATH_REPOSITORY_FILE", settings.Home.RepositoryFile()},
|
||||
{"HELM_PATH_CACHE", settings.Home.Cache()},
|
||||
{"HELM_PATH_LOCAL_REPOSITORY", settings.Home.LocalRepository()},
|
||||
{"HELM_PATH_STARTER", settings.Home.Starters()},
|
||||
} {
|
||||
if got := os.Getenv(tt.name); got != tt.expect {
|
||||
|
|
|
|||
|
|
@ -92,12 +92,7 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, home helmpath.Ho
|
|||
wg.Add(1)
|
||||
go func(re *repo.ChartRepository) {
|
||||
defer wg.Done()
|
||||
if re.Config.Name == localRepository {
|
||||
fmt.Fprintf(out, "...Skip %s chart repository\n", re.Config.Name)
|
||||
return
|
||||
}
|
||||
err := re.DownloadIndexFile(home.Cache())
|
||||
if err != nil {
|
||||
if err := re.DownloadIndexFile(home.Cache()); err != nil {
|
||||
fmt.Fprintf(out, "...Unable to get an update from the %q chart repository (%s):\n\t%s\n", re.Config.Name, re.Config.URL, err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "...Successfully got an update from the %q chart repository\n", re.Config.Name)
|
||||
|
|
|
|||
|
|
@ -60,8 +60,8 @@ func TestUpdateCmd(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if got := out.String(); !strings.Contains(got, "charts") || !strings.Contains(got, "local") {
|
||||
t.Errorf("Expected 'charts' and 'local' (in any order) got %q", got)
|
||||
if got := out.String(); !strings.Contains(got, "charts") {
|
||||
t.Errorf("Expected 'charts' got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,5 +6,4 @@ echo $HELM_HOME
|
|||
echo $HELM_PATH_REPOSITORY
|
||||
echo $HELM_PATH_REPOSITORY_FILE
|
||||
echo $HELM_PATH_CACHE
|
||||
echo $HELM_PATH_LOCAL_REPOSITORY
|
||||
echo $HELM_BIN
|
||||
|
|
|
|||
2
cmd/helm/testdata/repositories.yaml
vendored
2
cmd/helm/testdata/repositories.yaml
vendored
|
|
@ -2,5 +2,3 @@ apiVersion: v1
|
|||
repositories:
|
||||
- name: charts
|
||||
url: "https://kubernetes-charts.storage.googleapis.com"
|
||||
- name: local
|
||||
url: "http://localhost:8879/charts"
|
||||
|
|
|
|||
|
|
@ -77,19 +77,6 @@ type ListReleasesRequest struct {
|
|||
StatusCodes []release.StatusCode `json:"status_codes,omitempty"`
|
||||
}
|
||||
|
||||
// ListReleasesResponse is a list of releases.
|
||||
type ListReleasesResponse struct {
|
||||
// Count is the expected total number of releases to be returned.
|
||||
Count int64 `json:"count,omitempty"`
|
||||
// Next is the name of the next release. If this is other than an empty
|
||||
// string, it means there are more results.
|
||||
Next string `json:"next,omitempty"`
|
||||
// Total is the total number of queryable releases.
|
||||
Total int64 `json:"total,omitempty"`
|
||||
// Releases is the list of found release objects.
|
||||
Releases []*release.Release `json:"releases,omitempty"`
|
||||
}
|
||||
|
||||
// GetReleaseStatusRequest is a request to get the status of a release.
|
||||
type GetReleaseStatusRequest struct {
|
||||
// Name is the name of the release
|
||||
|
|
|
|||
|
|
@ -66,17 +66,6 @@ func (h Home) Starters() string {
|
|||
return h.Path("starters")
|
||||
}
|
||||
|
||||
// LocalRepository returns the location to the local repo.
|
||||
//
|
||||
// The local repo is the one used by 'helm serve'
|
||||
//
|
||||
// If additional path elements are passed, they are appended to the returned path.
|
||||
func (h Home) LocalRepository(elem ...string) string {
|
||||
p := []string{"repository", "local"}
|
||||
p = append(p, elem...)
|
||||
return h.Path(p...)
|
||||
}
|
||||
|
||||
// Plugins returns the path to the plugins directory.
|
||||
func (h Home) Plugins() string {
|
||||
return h.Path("plugins")
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ func TestHelmHome(t *testing.T) {
|
|||
isEq(t, hh.String(), "/r")
|
||||
isEq(t, hh.Repository(), "/r/repository")
|
||||
isEq(t, hh.RepositoryFile(), "/r/repository/repositories.yaml")
|
||||
isEq(t, hh.LocalRepository(), "/r/repository/local")
|
||||
isEq(t, hh.Cache(), "/r/repository/cache")
|
||||
isEq(t, hh.CacheIndex("t"), "/r/repository/cache/t-index.yaml")
|
||||
isEq(t, hh.Starters(), "/r/starters")
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ func TestHelmHome(t *testing.T) {
|
|||
isEq(t, hh.String(), "r:\\")
|
||||
isEq(t, hh.Repository(), "r:\\repository")
|
||||
isEq(t, hh.RepositoryFile(), "r:\\repository\\repositories.yaml")
|
||||
isEq(t, hh.LocalRepository(), "r:\\repository\\local")
|
||||
isEq(t, hh.Cache(), "r:\\repository\\cache")
|
||||
isEq(t, hh.CacheIndex("t"), "r:\\repository\\cache\\t-index.yaml")
|
||||
isEq(t, hh.Starters(), "r:\\starters")
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ func (g *TarGzExtractor) Extract(buffer *bytes.Buffer, targetDir string) error {
|
|||
|
||||
os.MkdirAll(targetDir, 0755)
|
||||
|
||||
for true {
|
||||
for {
|
||||
header, err := tarReader.Next()
|
||||
|
||||
if err == io.EOF {
|
||||
|
|
|
|||
|
|
@ -177,11 +177,10 @@ func SetupPluginEnv(settings helm_env.EnvSettings,
|
|||
"HELM_HOME": settings.Home.String(),
|
||||
|
||||
// Set vars that convey common information.
|
||||
"HELM_PATH_REPOSITORY": settings.Home.Repository(),
|
||||
"HELM_PATH_REPOSITORY_FILE": settings.Home.RepositoryFile(),
|
||||
"HELM_PATH_CACHE": settings.Home.Cache(),
|
||||
"HELM_PATH_LOCAL_REPOSITORY": settings.Home.LocalRepository(),
|
||||
"HELM_PATH_STARTER": settings.Home.Starters(),
|
||||
"HELM_PATH_REPOSITORY": settings.Home.Repository(),
|
||||
"HELM_PATH_REPOSITORY_FILE": settings.Home.RepositoryFile(),
|
||||
"HELM_PATH_CACHE": settings.Home.Cache(),
|
||||
"HELM_PATH_STARTER": settings.Home.Starters(),
|
||||
} {
|
||||
os.Setenv(key, val)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,137 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
htemplate "html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
|
||||
"k8s.io/helm/pkg/chartutil"
|
||||
"k8s.io/helm/pkg/hapi/chart"
|
||||
"k8s.io/helm/pkg/provenance"
|
||||
)
|
||||
|
||||
const indexHTMLTemplate = `
|
||||
<html>
|
||||
<head>
|
||||
<title>Helm Repository</title>
|
||||
</head>
|
||||
<h1>Helm Charts Repository</h1>
|
||||
<ul>
|
||||
{{range $name, $ver := .Index.Entries}}
|
||||
<li>{{$name}}<ul>{{range $ver}}
|
||||
<li><a href="{{index .URLs 0}}">{{.Name}}-{{.Version}}</a></li>
|
||||
{{end}}</ul>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
<body>
|
||||
<p>Last Generated: {{.Index.Generated}}</p>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
// RepositoryServer is an HTTP handler for serving a chart repository.
|
||||
type RepositoryServer struct {
|
||||
RepoPath string
|
||||
}
|
||||
|
||||
// ServeHTTP implements the http.Handler interface.
|
||||
func (s *RepositoryServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
uri := r.URL.Path
|
||||
switch uri {
|
||||
case "/", "/charts/", "/charts/index.html", "/charts/index":
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
s.htmlIndex(w, r)
|
||||
default:
|
||||
file := strings.TrimPrefix(uri, "/charts/")
|
||||
http.ServeFile(w, r, filepath.Join(s.RepoPath, file))
|
||||
}
|
||||
}
|
||||
|
||||
// StartLocalRepo starts a web server and serves files from the given path
|
||||
func StartLocalRepo(path, address string) error {
|
||||
if address == "" {
|
||||
address = "127.0.0.1:8879"
|
||||
}
|
||||
s := &RepositoryServer{RepoPath: path}
|
||||
return http.ListenAndServe(address, s)
|
||||
}
|
||||
|
||||
func (s *RepositoryServer) htmlIndex(w http.ResponseWriter, r *http.Request) {
|
||||
t := htemplate.Must(htemplate.New("index.html").Parse(indexHTMLTemplate))
|
||||
// load index
|
||||
lrp := filepath.Join(s.RepoPath, "index.yaml")
|
||||
i, err := LoadIndexFile(lrp)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"Index": i,
|
||||
}
|
||||
if err := t.Execute(w, data); err != nil {
|
||||
fmt.Fprintf(w, "Template error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// AddChartToLocalRepo saves a chart in the given path and then reindexes the index file
|
||||
func AddChartToLocalRepo(ch *chart.Chart, path string) error {
|
||||
_, err := chartutil.Save(ch, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Reindex(ch, path+"/index.yaml")
|
||||
}
|
||||
|
||||
// Reindex adds an entry to the index file at the given path
|
||||
func Reindex(ch *chart.Chart, path string) error {
|
||||
name := ch.Metadata.Name + "-" + ch.Metadata.Version
|
||||
y, err := LoadIndexFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
found := false
|
||||
for k := range y.Entries {
|
||||
if k == name {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
dig, err := provenance.DigestFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
y.Add(ch.Metadata, name+".tgz", "http://127.0.0.1:8879/charts", "sha256:"+dig)
|
||||
|
||||
out, err := yaml.Marshal(y)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ioutil.WriteFile(path, out, 0644)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRepositoryServer(t *testing.T) {
|
||||
expectedIndexYAML, err := ioutil.ReadFile("testdata/server/index.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
expect string
|
||||
}{
|
||||
{"index YAML", "/charts/index.yaml", string(expectedIndexYAML)},
|
||||
{"index HTML", "/charts/index.html", "<html>"},
|
||||
{"charts root", "/charts/", "<html>"},
|
||||
{"root", "/", "<html>"},
|
||||
{"file", "/test.txt", "Hello World"},
|
||||
}
|
||||
|
||||
s := &RepositoryServer{RepoPath: "testdata/server"}
|
||||
srv, err := startLocalServerForTests(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer srv.Close()
|
||||
|
||||
for _, tt := range tests {
|
||||
res, err := http.Get(srv.URL + tt.path)
|
||||
if err != nil {
|
||||
t.Errorf("%s: error getting %s: %s", tt.name, tt.path, err)
|
||||
continue
|
||||
}
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Errorf("%s: error reading %s: %s", tt.name, tt.path, err)
|
||||
}
|
||||
res.Body.Close()
|
||||
if !strings.Contains(string(body), tt.expect) {
|
||||
t.Errorf("%s: expected to find %q in %q", tt.name, tt.expect, string(body))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -202,7 +202,7 @@ func TestWriteFile(t *testing.T) {
|
|||
t.Errorf("failed to create test-file (%v)", err)
|
||||
}
|
||||
defer os.Remove(repoFile.Name())
|
||||
if err := sampleRepository.WriteFile(repoFile.Name(), 744); err != nil {
|
||||
if err := sampleRepository.WriteFile(repoFile.Name(), 0744); err != nil {
|
||||
t.Errorf("failed to write file (%v)", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,9 +66,6 @@ var (
|
|||
errInvalidName = errors.New("invalid release name, must match regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])+$ and the length must not longer than 53")
|
||||
)
|
||||
|
||||
// ListDefaultLimit is the default limit for number of items returned in a list.
|
||||
var ListDefaultLimit int64 = 512
|
||||
|
||||
// ValidName is a regular expression for names.
|
||||
//
|
||||
// According to the Kubernetes help text, the regular expression it uses is:
|
||||
|
|
|
|||
Loading…
Reference in a new issue