mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #3468 from smarterclayton/better_log_on_empty_delete
Write to STDERR when Delete contains no resources
This commit is contained in:
		@@ -20,7 +20,6 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
 | 
			
		||||
	"github.com/golang/glog"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
 | 
			
		||||
@@ -70,7 +69,7 @@ Examples:
 | 
			
		||||
				Do()
 | 
			
		||||
 | 
			
		||||
			found := 0
 | 
			
		||||
			r.IgnoreErrors(errors.IsNotFound).Visit(func(r *resource.Info) error {
 | 
			
		||||
			err := r.IgnoreErrors(errors.IsNotFound).Visit(func(r *resource.Info) error {
 | 
			
		||||
				found++
 | 
			
		||||
				if err := resource.NewHelper(r.Client, r.Mapping).Delete(r.Namespace, r.Name); err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
@@ -78,8 +77,9 @@ Examples:
 | 
			
		||||
				fmt.Fprintf(out, "%s\n", r.Name)
 | 
			
		||||
				return nil
 | 
			
		||||
			})
 | 
			
		||||
			checkErr(err)
 | 
			
		||||
			if found == 0 {
 | 
			
		||||
				glog.V(2).Infof("No resource(s) found")
 | 
			
		||||
				fmt.Fprintf(cmd.Out(), "No resources found\n")
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -82,6 +83,37 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestDeleteNoObjects(t *testing.T) {
 | 
			
		||||
	f, tf, codec := NewAPIFactory()
 | 
			
		||||
	tf.Printer = &testPrinter{}
 | 
			
		||||
	tf.Client = &client.FakeRESTClient{
 | 
			
		||||
		Codec: codec,
 | 
			
		||||
		Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
			switch p, m := req.URL.Path, req.Method; {
 | 
			
		||||
			case p == "/ns/test/pods" && m == "GET":
 | 
			
		||||
				return &http.Response{StatusCode: 200, Body: objBody(codec, &api.PodList{})}, nil
 | 
			
		||||
			default:
 | 
			
		||||
				t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
 | 
			
		||||
				return nil, nil
 | 
			
		||||
			}
 | 
			
		||||
		}),
 | 
			
		||||
	}
 | 
			
		||||
	buf := bytes.NewBuffer([]byte{})
 | 
			
		||||
	stderr := bytes.NewBuffer([]byte{})
 | 
			
		||||
 | 
			
		||||
	cmd := f.NewCmdDelete(buf)
 | 
			
		||||
	cmd.SetOutput(stderr)
 | 
			
		||||
	cmd.Flags().String("namespace", "test", "")
 | 
			
		||||
	cmd.Run(cmd, []string{"pods"})
 | 
			
		||||
 | 
			
		||||
	if buf.String() != "" {
 | 
			
		||||
		t.Errorf("unexpected output: %s", buf.String())
 | 
			
		||||
	}
 | 
			
		||||
	if stderr.String() != "No resources found\n" {
 | 
			
		||||
		t.Errorf("unexpected output: %s", stderr.String())
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestDeleteMultipleObject(t *testing.T) {
 | 
			
		||||
	pods, svc := testData()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user