本文整理匯總了Golang中k8s/io/kubernetes/pkg/client/unversioned.ResourceQuotaInterface.List方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceQuotaInterface.List方法的具體用法?Golang ResourceQuotaInterface.List怎麽用?Golang ResourceQuotaInterface.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/client/unversioned.ResourceQuotaInterface
的用法示例。
在下文中一共展示了ResourceQuotaInterface.List方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WaitForResourceQuotaSync
// WaitForResourceQuotaSync watches given resource quota until its usage is updated to desired level or a
// timeout occurs. If successful, used quota values will be returned for expected resources. Otherwise an
// ErrWaitTimeout will be returned. If expectedIsUpperLimit is true, given expected usage must compare greater
// or equal to quota's usage, which is useful for expected usage increment. Otherwise expected usage must
// compare lower or equal to quota's usage, which is useful for expected usage decrement.
func WaitForResourceQuotaSync(
client kclient.ResourceQuotaInterface,
name string,
expectedUsage kapi.ResourceList,
expectedIsUpperLimit bool,
timeout time.Duration,
) (kapi.ResourceList, error) {
startTime := time.Now()
endTime := startTime.Add(timeout)
expectedResourceNames := quota.ResourceNames(expectedUsage)
list, err := client.List(kapi.ListOptions{FieldSelector: fields.Set{"metadata.name": name}.AsSelector()})
if err != nil {
return nil, err
}
for i := range list.Items {
used := quota.Mask(list.Items[i].Status.Used, expectedResourceNames)
if isUsageSynced(used, expectedUsage, expectedIsUpperLimit) {
return used, nil
}
}
rv := list.ResourceVersion
w, err := client.Watch(kapi.ListOptions{FieldSelector: fields.Set{"metadata.name": name}.AsSelector(), ResourceVersion: rv})
if err != nil {
return nil, err
}
defer w.Stop()
for time.Now().Before(endTime) {
select {
case val, ok := <-w.ResultChan():
if !ok {
// reget and re-watch
continue
}
if rq, ok := val.Object.(*kapi.ResourceQuota); ok {
used := quota.Mask(rq.Status.Used, expectedResourceNames)
if isUsageSynced(used, expectedUsage, expectedIsUpperLimit) {
return used, nil
}
}
case <-time.After(endTime.Sub(time.Now())):
return nil, wait.ErrWaitTimeout
}
}
return nil, wait.ErrWaitTimeout
}