本文整理汇总了Golang中k8s/io/kubernetes/pkg/kubectl.ResourceShortFormFor函数的典型用法代码示例。如果您正苦于以下问题:Golang ResourceShortFormFor函数的具体用法?Golang ResourceShortFormFor怎么用?Golang ResourceShortFormFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceShortFormFor函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunGet
//.........这里部分代码省略.........
for ix := range infos {
objs[ix] = infos[ix].Object
}
sorting, err := cmd.Flags().GetString("sort-by")
if err != nil {
return err
}
var sorter *kubectl.RuntimeSort
if len(sorting) > 0 && len(objs) > 1 {
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
version, err := cmdutil.OutputVersion(cmd, clientConfig.GroupVersion)
if err != nil {
return err
}
for ix := range infos {
objs[ix], err = infos[ix].Mapping.ConvertToVersion(infos[ix].Object, version)
if err != nil {
allErrs = append(allErrs, err)
continue
}
}
// TODO: questionable
if sorter, err = kubectl.SortObjects(f.Decoder(true), objs, sorting); err != nil {
return err
}
}
// use the default printer for each object
printer = nil
var lastMapping *meta.RESTMapping
w := kubectl.GetNewTabWriter(out)
if mustPrintWithKinds(objs, infos, sorter, printAll) {
showKind = true
}
for ix := range objs {
var mapping *meta.RESTMapping
var original runtime.Object
if sorter != nil {
mapping = infos[sorter.OriginalPosition(ix)].Mapping
original = infos[sorter.OriginalPosition(ix)].Object
} else {
mapping = infos[ix].Mapping
original = infos[ix].Object
}
if printer == nil || lastMapping == nil || mapping == nil || mapping.Resource != lastMapping.Resource {
if printer != nil {
w.Flush()
printer.AfterPrint(errOut, lastMapping.Resource)
}
printer, err = f.PrinterForMapping(cmd, mapping, allNamespaces)
if err != nil {
allErrs = append(allErrs, err)
continue
}
lastMapping = mapping
}
if resourcePrinter, found := printer.(*kubectl.HumanReadablePrinter); found {
resourceName := resourcePrinter.GetResourceKind()
if mapping != nil {
if resourceName == "" {
resourceName = mapping.Resource
}
if alias, ok := kubectl.ResourceShortFormFor(mapping.Resource); ok {
resourceName = alias
} else if resourceName == "" {
resourceName = "none"
}
} else {
resourceName = "none"
}
if showKind {
resourcePrinter.EnsurePrintWithKind(resourceName)
}
if err := printer.PrintObj(original, w); err != nil {
allErrs = append(allErrs, err)
}
continue
}
if err := printer.PrintObj(original, w); err != nil {
allErrs = append(allErrs, err)
continue
}
}
w.Flush()
if printer != nil {
printer.AfterPrint(errOut, lastMapping.Resource)
}
return utilerrors.NewAggregate(allErrs)
}
示例2: RunGet
//.........这里部分代码省略.........
}
}
// use the default printer for each object
printer = nil
var lastMapping *meta.RESTMapping
w := kubectl.GetNewTabWriter(out)
filteredResourceCount := 0
if resource.MultipleTypesRequested(args) || cmdutil.MustPrintWithKinds(objs, infos, sorter) {
showKind = true
}
for ix := range objs {
var mapping *meta.RESTMapping
var original runtime.Object
if sorter != nil {
mapping = infos[sorter.OriginalPosition(ix)].Mapping
original = infos[sorter.OriginalPosition(ix)].Object
} else {
mapping = infos[ix].Mapping
original = infos[ix].Object
}
if printer == nil || lastMapping == nil || mapping == nil || mapping.Resource != lastMapping.Resource {
if printer != nil {
w.Flush()
cmdutil.PrintFilterCount(filteredResourceCount, lastMapping.Resource, filterOpts)
}
printer, err = f.PrinterForMapping(cmd, mapping, allNamespaces)
if err != nil {
if !errs.Has(err.Error()) {
errs.Insert(err.Error())
allErrs = append(allErrs, err)
}
continue
}
// add linebreak between resource groups (if there is more than one)
// skip linebreak above first resource group
noHeaders := cmdutil.GetFlagBool(cmd, "no-headers")
if lastMapping != nil && !noHeaders {
fmt.Fprintf(errOut, "%s\n", "")
}
lastMapping = mapping
}
// filter objects if filter has been defined for current object
if isFiltered, err := filterFuncs.Filter(original, filterOpts); isFiltered {
if err == nil {
filteredResourceCount++
continue
}
if !errs.Has(err.Error()) {
errs.Insert(err.Error())
allErrs = append(allErrs, err)
}
}
if resourcePrinter, found := printer.(*kubectl.HumanReadablePrinter); found {
resourceName := resourcePrinter.GetResourceKind()
if mapping != nil {
if resourceName == "" {
resourceName = mapping.Resource
}
if alias, ok := kubectl.ResourceShortFormFor(mapping.Resource); ok {
resourceName = alias
} else if resourceName == "" {
resourceName = "none"
}
} else {
resourceName = "none"
}
if showKind {
resourcePrinter.EnsurePrintWithKind(resourceName)
}
if err := printer.PrintObj(original, w); err != nil {
if !errs.Has(err.Error()) {
errs.Insert(err.Error())
allErrs = append(allErrs, err)
}
}
continue
}
if err := printer.PrintObj(original, w); err != nil {
if !errs.Has(err.Error()) {
errs.Insert(err.Error())
allErrs = append(allErrs, err)
}
continue
}
}
w.Flush()
if printer != nil && lastMapping != nil {
cmdutil.PrintFilterCount(filteredResourceCount, lastMapping.Resource, filterOpts)
}
return utilerrors.NewAggregate(allErrs)
}
示例3: RunGet
//.........这里部分代码省略.........
}
objs := make([]runtime.Object, len(infos))
for ix := range infos {
objs[ix] = infos[ix].Object
}
sorting, err := cmd.Flags().GetString("sort-by")
var sorter *kubectl.RuntimeSort
if err == nil && len(sorting) > 0 && len(objs) > 1 {
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
version, err := cmdutil.OutputVersion(cmd, clientConfig.GroupVersion)
if err != nil {
return err
}
for ix := range infos {
objs[ix], err = infos[ix].Mapping.ConvertToVersion(infos[ix].Object, version)
if err != nil {
allErrs = append(allErrs, err)
continue
}
}
// TODO: questionable
if sorter, err = kubectl.SortObjects(f.Decoder(true), objs, sorting); err != nil {
return err
}
}
// use the default printer for each object
printer = nil
var lastMapping *meta.RESTMapping
var withKind bool = allKinds
w := kubectl.GetNewTabWriter(out)
defer w.Flush()
// determine if printing multiple kinds of
// objects and enforce "show-kinds" flag if so
for ix := range objs {
var mapping *meta.RESTMapping
if sorter != nil {
mapping = infos[sorter.OriginalPosition(ix)].Mapping
} else {
mapping = infos[ix].Mapping
}
// display "kind" column only if we have mixed resources
if lastMapping != nil && mapping.Resource != lastMapping.Resource {
withKind = true
}
lastMapping = mapping
}
lastMapping = nil
for ix := range objs {
var mapping *meta.RESTMapping
var original runtime.Object
if sorter != nil {
mapping = infos[sorter.OriginalPosition(ix)].Mapping
original = infos[sorter.OriginalPosition(ix)].Object
} else {
mapping = infos[ix].Mapping
original = infos[ix].Object
}
if printer == nil || lastMapping == nil || mapping == nil || mapping.Resource != lastMapping.Resource {
printer, err = f.PrinterForMapping(cmd, mapping, allNamespaces)
if err != nil {
allErrs = append(allErrs, err)
continue
}
lastMapping = mapping
}
if resourcePrinter, found := printer.(*kubectl.HumanReadablePrinter); found {
resourceName := mapping.Resource
if alias, ok := kubectl.ResourceShortFormFor(mapping.Resource); ok {
resourceName = alias
} else if resourceName == "" {
resourceName = "none"
}
resourcePrinter.Options.WithKind = withKind
resourcePrinter.Options.KindName = resourceName
if err := printer.PrintObj(original, w); err != nil {
allErrs = append(allErrs, err)
}
continue
}
if err := printer.PrintObj(original, w); err != nil {
allErrs = append(allErrs, err)
continue
}
}
return utilerrors.NewAggregate(allErrs)
}