本文整理匯總了Golang中github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory.ApproximatePodTemplateForObject方法的典型用法代碼示例。如果您正苦於以下問題:Golang Factory.ApproximatePodTemplateForObject方法的具體用法?Golang Factory.ApproximatePodTemplateForObject怎麽用?Golang Factory.ApproximatePodTemplateForObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory
的用法示例。
在下文中一共展示了Factory.ApproximatePodTemplateForObject方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Complete
func (o *DebugOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args []string, in io.Reader, out, errout io.Writer) error {
if i := cmd.ArgsLenAtDash(); i != -1 && i < len(args) {
o.Command = args[i:]
args = args[:i]
}
resources, envArgs, ok := cmdutil.SplitEnvironmentFromResources(args)
if !ok {
return kcmdutil.UsageError(cmd, "all resources must be specified before environment changes: %s", strings.Join(args, " "))
}
switch {
case o.ForceTTY && o.NoStdin:
return kcmdutil.UsageError(cmd, "you may not specify -I and -t together")
case o.ForceTTY && o.DisableTTY:
return kcmdutil.UsageError(cmd, "you may not specify -t and -T together")
case o.ForceTTY:
o.Attach.TTY = true
case o.DisableTTY:
o.Attach.TTY = false
// don't default TTY to true if a command is passed
case len(o.Command) > 0:
o.Attach.TTY = false
o.Attach.Stdin = false
default:
o.Attach.TTY = term.IsTerminal(in)
glog.V(4).Infof("Defaulting TTY to %t", o.Attach.TTY)
}
if o.NoStdin {
o.Attach.TTY = false
o.Attach.Stdin = false
}
if o.Annotations == nil {
o.Annotations = make(map[string]string)
}
if len(o.Command) == 0 {
o.Command = []string{"/bin/sh"}
}
cmdNamespace, explicit, err := f.DefaultNamespace()
if err != nil {
return err
}
mapper, typer := f.Object(false)
b := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), kapi.Codecs.UniversalDecoder()).
NamespaceParam(cmdNamespace).DefaultNamespace().
SingleResourceType().
ResourceNames("pods", resources...).
Flatten()
if len(o.Filename) > 0 {
b.FilenameParam(explicit, false, o.Filename)
}
o.AddEnv, o.RemoveEnv, err = cmdutil.ParseEnv(envArgs, nil)
if err != nil {
return err
}
one := false
infos, err := b.Do().IntoSingular(&one).Infos()
if err != nil {
return err
}
if !one {
return fmt.Errorf("you must identify a resource with a pod template to debug")
}
template, err := f.ApproximatePodTemplateForObject(infos[0].Object)
if err != nil && template == nil {
return fmt.Errorf("cannot debug %s: %v", infos[0].Name, err)
}
if err != nil {
glog.V(4).Infof("Unable to get exact template, but continuing with fallback: %v", err)
}
pod := &kapi.Pod{
ObjectMeta: template.ObjectMeta,
Spec: template.Spec,
}
pod.Name, pod.Namespace = infos[0].Name, infos[0].Namespace
o.Attach.Pod = pod
o.AsNonRoot = !o.AsRoot && cmd.Flag("as-root").Changed
if len(o.Attach.ContainerName) == 0 && len(pod.Spec.Containers) > 0 {
glog.V(4).Infof("Defaulting container name to %s", pod.Spec.Containers[0].Name)
o.Attach.ContainerName = pod.Spec.Containers[0].Name
}
o.Annotations[debugPodAnnotationSourceResource] = fmt.Sprintf("%s/%s", infos[0].Mapping.Resource, infos[0].Name)
o.Annotations[debugPodAnnotationSourceContainer] = o.Attach.ContainerName
output := kcmdutil.GetFlagString(cmd, "output")
if len(output) != 0 {
o.Print = func(pod *kapi.Pod, out io.Writer) error {
return f.PrintObject(cmd, mapper, pod, out)
}
}
//.........這裏部分代碼省略.........