+70
-3
lines changedFilter options
+70
-3
lines changed Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ type initCmd struct {
80
80
dryRun bool
81
81
forceUpgrade bool
82
82
skipRefresh bool
83
+
skipRepos bool
83
84
out io.Writer
84
85
client helm.Interface
85
86
home helmpath.Home
@@ -118,6 +119,7 @@ func newInitCmd(out io.Writer) *cobra.Command {
118
119
f.BoolVarP(&i.clientOnly, "client-only", "c", false, "If set does not install Tiller")
119
120
f.BoolVar(&i.dryRun, "dry-run", false, "Do not install local or remote")
120
121
f.BoolVar(&i.skipRefresh, "skip-refresh", false, "Do not refresh (download) the local repository cache")
122
+
f.BoolVar(&i.skipRepos, "skip-repos", false, "Skip adding the stable and local repositories")
121
123
f.BoolVar(&i.wait, "wait", false, "Block until Tiller is running and ready to receive requests")
122
124
123
125
// TODO: replace TLS flags with pkg/helm/environment.AddFlagsTLS() in Helm 3
@@ -258,8 +260,14 @@ func (i *initCmd) run() error {
258
260
return nil
259
261
}
260
262
261
-
if err := installer.Initialize(i.home, i.out, i.skipRefresh, settings, stableRepositoryURL, localRepositoryURL); err != nil {
262
-
return fmt.Errorf("error initializing: %s", err)
263
+
if i.skipRepos {
264
+
if err := installer.InitializeWithoutRepos(i.home, i.out); err != nil {
265
+
return fmt.Errorf("error initializing: %s", err)
266
+
}
267
+
} else {
268
+
if err := installer.Initialize(i.home, i.out, i.skipRefresh, settings, stableRepositoryURL, localRepositoryURL); err != nil {
269
+
return fmt.Errorf("error initializing: %s", err)
270
+
}
263
271
}
264
272
fmt.Fprintf(i.out, "$HELM_HOME has been configured at %s.\n", settings.Home)
265
273
Original file line number Diff line number Diff line change
@@ -51,6 +51,29 @@ func Initialize(home helmpath.Home, out io.Writer, skipRefresh bool, settings he
51
51
return ensureRepoFileFormat(home.RepositoryFile(), out)
52
52
}
53
53
54
+
// InitializeWithoutRepos initializes local config without adding repos
55
+
//
56
+
// Returns an error if the command failed.
57
+
func InitializeWithoutRepos(home helmpath.Home, out io.Writer) error {
58
+
if err := ensureDirectories(home, out); err != nil {
59
+
return err
60
+
}
61
+
62
+
// Adding an empty repositories file
63
+
repoFile := home.RepositoryFile()
64
+
if fi, err := os.Stat(repoFile); err != nil {
65
+
fmt.Fprintf(out, "Creating %s \n", repoFile)
66
+
f := repo.NewRepoFile()
67
+
if err := f.WriteFile(repoFile, 0644); err != nil {
68
+
return err
69
+
}
70
+
} else if fi.IsDir() {
71
+
return fmt.Errorf("%s must be a file, not a directory", repoFile)
72
+
}
73
+
74
+
return ensureRepoFileFormat(home.RepositoryFile(), out)
75
+
}
76
+
54
77
// ensureDirectories checks to see if $HELM_HOME exists.
55
78
//
56
79
// If $HELM_HOME does not exist, this function will create it.
Original file line number Diff line number Diff line change
@@ -68,6 +68,41 @@ func TestInitialize(t *testing.T) {
68
68
}
69
69
}
70
70
71
+
func TestInitializeWithoutRepos(t *testing.T) {
72
+
home, err := ioutil.TempDir("", "helm_home")
73
+
if err != nil {
74
+
t.Fatal(err)
75
+
}
76
+
defer os.RemoveAll(home)
77
+
78
+
b := bytes.NewBuffer(nil)
79
+
hh := helmpath.Home(home)
80
+
81
+
if err := InitializeWithoutRepos(hh, b); err != nil {
82
+
t.Error(err)
83
+
}
84
+
85
+
expectedDirs := []string{hh.String(), hh.Repository(), hh.Cache()}
86
+
for _, dir := range expectedDirs {
87
+
if fi, err := os.Stat(dir); err != nil {
88
+
t.Errorf("%s", err)
89
+
} else if !fi.IsDir() {
90
+
t.Errorf("%s is not a directory", fi)
91
+
}
92
+
}
93
+
94
+
if fi, err := os.Stat(hh.RepositoryFile()); err != nil {
95
+
t.Error(err)
96
+
} else if fi.IsDir() {
97
+
t.Errorf("%s should not be a directory", fi)
98
+
}
99
+
100
+
// Make sure the local repository was not added
101
+
if fi, err := os.Stat(hh.LocalRepository(LocalRepositoryIndexFile)); err == nil {
102
+
t.Errorf("%s should not be found", fi)
103
+
}
104
+
}
105
+
71
106
func TestEnsureHome(t *testing.T) {
72
107
home, err := ioutil.TempDir("", "helm_home")
73
108
if err != nil {
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ helm init [flags]
47
47
--replicas int Amount of tiller instances to run on the cluster (default 1)
48
48
--service-account string Name of service account
49
49
--skip-refresh Do not refresh (download) the local repository cache
50
+
--skip-repos Skip adding the stable and local repositories
50
51
--stable-repo-url string URL for stable repository (default "https://kubernetes-charts.storage.googleapis.com")
51
52
-i, --tiller-image string Override Tiller image
52
53
--tiller-tls Install Tiller with TLS enabled
@@ -75,4 +76,4 @@ helm init [flags]
75
76
76
77
* [helm](helm.md) - The Helm package manager for Kubernetes.
77
78
78
-
###### Auto generated by spf13/cobra on 16-May-2019
79
+
###### Auto generated by spf13/cobra on 25-Jun-2020
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4