本文整理汇总了Golang中k8s/io/kubernetes/pkg/kubectl/cmd/util.FilterResourceList函数的典型用法代码示例。如果您正苦于以下问题:Golang FilterResourceList函数的具体用法?Golang FilterResourceList怎么用?Golang FilterResourceList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FilterResourceList函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Example_printPodHideTerminated
func Example_printPodHideTerminated() {
f, tf, _, ns := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(kubectl.PrintOptions{
ColumnLabels: []string{},
})
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
Client: nil,
}
cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr)
podList := newAllPhasePodList()
// filter pods
filterFuncs := f.DefaultResourceFilterFunc()
filterOpts := f.DefaultResourceFilterOptions(cmd, false)
_, filteredPodList, errs := cmdutil.FilterResourceList(podList, filterFuncs, filterOpts)
if errs != nil {
fmt.Printf("Unexpected filter error: %v\n", errs)
}
for _, pod := range filteredPodList {
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, pod, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
}
}
// Output:
// NAME READY STATUS RESTARTS AGE
// test1 1/2 Pending 6 10y
// test2 1/2 Running 6 10y
// test5 1/2 Unknown 6 10y
}
示例2: RunConvert
// RunConvert implements the generic Convert command
func (o *ConvertOptions) RunConvert() error {
r := o.builder.Do()
err := r.Err()
if err != nil {
return err
}
singular := false
infos, err := r.IntoSingular(&singular).Infos()
if err != nil {
return err
}
if len(infos) == 0 {
return fmt.Errorf("no objects passed to convert")
}
objects, err := resource.AsVersionedObject(infos, !singular, o.outputVersion, o.encoder)
if err != nil {
return err
}
if meta.IsListType(objects) {
_, items, err := cmdutil.FilterResourceList(objects, nil, nil)
if err != nil {
return err
}
filteredObj, err := cmdutil.ObjectListToVersionedObject(items, o.outputVersion)
if err != nil {
return err
}
return o.printer.PrintObj(filteredObj, o.out)
}
return o.printer.PrintObj(objects, o.out)
}
示例3: RunGet
//.........这里部分代码省略.........
return err
}
errs = append(errs, err)
}
if len(infos) == 0 && len(errs) == 0 {
outputEmptyListWarning(errOut)
}
res := ""
if len(infos) > 0 {
res = infos[0].ResourceMapping().Resource
}
var obj runtime.Object
if singular {
obj = infos[0].Object
} else {
// we have more than one item, so coerce all items into a list
list := &runtime.UnstructuredList{
Object: map[string]interface{}{
"kind": "List",
"apiVersion": "v1",
"metadata": map[string]interface{}{},
},
}
for _, info := range infos {
list.Items = append(list.Items, info.Object.(*runtime.Unstructured))
}
obj = list
}
isList := meta.IsListType(obj)
if isList {
filteredResourceCount, items, err := cmdutil.FilterResourceList(obj, filterFuncs, filterOpts)
if err != nil {
return err
}
// take the filtered items and create a new list for display
list := &runtime.UnstructuredList{
Object: map[string]interface{}{
"kind": "List",
"apiVersion": "v1",
"metadata": map[string]interface{}{},
},
}
if listMeta, err := meta.ListAccessor(obj); err == nil {
list.Object["selfLink"] = listMeta.GetSelfLink()
list.Object["resourceVersion"] = listMeta.GetResourceVersion()
}
for _, item := range items {
list.Items = append(list.Items, item.(*runtime.Unstructured))
}
if err := printer.PrintObj(list, out); err != nil {
errs = append(errs, err)
}
cmdutil.PrintFilterCount(filteredResourceCount, res, filterOpts)
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
}
filteredResourceCount := 0
if isFiltered, err := filterFuncs.Filter(obj, filterOpts); !isFiltered {
if err != nil {
glog.V(2).Infof("Unable to filter resource: %v", err)
示例4: RunGet
//.........这里部分代码省略.........
if err != nil {
return err
}
// the outermost object will be converted to the output-version, but inner
// objects can use their mappings
version, err := cmdutil.OutputVersion(cmd, clientConfig.GroupVersion)
if err != nil {
return err
}
var errs []error
singular := false
infos, err := r.IntoSingular(&singular).Infos()
if err != nil {
if singular {
return err
}
errs = append(errs, err)
}
res := ""
if len(infos) > 0 {
res = infos[0].ResourceMapping().Resource
}
obj, err := resource.AsVersionedObject(infos, !singular, version, f.JSONEncoder())
if err != nil {
return err
}
isList := meta.IsListType(obj)
if isList {
filteredResourceCount, items, err := cmdutil.FilterResourceList(obj, filterFuncs, filterOpts)
if err != nil {
return err
}
filteredObj, err := cmdutil.ObjectListToVersionedObject(items, version)
if err != nil {
return err
}
if err := printer.PrintObj(filteredObj, out); err != nil {
errs = append(errs, err)
}
cmdutil.PrintFilterCount(filteredResourceCount, res, errOut, filterOpts)
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
}
filteredResourceCount := 0
if isFiltered, err := filterFuncs.Filter(obj, filterOpts); !isFiltered {
if err != nil {
glog.V(2).Infof("Unable to filter resource: %v", err)
} else if err := printer.PrintObj(obj, out); err != nil {
errs = append(errs, err)
}
} else if isFiltered {
filteredResourceCount++
}
cmdutil.PrintFilterCount(filteredResourceCount, res, errOut, filterOpts)
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
}
allErrs := []error{}
infos, err := r.Infos()