feat(*): integrate support for upgrade hooks

pull/1030/head
Michelle Noorali 9 years ago
parent 70b9f11a03
commit f99228778d

@ -95,7 +95,8 @@ func (u *upgradeCmd) run() error {
return prettyError(err) return prettyError(err)
} }
fmt.Fprintf(u.out, "It's not you. It's me\nYour upgrade looks valid but this command is still under active development.\nHang tight.\n") success := u.release + " has been upgraded. Happy Helming!\n"
fmt.Fprintf(u.out, success)
return nil return nil

@ -52,18 +52,22 @@ func TestUpgradeCmd(t *testing.T) {
Description: "A Helm chart for Kubernetes", Description: "A Helm chart for Kubernetes",
Version: "0.1.2", Version: "0.1.2",
} }
chartPath, err = chartutil.Create(cfile, tmpChart) chartPath, err = chartutil.Create(cfile, tmpChart)
if err != nil { if err != nil {
t.Errorf("Error creating chart: %v", err) t.Errorf("Error creating chart: %v", err)
} }
ch, _ = chartutil.Load(chartPath) ch, err = chartutil.Load(chartPath)
if err != nil {
t.Errorf("Error loading updated chart: %v", err)
}
tests := []releaseCase{ tests := []releaseCase{
{ {
name: "upgrade a release", name: "upgrade a release",
args: []string{"funny-bunny", chartPath}, args: []string{"funny-bunny", chartPath},
resp: releaseMock(&releaseOptions{name: "funny-bunny", version: 2, chart: ch}), resp: releaseMock(&releaseOptions{name: "funny-bunny", version: 2, chart: ch}),
expected: "It's not you. It's me\nYour upgrade looks valid but this command is still under active development.\nHang tight.\n", expected: "funny-bunny has been upgraded. Happy Helming!\n",
}, },
} }

@ -196,11 +196,11 @@ func (s *releaseServer) performUpdate(originalRelease, updatedRelease *release.R
} }
// pre-ugrade hooks // pre-ugrade hooks
//if !req.DisableHooks { if !req.DisableHooks {
//if err := s.execHook(updatedRelease.Hooks, updatedRelease.Name, updatedRelease.Namespace, preUpgrade); err != nil { if err := s.execHook(updatedRelease.Hooks, updatedRelease.Name, updatedRelease.Namespace, preUpgrade); err != nil {
//return res, err return res, err
//} }
//} }
kubeCli := s.env.KubeClient kubeCli := s.env.KubeClient
original := bytes.NewBufferString(originalRelease.Manifest) original := bytes.NewBufferString(originalRelease.Manifest)
@ -210,11 +210,11 @@ func (s *releaseServer) performUpdate(originalRelease, updatedRelease *release.R
} }
// post-upgrade hooks // post-upgrade hooks
//if !req.DisableHooks { if !req.DisableHooks {
//if err := s.execHook(updatedRelease.Hooks, updatedRelease.Name, updatedRelease.Namespace, postUpgrade); err != nil { if err := s.execHook(updatedRelease.Hooks, updatedRelease.Name, updatedRelease.Namespace, postUpgrade); err != nil {
//return res, err return res, err
//} }
//} }
updatedRelease.Info.Status.Code = release.Status_DEPLOYED updatedRelease.Info.Status.Code = release.Status_DEPLOYED

@ -44,6 +44,16 @@ data:
name: value name: value
` `
var manifestWithUpgradeHooks = `apiVersion: v1
kind: ConfigMap
metadata:
name: test-cm
annotations:
"helm.sh/hook": post-upgrade,pre-upgrade
data:
name: value
`
func rsFixture() *releaseServer { func rsFixture() *releaseServer {
return &releaseServer{ return &releaseServer{
env: mockEnvironment(), env: mockEnvironment(),
@ -302,6 +312,7 @@ func TestUpdateRelease(t *testing.T) {
Metadata: &chart.Metadata{Name: "hello"}, Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{ Templates: []*chart.Template{
{Name: "hello", Data: []byte("hello: world")}, {Name: "hello", Data: []byte("hello: world")},
{Name: "hooks", Data: []byte(manifestWithUpgradeHooks)},
}, },
}, },
} }
@ -309,6 +320,7 @@ func TestUpdateRelease(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed updated: %s", err) t.Errorf("Failed updated: %s", err)
} }
if res.Release.Name == "" { if res.Release.Name == "" {
t.Errorf("Expected release name.") t.Errorf("Expected release name.")
} }
@ -326,6 +338,21 @@ func TestUpdateRelease(t *testing.T) {
t.Errorf("Expected release for %s (%v).", res.Release.Name, rs.env.Releases) t.Errorf("Expected release for %s (%v).", res.Release.Name, rs.env.Releases)
} }
if len(updated.Hooks) != 1 {
t.Fatalf("Expected 1 hook, got %d", len(updated.Hooks))
}
if updated.Hooks[0].Manifest != manifestWithUpgradeHooks {
t.Errorf("Unexpected manifest: %v", updated.Hooks[0].Manifest)
}
if updated.Hooks[0].Events[0] != release.Hook_POST_UPGRADE {
t.Errorf("Expected event 0 to be post upgrade")
}
if updated.Hooks[0].Events[1] != release.Hook_PRE_UPGRADE {
t.Errorf("Expected event 0 to be pre upgrade")
}
if len(res.Release.Manifest) == 0 { if len(res.Release.Manifest) == 0 {
t.Errorf("No manifest returned: %v", res.Release) t.Errorf("No manifest returned: %v", res.Release)
} }
@ -343,6 +370,35 @@ func TestUpdateRelease(t *testing.T) {
} }
} }
func TestUpdateReleaseNoHooks(t *testing.T) {
c := context.Background()
rs := rsFixture()
rel := releaseStub()
rs.env.Releases.Create(rel)
req := &services.UpdateReleaseRequest{
Name: rel.Name,
DisableHooks: true,
Chart: &chart.Chart{
Metadata: &chart.Metadata{Name: "hello"},
Templates: []*chart.Template{
{Name: "hello", Data: []byte("hello: world")},
{Name: "hooks", Data: []byte(manifestWithUpgradeHooks)},
},
},
}
res, err := rs.UpdateRelease(c, req)
if err != nil {
t.Errorf("Failed updated: %s", err)
}
if hl := res.Release.Hooks[0].LastRun; hl != nil {
t.Errorf("Expected that no hooks were run. Got %d", hl)
}
}
func TestUninstallRelease(t *testing.T) { func TestUninstallRelease(t *testing.T) {
c := context.Background() c := context.Background()
rs := rsFixture() rs := rsFixture()

@ -244,7 +244,6 @@ func (o *options) rpcDeleteRelease(rlsName string, rlc rls.ReleaseServiceClient,
// Executes tiller.UpdateRelease RPC. // Executes tiller.UpdateRelease RPC.
func (o *options) rpcUpdateRelease(rlsName string, chr *cpb.Chart, rlc rls.ReleaseServiceClient, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) { func (o *options) rpcUpdateRelease(rlsName string, chr *cpb.Chart, rlc rls.ReleaseServiceClient, opts ...UpdateOption) (*rls.UpdateReleaseResponse, error) {
//TODO: handle dryRun
for _, opt := range opts { for _, opt := range opts {
opt(o) opt(o)
} }

Loading…
Cancel
Save