本文整理汇总了Golang中k8s/io/kubernetes/pkg/client.ReplicationControllerInterface.Watch方法的典型用法代码示例。如果您正苦于以下问题:Golang ReplicationControllerInterface.Watch方法的具体用法?Golang ReplicationControllerInterface.Watch怎么用?Golang ReplicationControllerInterface.Watch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/client.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 {
for {
requirement, err := labels.NewRequirement(deployapi.DeploymentConfigAnnotation, labels.EqualsOperator, kutil.NewStringSet(name))
if err != nil {
return fmt.Errorf("unexpected error generating label selector: %v", err)
}
list, err := client.List(labels.LabelSelector{*requirement})
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])
}
}
}
}
}