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
b2f7a874
Commit
b2f7a874
authored
May 17, 2016
by
Michelle Noorali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ref(helm): fix helm update
parent
df4dc3e1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
110 additions
and
55 deletions
+110
-55
repo.go
cmd/helm/repo.go
+1
-1
update.go
cmd/helm/update.go
+2
-41
index.go
pkg/repo/index.go
+51
-0
index_test.go
pkg/repo/index_test.go
+56
-0
local.go
pkg/repo/local.go
+0
-13
No files found.
cmd/helm/repo.go
View file @
b2f7a874
...
...
@@ -47,7 +47,7 @@ func runRepoAdd(cmd *cobra.Command, args []string) error {
}
name
,
url
:=
args
[
0
],
args
[
1
]
if
err
:=
downloadIndexFile
(
name
,
url
);
err
!=
nil
{
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
"
)
}
...
...
cmd/helm/update.go
View file @
b2f7a874
...
...
@@ -3,15 +3,9 @@ package main
import
(
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"github.com/kubernetes/helm/pkg/repo"
)
...
...
@@ -52,7 +46,8 @@ func updateCharts(repos map[string]string, verbose bool) {
wg
.
Add
(
1
)
go
func
(
n
,
u
string
)
{
defer
wg
.
Done
()
err
:=
downloadIndexFile
(
n
,
u
)
indexFileName
:=
cacheDirectory
(
n
+
"-index.yaml"
)
err
:=
repo
.
DownloadIndexFile
(
n
,
u
,
indexFileName
)
if
err
!=
nil
{
updateErr
:=
"...Unable to get an update from the "
+
n
+
" chart repository"
if
verbose
{
...
...
@@ -67,37 +62,3 @@ func updateCharts(repos map[string]string, verbose bool) {
wg
.
Wait
()
fmt
.
Println
(
"Update Complete. Happy Helming!"
)
}
func
downloadIndexFile
(
name
,
url
string
)
error
{
var
indexURL
string
indexURL
=
strings
.
TrimSuffix
(
url
,
"/"
)
+
"/index.yaml"
resp
,
err
:=
http
.
Get
(
indexURL
)
if
err
!=
nil
{
return
err
}
defer
resp
.
Body
.
Close
()
var
indexFile
*
os
.
File
var
r
repo
.
RepoFile
b
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
err
}
if
err
:=
yaml
.
Unmarshal
(
b
,
&
r
);
err
!=
nil
{
return
err
}
indexFile
,
err
=
os
.
Create
(
cacheDirectory
(
name
+
"-index.yaml"
))
if
err
!=
nil
{
return
err
}
if
_
,
err
:=
io
.
Copy
(
indexFile
,
resp
.
Body
);
err
!=
nil
{
return
err
}
return
nil
}
pkg/repo/index.go
0 → 100644
View file @
b2f7a874
package
repo
import
(
"io/ioutil"
"net/http"
"strings"
"gopkg.in/yaml.v2"
)
// IndexFile represents the index file in a chart repository
type
IndexFile
struct
{
Entries
map
[
string
]
*
ChartRef
}
// ChartRef represents a chart entry in the IndexFile
type
ChartRef
struct
{
Name
string
`yaml:"name"`
URL
string
`yaml:"url"`
Keywords
[]
string
`yaml:"keywords"`
Removed
bool
`yaml:"removed,omitempty"`
}
// DownloadIndexFile uses
func
DownloadIndexFile
(
repoName
,
url
,
indexFileName
string
)
error
{
var
indexURL
string
indexURL
=
strings
.
TrimSuffix
(
url
,
"/"
)
+
"/index.yaml"
resp
,
err
:=
http
.
Get
(
indexURL
)
if
err
!=
nil
{
return
err
}
defer
resp
.
Body
.
Close
()
var
r
IndexFile
b
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
err
}
if
err
:=
yaml
.
Unmarshal
(
b
,
&
r
);
err
!=
nil
{
return
err
}
if
err
:=
ioutil
.
WriteFile
(
indexFileName
,
b
,
0644
);
err
!=
nil
{
return
err
}
return
nil
}
pkg/repo/index_test.go
0 → 100644
View file @
b2f7a874
package
repo
import
(
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"gopkg.in/yaml.v2"
)
var
(
testRepo
=
"test-repo"
)
func
TestDownloadIndexFile
(
t
*
testing
.
T
)
{
fileBytes
,
err
:=
ioutil
.
ReadFile
(
"testdata/local-index.yaml"
)
if
err
!=
nil
{
t
.
Errorf
(
"%#v"
,
err
)
}
ts
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"binary/octet-stream"
)
fmt
.
Fprintln
(
w
,
string
(
fileBytes
))
}))
dirName
,
err
:=
ioutil
.
TempDir
(
"testdata"
,
"tmp"
)
path
:=
filepath
.
Join
(
dirName
,
testRepo
+
"-index.yaml"
)
if
err
:=
DownloadIndexFile
(
testRepo
,
ts
.
URL
,
path
);
err
!=
nil
{
t
.
Errorf
(
"%#v"
,
err
)
}
if
_
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
t
.
Errorf
(
"error finding created index file: %#v"
,
err
)
}
b
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
t
.
Errorf
(
"error reading index file: %#v"
,
err
)
}
var
i
IndexFile
if
err
=
yaml
.
Unmarshal
(
b
,
&
i
);
err
!=
nil
{
t
.
Errorf
(
"error unmarshaling index file: %#v"
,
err
)
}
numEntries
:=
len
(
i
.
Entries
)
if
numEntries
!=
2
{
t
.
Errorf
(
"Expected 2 entries in index file but got %v"
,
numEntries
)
}
os
.
Remove
(
path
)
}
pkg/repo/local.go
View file @
b2f7a874
...
...
@@ -13,19 +13,6 @@ import (
var
localRepoPath
string
// IndexFile represents the index file in a chart repository
type
IndexFile
struct
{
Entries
map
[
string
]
*
ChartRef
}
// ChartRef represents a chart entry in the IndexFile
type
ChartRef
struct
{
Name
string
`yaml:"name"`
URL
string
`yaml:"url"`
Keywords
[]
string
`yaml:"keywords"`
Removed
bool
`yaml:"removed,omitempty"`
}
// StartLocalRepo starts a web server and serves files from the given path
func
StartLocalRepo
(
path
string
)
{
fmt
.
Println
(
"Now serving you on localhost:8879..."
)
...
...
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