mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
SAControllerClientBuilder: Replace ListWatchUntil with UntilWithSync to
avoid watch timeouts
This commit is contained in:
parent
fdf381098b
commit
9747c9a221
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -34,11 +35,10 @@ import (
|
|||||||
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"
|
watchtools "k8s.io/client-go/tools/watch"
|
||||||
|
"k8s.io/klog"
|
||||||
"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"
|
||||||
|
|
||||||
"k8s.io/klog"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ControllerClientBuilder allows you to get clients and configs for controllers
|
// ControllerClientBuilder allows you to get clients and configs for controllers
|
||||||
@ -114,18 +114,22 @@ func (b SAControllerClientBuilder) Config(name string) (*restclient.Config, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
var clientConfig *restclient.Config
|
var clientConfig *restclient.Config
|
||||||
|
fieldSelector := fields.SelectorFromSet(map[string]string{
|
||||||
|
api.SecretTypeField: string(v1.SecretTypeServiceAccountToken),
|
||||||
|
}).String()
|
||||||
lw := &cache.ListWatch{
|
lw := &cache.ListWatch{
|
||||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||||
options.FieldSelector = fields.SelectorFromSet(map[string]string{api.SecretTypeField: string(v1.SecretTypeServiceAccountToken)}).String()
|
options.FieldSelector = fieldSelector
|
||||||
return b.CoreClient.Secrets(b.Namespace).List(options)
|
return b.CoreClient.Secrets(b.Namespace).List(options)
|
||||||
},
|
},
|
||||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||||
options.FieldSelector = fields.SelectorFromSet(map[string]string{api.SecretTypeField: string(v1.SecretTypeServiceAccountToken)}).String()
|
options.FieldSelector = fieldSelector
|
||||||
return b.CoreClient.Secrets(b.Namespace).Watch(options)
|
return b.CoreClient.Secrets(b.Namespace).Watch(options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = watchtools.ListWatchUntil(30*time.Second, lw,
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
_, err = watchtools.UntilWithSync(ctx, lw, &v1.Secret{}, nil,
|
||||||
func(event watch.Event) (bool, error) {
|
func(event watch.Event) (bool, error) {
|
||||||
switch event.Type {
|
switch event.Type {
|
||||||
case watch.Deleted:
|
case watch.Deleted:
|
||||||
|
Loading…
Reference in New Issue
Block a user