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


Golang Factory.Reaper方法代碼示例

本文整理匯總了Golang中vulcan/kubernetes/pkg/kubectl/cmd/util.Factory.Reaper方法的典型用法代碼示例。如果您正苦於以下問題:Golang Factory.Reaper方法的具體用法?Golang Factory.Reaper怎麽用?Golang Factory.Reaper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vulcan/kubernetes/pkg/kubectl/cmd/util.Factory的用法示例。


在下文中一共展示了Factory.Reaper方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ReapResult

func ReapResult(r *resource.Result, f *cmdutil.Factory, resp *restful.Response, isDefaultDelete, ignoreNotFound bool, timeout time.Duration, gracePeriod int) error {
	var obj runtime.Object
	found := 0
	if ignoreNotFound {
		r = r.IgnoreErrors(errors.IsNotFound)
	}
	err := r.Visit(func(info *resource.Info) error {
		found++
		reaper, err := f.Reaper(info.Mapping)
		if err != nil {
			// If there is no reaper for this resources and the user didn't explicitly ask for stop.
			if kubectl.IsNoSuchReaperError(err) && isDefaultDelete {
				return deleteResource(info, resp)
			}
			return cmdutil.AddSourceToErr("reaping", info.Source, err)
		}
		var options *api.DeleteOptions
		if gracePeriod >= 0 {
			options = api.NewDeleteOptions(int64(gracePeriod))
		}
		if _, err := reaper.Stop(info.Namespace, info.Name, timeout, options); err != nil {
			return cmdutil.AddSourceToErr("stopping", info.Source, err)
		}
		message := fmt.Sprintf("delete %s/%s success", info.Mapping.Resource, info.Name)
		resp.WriteAsJson(ApiResult{message, info.Object, true})
		return nil
	})
	if err != nil {
		return err
	}
	if found == 0 {
		resp.WriteAsJson(ApiResult{"no resources found", obj, true})
	}
	return nil
}
開發者ID:qinguoan,項目名稱:vulcan,代碼行數:35,代碼來源:delete_handler.go

示例2: ReapResult

func ReapResult(r *resource.Result, f *cmdutil.Factory, out io.Writer, isDefaultDelete, ignoreNotFound bool, timeout time.Duration, gracePeriod int, shortOutput bool, mapper meta.RESTMapper) error {
	found := 0
	if ignoreNotFound {
		r = r.IgnoreErrors(errors.IsNotFound)
	}
	err := r.Visit(func(info *resource.Info, err error) error {
		if err != nil {
			return err
		}
		found++
		reaper, err := f.Reaper(info.Mapping)
		if err != nil {
			// If there is no reaper for this resources and the user didn't explicitly ask for stop.
			if kubectl.IsNoSuchReaperError(err) && isDefaultDelete {
				return deleteResource(info, out, shortOutput, mapper)
			}
			return cmdutil.AddSourceToErr("reaping", info.Source, err)
		}
		var options *api.DeleteOptions
		if gracePeriod >= 0 {
			options = api.NewDeleteOptions(int64(gracePeriod))
		}
		if _, err := reaper.Stop(info.Namespace, info.Name, timeout, options); err != nil {
			return cmdutil.AddSourceToErr("stopping", info.Source, err)
		}
		cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, "deleted")
		return nil
	})
	if err != nil {
		return err
	}
	if found == 0 {
		fmt.Fprintf(out, "No resources found\n")
	}
	return nil
}
開發者ID:qinguoan,項目名稱:vulcan,代碼行數:36,代碼來源:delete.go


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