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
db29c25a
Commit
db29c25a
authored
Sep 27, 2016
by
Matt Butcher
Committed by
GitHub
Sep 27, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1232 from technosophos/feat/1042-upgrade-install
feat(helm): add 'helm upgrade --install' support
parents
fde23e81
36e6094c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
24 deletions
+63
-24
upgrade.go
cmd/helm/upgrade.go
+56
-24
upgrade_test.go
cmd/helm/upgrade_test.go
+7
-0
No files found.
cmd/helm/upgrade.go
View file @
db29c25a
...
...
@@ -21,10 +21,12 @@ import (
"fmt"
"io"
"io/ioutil"
"strings"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/storage/driver"
)
const
upgradeDesc
=
`
...
...
@@ -48,6 +50,8 @@ type upgradeCmd struct {
values
*
values
verify
bool
keyring
string
install
bool
namespace
string
}
func
newUpgradeCmd
(
client
helm
.
Interface
,
out
io
.
Writer
)
*
cobra
.
Command
{
...
...
@@ -83,39 +87,43 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
f
.
BoolVar
(
&
upgrade
.
disableHooks
,
"disable-hooks"
,
false
,
"disable pre/post upgrade hooks"
)
f
.
BoolVar
(
&
upgrade
.
verify
,
"verify"
,
false
,
"verify the provenance of the chart before upgrading"
)
f
.
StringVar
(
&
upgrade
.
keyring
,
"keyring"
,
defaultKeyring
(),
"the path to the keyring that contains public singing keys"
)
f
.
BoolVarP
(
&
upgrade
.
install
,
"install"
,
"i"
,
false
,
"if a release by this name doesn't already exist, run an install"
)
f
.
StringVar
(
&
upgrade
.
namespace
,
"namespace"
,
"default"
,
"the namespace to install the release into (only used if --install is set)"
)
return
cmd
}
func
(
u
*
upgradeCmd
)
vals
()
([]
byte
,
error
)
{
var
buffer
bytes
.
Buffer
// User specified a values file via -f/--values
if
u
.
valuesFile
!=
""
{
bytes
,
err
:=
ioutil
.
ReadFile
(
u
.
valuesFile
)
func
(
u
*
upgradeCmd
)
run
()
error
{
chartPath
,
err
:=
locateChartPath
(
u
.
chart
,
u
.
verify
,
u
.
keyring
)
if
err
!=
nil
{
return
[]
byte
{},
err
}
buffer
.
Write
(
bytes
)
return
err
}
// User specified value pairs via --set
// These override any values in the specified file
if
len
(
u
.
values
.
pairs
)
>
0
{
bytes
,
err
:=
u
.
values
.
yaml
()
if
err
!=
nil
{
return
[]
byte
{},
err
if
u
.
install
{
// If a release does not exist, install it. If another error occurs during
// the check, ignore the error and continue with the upgrade.
//
// The returned error is a grpc.rpcError that wraps the message from the original error.
// So we're stuck doing string matching against the wrapped error, which is nested somewhere
// inside of the grpc.rpcError message.
_
,
err
:=
u
.
client
.
ReleaseContent
(
u
.
release
,
helm
.
ContentReleaseVersion
(
1
))
if
err
!=
nil
&&
strings
.
Contains
(
err
.
Error
(),
driver
.
ErrReleaseNotFound
.
Error
())
{
fmt
.
Fprintf
(
u
.
out
,
"Release %q does not exist. Installing it now.
\n
"
,
u
.
release
)
ic
:=
&
installCmd
{
chartPath
:
chartPath
,
client
:
u
.
client
,
out
:
u
.
out
,
name
:
u
.
release
,
valuesFile
:
u
.
valuesFile
,
dryRun
:
u
.
dryRun
,
verify
:
u
.
verify
,
disableHooks
:
u
.
disableHooks
,
keyring
:
u
.
keyring
,
values
:
u
.
values
,
namespace
:
u
.
namespace
,
}
buffer
.
Write
(
bytes
)
return
ic
.
run
(
)
}
return
buffer
.
Bytes
(),
nil
}
func
(
u
*
upgradeCmd
)
run
()
error
{
chartPath
,
err
:=
locateChartPath
(
u
.
chart
,
u
.
verify
,
u
.
keyring
)
if
err
!=
nil
{
return
err
}
rawVals
,
err
:=
u
.
vals
()
...
...
@@ -139,5 +147,29 @@ func (u *upgradeCmd) run() error {
PrintStatus
(
u
.
out
,
status
)
return
nil
}
func
(
u
*
upgradeCmd
)
vals
()
([]
byte
,
error
)
{
var
buffer
bytes
.
Buffer
// User specified a values file via -f/--values
if
u
.
valuesFile
!=
""
{
bytes
,
err
:=
ioutil
.
ReadFile
(
u
.
valuesFile
)
if
err
!=
nil
{
return
[]
byte
{},
err
}
buffer
.
Write
(
bytes
)
}
// User specified value pairs via --set
// These override any values in the specified file
if
len
(
u
.
values
.
pairs
)
>
0
{
bytes
,
err
:=
u
.
values
.
yaml
()
if
err
!=
nil
{
return
[]
byte
{},
err
}
buffer
.
Write
(
bytes
)
}
return
buffer
.
Bytes
(),
nil
}
cmd/helm/upgrade_test.go
View file @
db29c25a
...
...
@@ -69,6 +69,13 @@ func TestUpgradeCmd(t *testing.T) {
resp
:
releaseMock
(
&
releaseOptions
{
name
:
"funny-bunny"
,
version
:
2
,
chart
:
ch
}),
expected
:
"funny-bunny has been upgraded. Happy Helming!
\n
"
,
},
{
name
:
"install a release with 'upgrade --install'"
,
args
:
[]
string
{
"zany-bunny"
,
chartPath
},
flags
:
[]
string
{
"-i"
},
resp
:
releaseMock
(
&
releaseOptions
{
name
:
"zany-bunny"
,
version
:
1
,
chart
:
ch
}),
expected
:
"zany-bunny has been upgraded. Happy Helming!
\n
"
,
},
}
cmd
:=
func
(
c
*
fakeReleaseClient
,
out
io
.
Writer
)
*
cobra
.
Command
{
...
...
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