當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Factory.StatusViewer方法代碼示例

本文整理匯總了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
}
開發者ID:ttysteale,項目名稱:kubernetes-api,代碼行數:80,代碼來源:rollout_status.go


注:本文中的github.com/ttysteale/kubernetes-api/kubectl/cmd/util.Factory.StatusViewer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。