Unverified Commit 15d5deea authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #5460 from selslack/fix/update-not-found-error-text

refactor(*): make "not found" error message user-friendly
parents d8208abb 535f9cec
...@@ -333,9 +333,18 @@ func (c *Client) Update(namespace string, originalReader, targetReader io.Reader ...@@ -333,9 +333,18 @@ func (c *Client) Update(namespace string, originalReader, targetReader io.Reader
} }
originalInfo := original.Get(info) originalInfo := original.Get(info)
// The resource already exists in the cluster, but it wasn't defined in the previous release.
// In this case, we consider it to be a resource that was previously un-managed by the release and error out,
// asking for the user to intervene.
//
// See https://github.com/helm/helm/issues/1193 for more info.
if originalInfo == nil { if originalInfo == nil {
kind := info.Mapping.GroupVersionKind.Kind return fmt.Errorf(
return fmt.Errorf("no %s with the name %q found", kind, info.Name) "kind %s with the name %q already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart",
info.Mapping.GroupVersionKind.Kind,
info.Name,
)
} }
if err := updateResource(c, info, originalInfo.Object, force, recreate); err != nil { if err := updateResource(c, info, originalInfo.Object, force, recreate); err != nil {
......
...@@ -224,6 +224,43 @@ func TestUpdate(t *testing.T) { ...@@ -224,6 +224,43 @@ func TestUpdate(t *testing.T) {
} }
} }
func TestUpdateNonManagedResourceError(t *testing.T) {
actual := newPodList("starfish")
current := newPodList()
target := newPodList("starfish")
tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
p, m := req.URL.Path, req.Method
t.Logf("got request %s %s", p, m)
switch {
case p == "/namespaces/default/pods/starfish" && m == "GET":
return newResponse(200, &actual.Items[0])
default:
t.Fatalf("unexpected request: %s %s", req.Method, req.URL.Path)
return nil, nil
}
}),
}
c := &Client{
Factory: tf,
Log: nopLogger,
}
if err := c.Update(v1.NamespaceDefault, objBody(&current), objBody(&target), false, false, 0, false); err != nil {
if err.Error() != "kind Pod with the name \"starfish\" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart" {
t.Fatal(err)
}
} else {
t.Fatalf("error expected")
}
}
func TestBuild(t *testing.T) { func TestBuild(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
......
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