本文整理匯總了Golang中github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory.NewBuilder方法的典型用法代碼示例。如果您正苦於以下問題:Golang Factory.NewBuilder方法的具體用法?Golang Factory.NewBuilder怎麽用?Golang Factory.NewBuilder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory
的用法示例。
在下文中一共展示了Factory.NewBuilder方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Complete
//.........這裏部分代碼省略.........
namespace, explicitNamespace, err := f.DefaultNamespace()
if err != nil {
return err
}
allNamespaces := !explicitNamespace && o.AllNamespaces
if len(o.FromKey) > 0 || len(o.ToKey) > 0 {
o.FilterFn = func(info *resource.Info) (bool, error) {
var key string
if info.Mapping.Scope.Name() == meta.RESTScopeNameNamespace {
key = info.Namespace + "/" + info.Name
} else {
if !allNamespaces {
return false, nil
}
key = info.Name
}
if len(o.FromKey) > 0 && o.FromKey > key {
return false, nil
}
if len(o.ToKey) > 0 && o.ToKey <= key {
return false, nil
}
return true, nil
}
}
oclient, _, err := f.Clients()
if err != nil {
return err
}
mapper, _ := f.Object()
resourceNames := sets.NewString()
for i, s := range o.Include {
if resourceNames.Has(s) {
continue
}
if s != "*" {
resourceNames.Insert(s)
break
}
all, err := clientcmd.FindAllCanonicalResources(oclient.Discovery(), mapper)
if err != nil {
return fmt.Errorf("could not calculate the list of available resources: %v", err)
}
exclude := sets.NewString()
for _, gr := range o.DefaultExcludes {
exclude.Insert(gr.String())
}
candidate := sets.NewString()
for _, gr := range all {
// if the user specifies a resource that matches resource or resource+group, skip it
if resourceNames.Has(gr.Resource) || resourceNames.Has(gr.String()) || exclude.Has(gr.String()) {
continue
}
candidate.Insert(gr.String())
}
candidate.Delete(exclude.List()...)
include := candidate
if len(o.OverlappingResources) > 0 {
include = sets.NewString()
for _, k := range candidate.List() {
reduce := k
for _, others := range o.OverlappingResources {
if !others.Has(k) {
continue
}
reduce = others.List()[0]
break
}
include.Insert(reduce)
}
}
glog.V(4).Infof("Found the following resources from the server: %v", include.List())
last := o.Include[i+1:]
o.Include = append([]string{}, o.Include[:i]...)
o.Include = append(o.Include, include.List()...)
o.Include = append(o.Include, last...)
break
}
o.Builder = f.NewBuilder().
AllNamespaces(allNamespaces).
FilenameParam(false, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
ContinueOnError().
DefaultNamespace().
RequireObject(true).
SelectAllParam(true).
Flatten()
if !allNamespaces {
o.Builder.NamespaceParam(namespace)
}
if len(o.Filenames) == 0 {
o.Builder.ResourceTypes(o.Include...)
}
return nil
}