fix(tiller): fix helm status failure on missing resource

This fixes a bug in which 'helm status' fails if any of the expected
resources are missing in Kubernetes. Now it prints a list of missing
resources at the end of the status report.

Closes #2118
pull/2148/head
Matt Butcher 8 years ago
parent 386dc920f8
commit 27c3ff595a
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -151,11 +151,14 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
if err != nil {
return "", err
}
missing := []string{}
err = perform(c, namespace, infos, func(info *resource.Info) error {
log.Printf("Doing get for: '%s'", info.Name)
obj, err := resource.NewHelper(info.Client, info.Mapping).Get(info.Namespace, info.Name, info.Export)
if err != nil {
return err
log.Printf("WARNING: Failed Get for resource %q: %s", info.Name, err)
missing = append(missing, fmt.Sprintf("%v\t\t%s", info.Mapping.Resource, info.Name))
return nil
}
// We need to grab the ObjectReference so we can correctly group the objects.
or, err := api.GetReference(obj)
@ -194,6 +197,12 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
return "", err
}
}
if len(missing) > 0 {
buf.WriteString("==> MISSING\nKIND\t\tNAME\n")
for _, s := range missing {
fmt.Fprintln(buf, s)
}
}
return buf.String(), nil
}

@ -59,6 +59,7 @@ func newPodWithStatus(name string, status api.PodStatus, namespace string) api.P
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: ns,
SelfLink: "/api/v1/namespaces/default/pods/" + name,
},
Spec: api.PodSpec{
Containers: []api.Container{{
@ -279,6 +280,49 @@ func TestBuild(t *testing.T) {
}
}
func TestGet(t *testing.T) {
list := newPodList("starfish", "otter")
f, tf, _, ns := cmdtesting.NewAPIFactory()
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
p, m := req.URL.Path, req.Method
//actions = append(actions, p+":"+m)
t.Logf("got request %s %s", p, m)
switch {
case p == "/namespaces/default/pods/starfish" && m == "GET":
return newResponse(404, notFoundBody())
case p == "/namespaces/default/pods/otter" && m == "GET":
return newResponse(200, &list.Items[1])
default:
t.Fatalf("unexpected request: %s %s", req.Method, req.URL.Path)
return nil, nil
}
}),
}
c := &Client{Factory: f}
// Test Success
data := strings.NewReader("kind: Pod\napiVersion: v1\nmetadata:\n name: otter")
o, err := c.Get("default", data)
if err != nil {
t.Errorf("Expected missing results, got %q", err)
}
if !strings.Contains(o, "==> v1/Pod") && !strings.Contains(o, "otter") {
t.Errorf("Expected v1/Pod otter, got %s", o)
}
// Test failure
data = strings.NewReader("kind: Pod\napiVersion: v1\nmetadata:\n name: starfish")
o, err = c.Get("default", data)
if err != nil {
t.Errorf("Expected missing results, got %q", err)
}
if !strings.Contains(o, "MISSING") && !strings.Contains(o, "pods\t\tstarfish") {
t.Errorf("Expected missing starfish, got %s", o)
}
}
func TestPerform(t *testing.T) {
tests := []struct {
name string

Loading…
Cancel
Save