Rename Until to UntilWithoutRetry and move to using context so it's

cancelable
This commit is contained in:
Tomas Nozicka
2018-08-02 14:11:59 +02:00
parent ccb92f6ef8
commit 3d4a02abb5
16 changed files with 178 additions and 88 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package get
import (
"context"
"encoding/json"
"fmt"
"io"
@@ -36,6 +37,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/rest"
watchtools "k8s.io/client-go/tools/watch"
"k8s.io/kubernetes/pkg/api/legacyscheme"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/kubectl"
@@ -564,9 +566,11 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string)
}
first := true
intr := interrupt.New(nil, w.Stop)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
intr := interrupt.New(nil, cancel)
intr.Run(func() error {
_, err := watch.Until(0, w, func(e watch.Event) (bool, error) {
_, err := watchtools.UntilWithoutRetry(ctx, w, func(e watch.Event) (bool, error) {
if !isList && first {
// drop the initial watch event in the single resource case
first = false