diff --git a/hack/e2e.go b/hack/e2e.go index 0f7dcd5f304..26228d6b490 100644 --- a/hack/e2e.go +++ b/hack/e2e.go @@ -134,6 +134,7 @@ func tryUp() bool { } func Test() (failed, passed []string) { + defer runBashUntil("watchEvents", "$KUBECTL --watch-only get events")() // run tests! dir, err := os.Open(filepath.Join(*root, "hack", "e2e-suite")) if err != nil { @@ -175,6 +176,24 @@ func runBash(stepName, bashFragment string) bool { return finishRunning(stepName, cmd) } +// call the returned anonymous function to stop. +func runBashUntil(stepName, bashFragment string) func() { + cmd := exec.Command("bash", "-s") + cmd.Stdin = strings.NewReader(bashWrap(bashFragment)) + log.Printf("Running in background: %v", stepName) + stdout, stderr := bytes.NewBuffer(nil), bytes.NewBuffer(nil) + cmd.Stdout, cmd.Stderr = stdout, stderr + if err := cmd.Start(); err != nil { + log.Printf("Unable to start '%v': '%v'", stepName, err) + return func() {} + } + return func() { + cmd.Process.Signal(os.Interrupt) + fmt.Printf("%v stdout:\n------\n%v\n------\n", stepName, string(stdout.Bytes())) + fmt.Printf("%v stderr:\n------\n%v\n------\n", stepName, string(stderr.Bytes())) + } +} + func run(stepName, cmdPath string) bool { return finishRunning(stepName, exec.Command(filepath.Join(*root, cmdPath))) } diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index 45e7859d8ca..301ed8a8f3a 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -73,11 +73,13 @@ Examples: obj, err := restHelper.Get(namespace, name, labelSelector) checkErr(err) - if err := printer.PrintObj(obj, out); err != nil { - checkErr(fmt.Errorf("Unable to output the provided object: %v", err)) + if !GetFlagBool(cmd, "watch-only") { + if err := printer.PrintObj(obj, out); err != nil { + checkErr(fmt.Errorf("Unable to output the provided object: %v", err)) + } } - if GetFlagBool(cmd, "watch") { + if GetFlagBool(cmd, "watch") || GetFlagBool(cmd, "watch-only") { vi, err := latest.InterfacesFor(outputVersion) checkErr(err) @@ -97,5 +99,6 @@ Examples: cmd.Flags().StringP("template", "t", "", "Template string or path to template file to use when --output=template or --output=templatefile") cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on") cmd.Flags().BoolP("watch", "w", false, "After listing/getting the requested object, watch for changes.") + cmd.Flags().Bool("watch-only", false, "Watch for changes to the requseted object(s), without listing/getting first.") return cmd }