Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
a971769e
Commit
a971769e
authored
May 25, 2016
by
Michelle Noorali
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #720 from michelleN/add-default-repo
ref(helm): add default repository on init step
parents
57c98611
1d4d5ec8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
19 deletions
+44
-19
init.go
cmd/helm/init.go
+3
-1
init_test.go
cmd/helm/init_test.go
+9
-0
repo.go
cmd/helm/repo.go
+10
-6
repo_test.go
cmd/helm/repo_test.go
+20
-6
index.go
pkg/repo/index.go
+2
-6
No files found.
cmd/helm/init.go
View file @
a971769e
...
@@ -19,6 +19,8 @@ var (
...
@@ -19,6 +19,8 @@ var (
tillerNamespace
string
tillerNamespace
string
clientOnly
bool
clientOnly
bool
initSkipNamespace
bool
initSkipNamespace
bool
defaultRepository
=
"kubernetes-charts"
defaultRepositoryURL
=
"http://storage.googleapis.com/kubernetes-charts"
)
)
func
init
()
{
func
init
()
{
...
@@ -96,7 +98,7 @@ func ensureHome() error {
...
@@ -96,7 +98,7 @@ func ensureHome() error {
if
_
,
err
:=
os
.
Create
(
repoFile
);
err
!=
nil
{
if
_
,
err
:=
os
.
Create
(
repoFile
);
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
insertRepoLine
(
"local"
,
"http://localhost:8879/charts"
);
err
!=
nil
{
if
err
:=
addRepository
(
defaultRepository
,
defaultRepositoryURL
);
err
!=
nil
{
return
err
return
err
}
}
}
else
if
fi
.
IsDir
()
{
}
else
if
fi
.
IsDir
()
{
...
...
cmd/helm/init_test.go
View file @
a971769e
package
main
package
main
import
(
import
(
"fmt"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"os"
"testing"
"testing"
)
)
func
TestEnsureHome
(
t
*
testing
.
T
)
{
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
()
home
:=
createTmpHome
()
helmHome
=
home
helmHome
=
home
if
err
:=
ensureHome
();
err
!=
nil
{
if
err
:=
ensureHome
();
err
!=
nil
{
...
...
cmd/helm/repo.go
View file @
a971769e
...
@@ -55,15 +55,11 @@ func runRepoAdd(cmd *cobra.Command, args []string) error {
...
@@ -55,15 +55,11 @@ func runRepoAdd(cmd *cobra.Command, args []string) error {
}
}
name
,
url
:=
args
[
0
],
args
[
1
]
name
,
url
:=
args
[
0
],
args
[
1
]
if
err
:=
repo
.
DownloadIndexFile
(
name
,
url
,
cacheDirectory
(
name
,
"-index.yaml"
));
err
!=
nil
{
if
err
:=
addRepository
(
name
,
url
);
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
{
return
err
return
err
}
}
fmt
.
Println
(
args
[
0
]
+
" has been added to your repositories"
)
fmt
.
Println
(
name
+
" has been added to your repositories"
)
return
nil
return
nil
}
}
...
@@ -114,6 +110,14 @@ func index(dir, url string) error {
...
@@ -114,6 +110,14 @@ func index(dir, url string) error {
return
chartRepo
.
Index
()
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
{
func
removeRepoLine
(
name
string
)
error
{
r
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
r
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
if
err
!=
nil
{
if
err
!=
nil
{
...
...
cmd/helm/repo_test.go
View file @
a971769e
package
main
package
main
import
(
import
(
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"testing"
"github.com/kubernetes/helm/pkg/repo"
"github.com/kubernetes/helm/pkg/repo"
...
@@ -12,13 +18,21 @@ var (
...
@@ -12,13 +18,21 @@ var (
)
)
func
TestRepoAdd
(
t
*
testing
.
T
)
{
func
TestRepoAdd
(
t
*
testing
.
T
)
{
home
:=
createTmpHome
()
ts
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
helmHome
=
home
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain"
)
if
err
:=
ensureHome
();
err
!=
nil
{
fmt
.
Fprintln
(
w
,
"OK"
)
t
.
Errorf
(
"%s"
,
err
)
}))
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
,
test
URL
);
err
!=
nil
{
if
err
:=
addRepository
(
testName
,
ts
.
URL
);
err
!=
nil
{
t
.
Errorf
(
"%s"
,
err
)
t
.
Errorf
(
"%s"
,
err
)
}
}
...
@@ -31,7 +45,7 @@ func TestRepoAdd(t *testing.T) {
...
@@ -31,7 +45,7 @@ func TestRepoAdd(t *testing.T) {
t
.
Errorf
(
"%s was not successfully inserted into %s"
,
testName
,
repositoriesFile
())
t
.
Errorf
(
"%s was not successfully inserted into %s"
,
testName
,
repositoriesFile
())
}
}
if
err
:=
insertRepoLine
(
testName
,
t
est
URL
);
err
==
nil
{
if
err
:=
insertRepoLine
(
testName
,
t
s
.
URL
);
err
==
nil
{
t
.
Errorf
(
"Duplicate repository name was added"
)
t
.
Errorf
(
"Duplicate repository name was added"
)
}
}
...
...
pkg/repo/index.go
View file @
a971769e
...
@@ -28,7 +28,7 @@ type ChartRef struct {
...
@@ -28,7 +28,7 @@ type ChartRef struct {
}
}
// DownloadIndexFile uses
// DownloadIndexFile uses
func
DownloadIndexFile
(
repoName
,
url
,
indexFile
Name
string
)
error
{
func
DownloadIndexFile
(
repoName
,
url
,
indexFile
Path
string
)
error
{
var
indexURL
string
var
indexURL
string
indexURL
=
strings
.
TrimSuffix
(
url
,
"/"
)
+
"/index.yaml"
indexURL
=
strings
.
TrimSuffix
(
url
,
"/"
)
+
"/index.yaml"
...
@@ -49,11 +49,7 @@ func DownloadIndexFile(repoName, url, indexFileName string) error {
...
@@ -49,11 +49,7 @@ func DownloadIndexFile(repoName, url, indexFileName string) error {
return
err
return
err
}
}
if
err
:=
ioutil
.
WriteFile
(
indexFileName
,
b
,
0644
);
err
!=
nil
{
return
ioutil
.
WriteFile
(
indexFilePath
,
b
,
0644
)
return
err
}
return
nil
}
}
// UnmarshalYAML unmarshals the index file
// UnmarshalYAML unmarshals the index file
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment