本文整理匯總了Golang中k8s/io/kubernetes/pkg/client/unversioned.ReplicationControllerInterface.Watch方法的典型用法代碼示例。如果您正苦於以下問題:Golang ReplicationControllerInterface.Watch方法的具體用法?Golang ReplicationControllerInterface.Watch怎麽用?Golang ReplicationControllerInterface.Watch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/client/unversioned.ReplicationControllerInterface
的用法示例。
在下文中一共展示了ReplicationControllerInterface.Watch方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WaitForADeployment
// WaitForADeployment waits for a Deployment to fulfill the isOK function
func WaitForADeployment(client kclient.ReplicationControllerInterface,
name string,
isOK, isFailed func(*kapi.ReplicationController) bool) error {
startTime := time.Now()
endTime := startTime.Add(15 * time.Minute)
for time.Now().Before(endTime) {
requirement, err := labels.NewRequirement(deployapi.DeploymentConfigAnnotation, labels.EqualsOperator, sets.NewString(name))
if err != nil {
return fmt.Errorf("unexpected error generating label selector: %v", err)
}
list, err := client.List(labels.LabelSelector{*requirement}, fields.Everything())
if err != nil {
return err
}
for i := range list.Items {
if isOK(&list.Items[i]) {
return nil
}
if isFailed(&list.Items[i]) {
return fmt.Errorf("The deployment %q status is %q",
name, list.Items[i].Annotations[deployapi.DeploymentStatusAnnotation])
}
}
rv := list.ResourceVersion
w, err := client.Watch(labels.LabelSelector{*requirement}, fields.Everything(), rv)
if err != nil {
return err
}
defer w.Stop()
for {
val, ok := <-w.ResultChan()
if !ok {
// reget and re-watch
break
}
if e, ok := val.Object.(*kapi.ReplicationController); ok {
if isOK(e) {
return nil
}
if isFailed(e) {
return fmt.Errorf("The deployment %q status is %q",
name, e.Annotations[deployapi.DeploymentStatusAnnotation])
}
}
}
}
return fmt.Errorf("the deploy did not finish within 3 minutes")
}