Adding init flad to skip adding repos

The stable charts repository is nearing the end of its life. Once
that has happened those who attempt to run helm init will get an
error. This flag provides a means to still use Helm v2 after the
stable charts repository is gone.

A secondary situation is that Helm v2 can be used in environmnets
without a network connection.

Closes #7868

Signed-off-by: Matt Farina <matt@mattfarina.com>
pull/8344/head
Matt Farina 4 years ago
parent 3ce9ac387d
commit a03d3e34ac
No known key found for this signature in database
GPG Key ID: 9436E80BFBA46909

@ -80,6 +80,7 @@ type initCmd struct {
dryRun bool
forceUpgrade bool
skipRefresh bool
skipRepos bool
out io.Writer
client helm.Interface
home helmpath.Home
@ -118,6 +119,7 @@ func newInitCmd(out io.Writer) *cobra.Command {
f.BoolVarP(&i.clientOnly, "client-only", "c", false, "If set does not install Tiller")
f.BoolVar(&i.dryRun, "dry-run", false, "Do not install local or remote")
f.BoolVar(&i.skipRefresh, "skip-refresh", false, "Do not refresh (download) the local repository cache")
f.BoolVar(&i.skipRepos, "skip-repos", false, "Skip adding the stable and local repositories")
f.BoolVar(&i.wait, "wait", false, "Block until Tiller is running and ready to receive requests")
// TODO: replace TLS flags with pkg/helm/environment.AddFlagsTLS() in Helm 3
@ -258,8 +260,14 @@ func (i *initCmd) run() error {
return nil
}
if err := installer.Initialize(i.home, i.out, i.skipRefresh, settings, stableRepositoryURL, localRepositoryURL); err != nil {
return fmt.Errorf("error initializing: %s", err)
if i.skipRepos {
if err := installer.InitializeWithoutRepos(i.home, i.out); err != nil {
return fmt.Errorf("error initializing: %s", err)
}
} else {
if err := installer.Initialize(i.home, i.out, i.skipRefresh, settings, stableRepositoryURL, localRepositoryURL); err != nil {
return fmt.Errorf("error initializing: %s", err)
}
}
fmt.Fprintf(i.out, "$HELM_HOME has been configured at %s.\n", settings.Home)

@ -51,6 +51,29 @@ func Initialize(home helmpath.Home, out io.Writer, skipRefresh bool, settings he
return ensureRepoFileFormat(home.RepositoryFile(), out)
}
// InitializeWithoutRepos initializes local config without adding repos
//
// Returns an error if the command failed.
func InitializeWithoutRepos(home helmpath.Home, out io.Writer) error {
if err := ensureDirectories(home, out); err != nil {
return err
}
// Adding an empty repositories file
repoFile := home.RepositoryFile()
if fi, err := os.Stat(repoFile); err != nil {
fmt.Fprintf(out, "Creating %s \n", repoFile)
f := repo.NewRepoFile()
if err := f.WriteFile(repoFile, 0644); err != nil {
return err
}
} else if fi.IsDir() {
return fmt.Errorf("%s must be a file, not a directory", repoFile)
}
return ensureRepoFileFormat(home.RepositoryFile(), out)
}
// ensureDirectories checks to see if $HELM_HOME exists.
//
// If $HELM_HOME does not exist, this function will create it.

@ -68,6 +68,41 @@ func TestInitialize(t *testing.T) {
}
}
func TestInitializeWithoutRepos(t *testing.T) {
home, err := ioutil.TempDir("", "helm_home")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(home)
b := bytes.NewBuffer(nil)
hh := helmpath.Home(home)
if err := InitializeWithoutRepos(hh, b); err != nil {
t.Error(err)
}
expectedDirs := []string{hh.String(), hh.Repository(), hh.Cache()}
for _, dir := range expectedDirs {
if fi, err := os.Stat(dir); err != nil {
t.Errorf("%s", err)
} else if !fi.IsDir() {
t.Errorf("%s is not a directory", fi)
}
}
if fi, err := os.Stat(hh.RepositoryFile()); err != nil {
t.Error(err)
} else if fi.IsDir() {
t.Errorf("%s should not be a directory", fi)
}
// Make sure the local repository was not added
if fi, err := os.Stat(hh.LocalRepository(LocalRepositoryIndexFile)); err == nil {
t.Errorf("%s should not be found", fi)
}
}
func TestEnsureHome(t *testing.T) {
home, err := ioutil.TempDir("", "helm_home")
if err != nil {

@ -47,6 +47,7 @@ helm init [flags]
--replicas int Amount of tiller instances to run on the cluster (default 1)
--service-account string Name of service account
--skip-refresh Do not refresh (download) the local repository cache
--skip-repos Skip adding the stable and local repositories
--stable-repo-url string URL for stable repository (default "https://kubernetes-charts.storage.googleapis.com")
-i, --tiller-image string Override Tiller image
--tiller-tls Install Tiller with TLS enabled
@ -75,4 +76,4 @@ helm init [flags]
* [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 16-May-2019
###### Auto generated by spf13/cobra on 25-Jun-2020

Loading…
Cancel
Save