mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Deprecate ListWatchUntil, fix it and call places
This commit is contained in:
parent
07b8373ab3
commit
e434f3189e
@ -214,7 +214,7 @@ func TestListWatchUntil(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeout := 10 * time.Second
|
timeout := 10 * time.Second
|
||||||
lastEvent, err := ListWatchUntil(timeout, listwatch, conditions...)
|
lastEvent, err := watchtools.ListWatchUntil(timeout, listwatch, conditions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("expected nil error, got %#v", err)
|
t.Fatalf("expected nil error, got %#v", err)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
|
watchtools "k8s.io/client-go/tools/watch"
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
"k8s.io/kubernetes/pkg/serviceaccount"
|
"k8s.io/kubernetes/pkg/serviceaccount"
|
||||||
@ -122,7 +123,7 @@ func (b SAControllerClientBuilder) Config(name string) (*restclient.Config, erro
|
|||||||
return b.CoreClient.Secrets(b.Namespace).Watch(options)
|
return b.CoreClient.Secrets(b.Namespace).Watch(options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = cache.ListWatchUntil(30*time.Second, lw,
|
_, err = watchtools.ListWatchUntil(30*time.Second, lw,
|
||||||
func(event watch.Event) (bool, error) {
|
func(event watch.Event) (bool, error) {
|
||||||
switch event.Type {
|
switch event.Type {
|
||||||
case watch.Deleted:
|
case watch.Deleted:
|
||||||
|
@ -23,8 +23,10 @@ import (
|
|||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
|
"k8s.io/client-go/tools/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConditionFunc returns true if the condition has been reached, false if it has not been reached yet,
|
// ConditionFunc returns true if the condition has been reached, false if it has not been reached yet,
|
||||||
@ -105,7 +107,10 @@ func ContextWithOptionalTimeout(parent context.Context, timeout time.Duration) (
|
|||||||
// ListWatchUntil checks the provided conditions against the items returned by the list watcher, returning wait.ErrWaitTimeout
|
// ListWatchUntil checks the provided conditions against the items returned by the list watcher, returning wait.ErrWaitTimeout
|
||||||
// if timeout is exceeded without all conditions returning true, or an error if an error occurs.
|
// if timeout is exceeded without all conditions returning true, or an error if an error occurs.
|
||||||
// TODO: check for watch expired error and retry watch from latest point? Same issue exists for Until.
|
// TODO: check for watch expired error and retry watch from latest point? Same issue exists for Until.
|
||||||
func ListWatchUntil(timeout time.Duration, lw ListerWatcher, conditions ...watchtools.ConditionFunc) (*watch.Event, error) {
|
// TODO: remove when no longer used
|
||||||
|
//
|
||||||
|
// Deprecated: Use UntilWithSync instead.
|
||||||
|
func ListWatchUntil(timeout time.Duration, lw cache.ListerWatcher, conditions ...ConditionFunc) (*watch.Event, error) {
|
||||||
if len(conditions) == 0 {
|
if len(conditions) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -167,10 +172,10 @@ func ListWatchUntil(timeout time.Duration, lw ListerWatcher, conditions ...watch
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), timeout)
|
ctx, cancel := ContextWithOptionalTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
evt, err := watchtools.UntilWithoutRetry(ctx, watchInterface, remainingConditions...)
|
evt, err := UntilWithoutRetry(ctx, watchInterface, remainingConditions...)
|
||||||
if err == watchtools.ErrWatchClosed {
|
if err == ErrWatchClosed {
|
||||||
// present a consistent error interface to callers
|
// present a consistent error interface to callers
|
||||||
err = wait.ErrWaitTimeout
|
err = wait.ErrWaitTimeout
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,11 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/glog"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
|
|
||||||
certificates "k8s.io/api/certificates/v1beta1"
|
certificates "k8s.io/api/certificates/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -38,6 +39,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
|
certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
|
watchtools "k8s.io/client-go/tools/watch"
|
||||||
certutil "k8s.io/client-go/util/cert"
|
certutil "k8s.io/client-go/util/cert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -121,7 +123,7 @@ func RequestCertificate(client certificatesclient.CertificateSigningRequestInter
|
|||||||
func WaitForCertificate(client certificatesclient.CertificateSigningRequestInterface, req *certificates.CertificateSigningRequest, timeout time.Duration) (certData []byte, err error) {
|
func WaitForCertificate(client certificatesclient.CertificateSigningRequestInterface, req *certificates.CertificateSigningRequest, timeout time.Duration) (certData []byte, err error) {
|
||||||
fieldSelector := fields.OneTermEqualSelector("metadata.name", req.Name).String()
|
fieldSelector := fields.OneTermEqualSelector("metadata.name", req.Name).String()
|
||||||
|
|
||||||
event, err := cache.ListWatchUntil(
|
event, err := watchtools.ListWatchUntil(
|
||||||
timeout,
|
timeout,
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user