mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Test equality in get from storage
This commit is contained in:
parent
92c3e20e93
commit
2fb71ed955
@ -280,3 +280,30 @@ func WaitForStoreUpdate(store util.FederatedReadOnlyStore, clusterName, key stri
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// Ensure a key is in the store before returning (or timeout w/ error)
|
||||
func WaitForStoreUpdateChecking(store util.FederatedReadOnlyStore, clusterName, key string, timeout time.Duration,
|
||||
checkFunction CheckingFunction) error {
|
||||
retryInterval := 500 * time.Millisecond
|
||||
var lastError error
|
||||
err := wait.PollImmediate(retryInterval, timeout, func() (bool, error) {
|
||||
item, found, err := store.GetByKey(clusterName, key)
|
||||
if err != nil || !found {
|
||||
return found, err
|
||||
}
|
||||
runtimeObj := item.(runtime.Object)
|
||||
lastError = checkFunction(runtimeObj)
|
||||
glog.V(2).Infof("Check function failed for %s %v %v", key, runtimeObj, lastError)
|
||||
return lastError == nil, nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func MetaAndSpecCheckingFunction(expected runtime.Object) CheckingFunction {
|
||||
return func(obj runtime.Object) error {
|
||||
if util.ObjectMetaAndSpecEquivalent(obj, expected) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Object different expected=%#v received=%#v", expected, obj)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user