mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #43107 from intelsdi-x/guarantee-watch-before-action
Automatic merge from submit-queue Guarantee watch before action in e2e event observer helper function. **What this PR does / why we need it**: Adds a missing synchronization barrier to an e2e event observation helper function. - This change should guarantee that in observeEventAfterAction, the action is only executed after the informer begins watching the event stream. **Release note**: ```release-note NONE ``` cc @kubernetes/sig-scheduling-pr-reviews @bsalamat
This commit is contained in:
commit
355f576c0b
@ -50,10 +50,10 @@ func ObserveNodeUpdateAfterAction(f *framework.Framework, nodeName string, nodeP
|
|||||||
return ls, err
|
return ls, err
|
||||||
},
|
},
|
||||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||||
|
// Signal parent goroutine that watching has begun.
|
||||||
|
defer informerStartedGuard.Do(func() { close(informerStartedChan) })
|
||||||
options.FieldSelector = nodeSelector.String()
|
options.FieldSelector = nodeSelector.String()
|
||||||
w, err := f.ClientSet.Core().Nodes().Watch(options)
|
w, err := f.ClientSet.Core().Nodes().Watch(options)
|
||||||
// Signal parent goroutine that watching has begun.
|
|
||||||
informerStartedGuard.Do(func() { close(informerStartedChan) })
|
|
||||||
return w, err
|
return w, err
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -96,6 +96,8 @@ func ObserveNodeUpdateAfterAction(f *framework.Framework, nodeName string, nodeP
|
|||||||
// after performing the supplied action.
|
// after performing the supplied action.
|
||||||
func ObserveEventAfterAction(f *framework.Framework, eventPredicate func(*v1.Event) bool, action func() error) (bool, error) {
|
func ObserveEventAfterAction(f *framework.Framework, eventPredicate func(*v1.Event) bool, action func() error) (bool, error) {
|
||||||
observedMatchingEvent := false
|
observedMatchingEvent := false
|
||||||
|
informerStartedChan := make(chan struct{})
|
||||||
|
var informerStartedGuard sync.Once
|
||||||
|
|
||||||
// Create an informer to list/watch events from the test framework namespace.
|
// Create an informer to list/watch events from the test framework namespace.
|
||||||
_, controller := cache.NewInformer(
|
_, controller := cache.NewInformer(
|
||||||
@ -105,6 +107,8 @@ func ObserveEventAfterAction(f *framework.Framework, eventPredicate func(*v1.Eve
|
|||||||
return ls, err
|
return ls, err
|
||||||
},
|
},
|
||||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||||
|
// Signal parent goroutine that watching has begun.
|
||||||
|
defer informerStartedGuard.Do(func() { close(informerStartedChan) })
|
||||||
w, err := f.ClientSet.Core().Events(f.Namespace.Name).Watch(options)
|
w, err := f.ClientSet.Core().Events(f.Namespace.Name).Watch(options)
|
||||||
return w, err
|
return w, err
|
||||||
},
|
},
|
||||||
@ -123,9 +127,11 @@ func ObserveEventAfterAction(f *framework.Framework, eventPredicate func(*v1.Eve
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Start the informer and block this goroutine waiting for the started signal.
|
||||||
informerStopChan := make(chan struct{})
|
informerStopChan := make(chan struct{})
|
||||||
defer func() { close(informerStopChan) }()
|
defer func() { close(informerStopChan) }()
|
||||||
go controller.Run(informerStopChan)
|
go controller.Run(informerStopChan)
|
||||||
|
<-informerStartedChan
|
||||||
|
|
||||||
// Invoke the action function.
|
// Invoke the action function.
|
||||||
err := action()
|
err := action()
|
||||||
|
Loading…
Reference in New Issue
Block a user