本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl.ResourcePrinter类的典型用法代码示例。如果您正苦于以下问题:Golang ResourcePrinter类的具体用法?Golang ResourcePrinter怎么用?Golang ResourcePrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourcePrinter类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (o ViewOptions) Run(out io.Writer, printer kubectl.ResourcePrinter) error {
config, err := o.loadConfig()
if err != nil {
return err
}
if o.Minify {
if err := clientcmdapi.MinifyConfig(config); err != nil {
return err
}
}
if o.Flatten {
if err := clientcmdapi.FlattenConfig(config); err != nil {
return err
}
} else if !o.RawByteData {
clientcmdapi.ShortenConfig(config)
}
err = printer.PrintObj(config, out)
if err != nil {
return err
}
return nil
}
示例2: runListPods
func (l *ListPodsOptions) runListPods(node *kapi.Node, printer kubectl.ResourcePrinter) error {
labelSelector, err := labels.Parse(l.Options.PodSelector)
if err != nil {
return err
}
fieldSelector := fields.Set{GetPodHostFieldLabel(node.TypeMeta.APIVersion): node.ObjectMeta.Name}.AsSelector()
// Filter all pods that satisfies pod label selector and belongs to the given node
pods, err := l.Options.Kclient.Pods(kapi.NamespaceAll).List(labelSelector, fieldSelector)
if err != nil {
return err
}
fmt.Fprintln(l.Options.Writer, "\nListing matched pods on node: ", node.ObjectMeta.Name, "\n")
printer.PrintObj(pods, l.Options.Writer)
return err
}
示例3: RunListPods
func (l *ListPodsOptions) RunListPods(node *kapi.Node) error {
labelSelector, err := labels.Parse(l.Options.PodSelector)
if err != nil {
return err
}
fieldSelector := fields.Set{GetPodHostFieldLabel(node.TypeMeta.APIVersion): node.ObjectMeta.Name}.AsSelector()
// Filter all pods that satisfies pod label selector and belongs to the given node
pods, err := l.Options.Kclient.Pods(kapi.NamespaceAll).List(labelSelector, fieldSelector)
if err != nil {
return err
}
var printerWithHeaders, printerNoHeaders kubectl.ResourcePrinter
if l.Options.CmdPrinterOutput {
printerWithHeaders = l.Options.CmdPrinter
printerNoHeaders = l.Options.CmdPrinter
} else {
printerWithHeaders, printerNoHeaders, err = l.Options.GetPrintersByResource("pod")
if err != nil {
return err
}
}
firstPod := true
for _, pod := range pods.Items {
if firstPod {
fmt.Fprintln(l.Options.Writer, "\nListing matched pods on node: ", node.ObjectMeta.Name, "\n")
printerWithHeaders.PrintObj(&pod, l.Options.Writer)
firstPod = false
} else {
printerNoHeaders.PrintObj(&pod, l.Options.Writer)
}
}
return err
}
示例4: RunEdit
// RunEdit contains all the necessary functionality for the OpenShift cli edit command
func RunEdit(fullName string, f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string, filenames util.StringList) error {
var printer kubectl.ResourcePrinter
var ext string
switch format := cmdutil.GetFlagString(cmd, "output"); format {
case "json":
printer = &kubectl.JSONPrinter{}
ext = ".json"
case "yaml":
printer = &kubectl.YAMLPrinter{}
ext = ".yaml"
default:
return cmdutil.UsageError(cmd, "The flag 'output' must be one of yaml|json")
}
cmdNamespace, err := f.DefaultNamespace()
if err != nil {
return err
}
mapper, typer := f.Object()
rmap := &resource.Mapper{
ObjectTyper: typer,
RESTMapper: mapper,
ClientMapper: f.ClientMapperForCommand(),
}
b := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(filenames...).
//SelectorParam(selector).
ResourceTypeOrNameArgs(true, args...).
Latest()
if err != nil {
return err
}
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
r := b.Flatten().Do()
infos, err := r.Infos()
if err != nil {
return err
}
defaultVersion := cmdutil.OutputVersion(cmd, clientConfig.Version)
results := editResults{}
for {
obj, err := resource.AsVersionedObject(infos, false, defaultVersion)
if err != nil {
return preservedFile(err, results.file, cmd.Out())
}
// TODO: add an annotating YAML printer that can print inline comments on each field,
// including descriptions or validation errors
// generate the file to edit
buf := &bytes.Buffer{}
if err := results.header.WriteTo(buf); err != nil {
return preservedFile(err, results.file, cmd.Out())
}
if err := printer.PrintObj(obj, buf); err != nil {
return preservedFile(err, results.file, cmd.Out())
}
original := buf.Bytes()
// launch the editor
edit := editor.NewDefaultEditor()
edited, file, err := edit.LaunchTempFile("oc-edit-", ext, buf)
if err != nil {
return preservedFile(err, results.file, cmd.Out())
}
// cleanup any file from the previous pass
if len(results.file) > 0 {
os.Remove(results.file)
}
glog.V(4).Infof("User edited:\n%s", string(edited))
lines, err := hasLines(bytes.NewBuffer(edited))
if err != nil {
return preservedFile(err, file, cmd.Out())
}
if bytes.Equal(original, edited) {
if len(results.edit) > 0 {
preservedFile(nil, file, cmd.Out())
} else {
os.Remove(file)
}
fmt.Fprintln(cmd.Out(), "Edit cancelled, no changes made.")
return nil
}
if !lines {
if len(results.edit) > 0 {
preservedFile(nil, file, cmd.Out())
} else {
os.Remove(file)
//.........这里部分代码省略.........