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
1fb16ab3
Commit
1fb16ab3
authored
Aug 25, 2016
by
Matt Butcher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(helm): refactor 'helm update' to match new style
And add tests. Closes #696
parent
56500729
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
18 deletions
+123
-18
helm.go
cmd/helm/helm.go
+1
-0
repositories.yaml
cmd/helm/testdata/repositories.yaml
+2
-0
update.go
cmd/helm/update.go
+33
-18
update_test.go
cmd/helm/update_test.go
+87
-0
No files found.
cmd/helm/helm.go
View file @
1fb16ab3
...
@@ -97,6 +97,7 @@ func newRootCmd(out io.Writer) *cobra.Command {
...
@@ -97,6 +97,7 @@ func newRootCmd(out io.Writer) *cobra.Command {
newPackageCmd
(
nil
,
out
),
newPackageCmd
(
nil
,
out
),
newFetchCmd
(
out
),
newFetchCmd
(
out
),
newVerifyCmd
(
out
),
newVerifyCmd
(
out
),
newUpdateCmd
(
out
),
)
)
return
cmd
return
cmd
}
}
...
...
cmd/helm/testdata/repositories.yaml
0 → 100644
View file @
1fb16ab3
charts
:
http://storage.googleapis.com/kubernetes-charts
local
:
http://localhost:8879/charts
cmd/helm/update.go
View file @
1fb16ab3
...
@@ -19,6 +19,7 @@ package main
...
@@ -19,6 +19,7 @@ package main
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io"
"sync"
"sync"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
...
@@ -26,23 +27,37 @@ import (
...
@@ -26,23 +27,37 @@ import (
"k8s.io/helm/pkg/repo"
"k8s.io/helm/pkg/repo"
)
)
var
verboseUpdate
bool
const
updateDesc
=
`
Update gets the latest information about charts from the respective chart repositories.
Information is cached locally, where it is used by commands like 'helm search'.
`
var
updateCommand
=
&
cobra
.
Command
{
type
updateCmd
struct
{
repoFile
string
update
func
(
map
[
string
]
string
,
bool
,
io
.
Writer
)
out
io
.
Writer
}
func
newUpdateCmd
(
out
io
.
Writer
)
*
cobra
.
Command
{
u
:=
&
updateCmd
{
out
:
out
,
update
:
updateCharts
,
repoFile
:
repositoriesFile
(),
}
cmd
:=
&
cobra
.
Command
{
Use
:
"update"
,
Use
:
"update"
,
Aliases
:
[]
string
{
"up"
},
Aliases
:
[]
string
{
"up"
},
Short
:
"update information on available charts in the chart repositories"
,
Short
:
"update information on available charts in the chart repositories"
,
RunE
:
runUpdate
,
Long
:
updateDesc
,
}
RunE
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
return
u
.
run
()
func
init
()
{
},
updateCommand
.
Flags
()
.
BoolVar
(
&
verboseUpdate
,
"verbose"
,
false
,
"verbose error messages"
)
}
RootCommand
.
AddCommand
(
updateCommand
)
return
cmd
}
}
func
runUpdate
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
func
(
u
*
updateCmd
)
run
()
error
{
f
,
err
:=
repo
.
LoadRepositoriesFile
(
u
.
repoFile
)
f
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -51,12 +66,12 @@ func runUpdate(cmd *cobra.Command, args []string) error {
...
@@ -51,12 +66,12 @@ func runUpdate(cmd *cobra.Command, args []string) error {
return
errors
.
New
(
"no repositories found. You must add one before updating"
)
return
errors
.
New
(
"no repositories found. You must add one before updating"
)
}
}
u
pdateCharts
(
f
.
Repositories
,
verboseUpdate
)
u
.
update
(
f
.
Repositories
,
flagDebug
,
u
.
out
)
return
nil
return
nil
}
}
func
updateCharts
(
repos
map
[
string
]
string
,
verbose
bool
)
{
func
updateCharts
(
repos
map
[
string
]
string
,
verbose
bool
,
out
io
.
Writer
)
{
fmt
.
Println
(
"Hang tight while we grab the latest from your chart repositories..."
)
fmt
.
Fprintln
(
out
,
"Hang tight while we grab the latest from your chart repositories..."
)
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
for
name
,
url
:=
range
repos
{
for
name
,
url
:=
range
repos
{
wg
.
Add
(
1
)
wg
.
Add
(
1
)
...
@@ -65,16 +80,16 @@ func updateCharts(repos map[string]string, verbose bool) {
...
@@ -65,16 +80,16 @@ func updateCharts(repos map[string]string, verbose bool) {
indexFileName
:=
cacheDirectory
(
n
+
"-index.yaml"
)
indexFileName
:=
cacheDirectory
(
n
+
"-index.yaml"
)
err
:=
repo
.
DownloadIndexFile
(
n
,
u
,
indexFileName
)
err
:=
repo
.
DownloadIndexFile
(
n
,
u
,
indexFileName
)
if
err
!=
nil
{
if
err
!=
nil
{
updateErr
:=
"...Unable to get an update from the "
+
n
+
" chart repository"
updateErr
:=
fmt
.
Sprintf
(
"...Unable to get an update from the %q chart repository"
,
n
)
if
verbose
{
if
verbose
{
updateErr
=
updateErr
+
": "
+
err
.
Error
()
updateErr
=
updateErr
+
": "
+
err
.
Error
()
}
}
fmt
.
Println
(
updateErr
)
fmt
.
Fprintln
(
out
,
updateErr
)
}
else
{
}
else
{
fmt
.
Println
(
"...Successfully got an update from the "
+
n
+
" chart repository"
)
fmt
.
Fprintf
(
out
,
"...Successfully got an update from the %q chart repository
\n
"
,
n
)
}
}
}(
name
,
url
)
}(
name
,
url
)
}
}
wg
.
Wait
()
wg
.
Wait
()
fmt
.
Println
(
"Update Complete. Happy Helming!"
)
fmt
.
Fprintln
(
out
,
"Update Complete. Happy Helming!"
)
}
}
cmd/helm/update_test.go
0 → 100644
View file @
1fb16ab3
/*
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
main
import
(
"bytes"
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func
TestUpdateCmd
(
t
*
testing
.
T
)
{
out
:=
bytes
.
NewBuffer
(
nil
)
// Instead of using the HTTP updater, we provide our own for this test.
// The TestUpdateCharts test verifies the HTTP behavior independently.
updater
:=
func
(
repos
map
[
string
]
string
,
verbose
bool
,
out
io
.
Writer
)
{
for
name
:=
range
repos
{
fmt
.
Fprintln
(
out
,
name
)
}
}
uc
:=
&
updateCmd
{
out
:
out
,
update
:
updater
,
repoFile
:
"testdata/repositories.yaml"
,
}
uc
.
run
()
if
got
:=
out
.
String
();
!
strings
.
Contains
(
got
,
"charts"
)
||
!
strings
.
Contains
(
got
,
"local"
)
{
t
.
Errorf
(
"Expected 'charts' and 'local' (in any order) got %s"
,
got
)
}
}
const
mockRepoIndex
=
`
mychart-0.1.0:
name: mychart-0.1.0
url: localhost:8879/charts/mychart-0.1.0.tgz
chartfile:
name: ""
home: ""
sources: []
version: ""
description: ""
keywords: []
maintainers: []
engine: ""
icon: ""
`
func
TestUpdateCharts
(
t
*
testing
.
T
)
{
// This tests the repo in isolation. It creates a mock HTTP server that simply
// returns a static YAML file in the anticipate format.
handler
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Write
([]
byte
(
mockRepoIndex
))
})
srv
:=
httptest
.
NewServer
(
handler
)
defer
srv
.
Close
()
buf
:=
bytes
.
NewBuffer
(
nil
)
repos
:=
map
[
string
]
string
{
"charts"
:
srv
.
URL
,
}
updateCharts
(
repos
,
false
,
buf
)
got
:=
buf
.
String
()
if
strings
.
Contains
(
got
,
"Unable to get an update"
)
{
t
.
Errorf
(
"Failed to get a repo: %q"
,
got
)
}
if
!
strings
.
Contains
(
got
,
"Update Complete."
)
{
t
.
Errorf
(
"Update was not successful"
)
}
}
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