本文整理汇总了Golang中github.com/ttysteale/kubernetes-api/kubectl/cmd/util.Factory.StatusViewer方法的典型用法代码示例。如果您正苦于以下问题:Golang Factory.StatusViewer方法的具体用法?Golang Factory.StatusViewer怎么用?Golang Factory.StatusViewer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ttysteale/kubernetes-api/kubectl/cmd/util.Factory
的用法示例。
在下文中一共展示了Factory.StatusViewer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunStatus
func RunStatus(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []string, options *StatusOptions) error {
if len(args) == 0 && len(options.Filenames) == 0 {
return cmdutil.UsageError(cmd, "Required resource not specified.")
}
mapper, typer := f.Object(false)
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil {
return err
}
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(enforceNamespace, options.Recursive, options.Filenames...).
ResourceTypeOrNameArgs(true, args...).
SingleResourceType().
Latest().
Do()
err = r.Err()
if err != nil {
return err
}
infos, err := r.Infos()
if err != nil {
return err
}
if len(infos) != 1 {
return fmt.Errorf("rollout status is only supported on individual resources and resource collections - %d resources were found", len(infos))
}
info := infos[0]
mapping := info.ResourceMapping()
obj, err := r.Object()
if err != nil {
return err
}
rv, err := mapping.MetadataAccessor.ResourceVersion(obj)
if err != nil {
return err
}
statusViewer, err := f.StatusViewer(mapping)
if err != nil {
return err
}
// check if deployment's has finished the rollout
status, done, err := statusViewer.Status(cmdNamespace, info.Name)
if err != nil {
return err
}
fmt.Fprintf(out, "%s", status)
if done {
return nil
}
// watch for changes to the deployment
w, err := r.Watch(rv)
if err != nil {
return err
}
// if the rollout isn't done yet, keep watching deployment status
kubectl.WatchLoop(w, func(e watch.Event) error {
// print deployment's status
status, done, err := statusViewer.Status(cmdNamespace, info.Name)
if err != nil {
return err
}
fmt.Fprintf(out, "%s", status)
// Quit waiting if the rollout is done
if done {
w.Stop()
}
return nil
})
return nil
}