Commit 57d1c1fd authored by adshmh's avatar adshmh Committed by Matthew Fisher

include the name of the missing object in release uninstall error (#4635)

* fix(tiller) added mock kube client to return failure on delete
Signed-off-by: 's avatarArash Deshmeh <adeshmeh@ca.ibm.com>

* fix(tiller) added object's name to delete release error message
Signed-off-by: 's avatarArash Deshmeh <adeshmeh@ca.ibm.com>
parent eb96576b
......@@ -18,7 +18,6 @@ package tiller
import (
"bytes"
"errors"
"fmt"
"log"
"strings"
......@@ -174,7 +173,11 @@ func DeleteRelease(rel *release.Release, vs chartutil.VersionSet, kubeClient env
log.Printf("uninstall: Failed deletion of %q: %s", rel.Name, err)
if err == kube.ErrNoObjectsVisited {
// Rewrite the message from "no objects visited"
err = errors.New("object not found, skipping delete")
obj := ""
if file.Head != nil && file.Head.Metadata != nil {
obj = "[" + file.Head.Kind + "] " + file.Head.Metadata.Name
}
err = fmt.Errorf("release %q: object %q not found, skipping delete", rel.Name, obj)
}
errs = append(errs, err)
}
......
......@@ -498,6 +498,20 @@ func (h *hookFailingKubeClient) WatchUntilReady(ns string, r io.Reader, timeout
return errors.New("Failed watch")
}
func newDeleteFailingKubeClient() *deleteFailingKubeClient {
return &deleteFailingKubeClient{
PrintingKubeClient: environment.PrintingKubeClient{Out: ioutil.Discard},
}
}
type deleteFailingKubeClient struct {
environment.PrintingKubeClient
}
func (d *deleteFailingKubeClient) Delete(ns string, r io.Reader) error {
return kube.ErrNoObjectsVisited
}
type mockListServer struct {
val *services.ListReleasesResponse
}
......
......@@ -197,3 +197,31 @@ func TestUninstallReleaseCustomDescription(t *testing.T) {
t.Errorf("Expected description to be %q, got %q", customDescription, res.Release.Info.Description)
}
}
func TestUninstallReleaseObjectNotFoundError(t *testing.T) {
c := helm.NewContext()
rs := rsFixture()
rel := releaseStub()
manifest := `kind: ConfigMap
metadata:
name: configmap-foo
data:
name: value
`
rel.Manifest = manifest
rs.env.Releases.Create(rel)
rs.env.KubeClient = newDeleteFailingKubeClient()
req := &services.UninstallReleaseRequest{
Name: "angry-panda",
}
_, err := rs.UninstallRelease(c, req)
if err == nil {
t.Fatalf("Expected failure to delete")
}
if !strings.Contains(err.Error(), "configmap-foo") {
t.Errorf("Expected delete error message to contain object name, got:" + err.Error())
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment