mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Update to use watcher
This commit is contained in:
parent
82d76e2d6d
commit
32e0da39fc
@ -1286,12 +1286,9 @@ func taintExists(taints []v1.Taint, taintToFind *v1.Taint) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDynamicResourceWatch(testContext context.Context, dc dynamic.Interface, resourceType schema.GroupVersionResource, namespace string, resourceName string, listOptions metav1.ListOptions) func() (watch.Interface, error) {
|
func getDynamicResourceWatch(testContext context.Context, dc dynamic.Interface, resourceType schema.GroupVersionResource, namespace string, listOptions metav1.ListOptions) (watch.Interface, error) {
|
||||||
return func() (watch.Interface, error) {
|
res, err := dc.Resource(resourceType).Namespace(namespace).Watch(context.TODO(), listOptions)
|
||||||
res, err := dc.Resource(resourceType).Namespace(namespace).Watch(context.TODO(), listOptions)
|
return res, err
|
||||||
ExpectNoError(err, "Failed to create a watch for %v", resourceType.Resource)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WatchEventEnsurerAndManager
|
// WatchEventEnsurerAndManager
|
||||||
@ -1305,10 +1302,20 @@ func getDynamicResourceWatch(testContext context.Context, dc dynamic.Interface,
|
|||||||
// expectedWatchEvents array of events which are expected to occur
|
// expectedWatchEvents array of events which are expected to occur
|
||||||
// scenario the function to run
|
// scenario the function to run
|
||||||
func WatchEventEnsurerAndManager(testContext context.Context, dc dynamic.Interface, resourceType schema.GroupVersionResource, namespace string, resourceName string, listOptions metav1.ListOptions, expectedWatchEvents []watch.Event, scenario func(*watch.Interface) []watch.Event) {
|
func WatchEventEnsurerAndManager(testContext context.Context, dc dynamic.Interface, resourceType schema.GroupVersionResource, namespace string, resourceName string, listOptions metav1.ListOptions, expectedWatchEvents []watch.Event, scenario func(*watch.Interface) []watch.Event) {
|
||||||
// TODO add client-go/tools/watch/retrywatcher to manage watch restarts
|
listWatcher := &cache.ListWatch{
|
||||||
|
WatchFunc: func(listOptions metav1.ListOptions) (watch.Interface, error) {
|
||||||
|
return getDynamicResourceWatch(testContext, dc, resourceType, namespace, listOptions)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
resourceWatch, err := watchtools.NewRetryWatcher("", listWatcher)
|
||||||
|
ExpectNoError(err, "Failed to create a resource watch of %v in namespace %v", resourceType.Resource, namespace)
|
||||||
|
|
||||||
|
ExpectNoError(err, "Failed to create a watch for %v", resourceType.Resource)
|
||||||
retries := 3
|
retries := 3
|
||||||
retriesLoop:
|
retriesLoop:
|
||||||
for try := 1; try <= retries; try++ {
|
for try := 1; try <= retries; try++ {
|
||||||
|
// TODO pass resourceWatch to the test function, or just collect events separately and parse them after
|
||||||
|
scenario()
|
||||||
errs := sets.NewString()
|
errs := sets.NewString()
|
||||||
watchEventsLoop:
|
watchEventsLoop:
|
||||||
for watchEventIndex, _ := range expectedWatchEvents {
|
for watchEventIndex, _ := range expectedWatchEvents {
|
||||||
|
Loading…
Reference in New Issue
Block a user