本文整理匯總了Golang中github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory.ClientConfig方法的典型用法代碼示例。如果您正苦於以下問題:Golang Factory.ClientConfig方法的具體用法?Golang Factory.ClientConfig怎麽用?Golang Factory.ClientConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory
的用法示例。
在下文中一共展示了Factory.ClientConfig方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RunRsh
// RunRsh starts a remote shell session on the server
func RunRsh(options *kubecmd.ExecOptions, f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return cmdutil.UsageError(cmd, "rsh requires a single POD to connect to")
}
options.PodName = args[0]
_, client, err := f.Clients()
if err != nil {
return err
}
options.Client = client
namespace, _, err := f.DefaultNamespace()
if err != nil {
return nil
}
options.Namespace = namespace
config, err := f.ClientConfig()
if err != nil {
return err
}
options.Config = config
if err := options.Validate(); err != nil {
return err
}
return options.Run()
}
示例2: Complete
func (v *VolumeOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, out io.Writer) error {
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
v.OutputVersion = kcmdutil.OutputVersion(cmd, clientConfig.Version)
cmdNamespace, explicit, err := f.DefaultNamespace()
if err != nil {
return err
}
mapper, typer := f.Object()
v.DefaultNamespace = cmdNamespace
v.ExplicitNamespace = explicit
v.Writer = out
v.Mapper = mapper
v.Typer = typer
v.RESTClientFactory = f.Factory.RESTClient
v.UpdatePodSpecForObject = f.UpdatePodSpecForObject
// In case of volume source ignore the default volume type
if len(v.AddOpts.Source) > 0 {
v.AddOpts.Type = ""
}
return nil
}
示例3: Execute
// Execute() will run a command in a pod and streams the out/err
func Execute(factory *osclientcmd.Factory, command []string, pod *kapi.Pod, in io.Reader, out, errOut io.Writer) error {
config, err := factory.ClientConfig()
if err != nil {
return err
}
client, err := factory.Client()
if err != nil {
return err
}
execOptions := &kubecmd.ExecOptions{
StreamOptions: kubecmd.StreamOptions{
Namespace: pod.Namespace,
PodName: pod.Name,
ContainerName: pod.Name,
In: in,
Out: out,
Err: errOut,
Stdin: in != nil,
},
Executor: &kubecmd.DefaultRemoteExecutor{},
Client: client,
Config: config,
Command: command,
}
err = execOptions.Validate()
if err != nil {
return err
}
return execOptions.Run()
}
示例4: Complete
func (v *VolumeOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, out io.Writer) error {
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
v.OutputVersion = kcmdutil.OutputVersion(cmd, clientConfig.Version)
cmdNamespace, err := f.DefaultNamespace()
if err != nil {
return err
}
mapper, typer := f.Object()
v.DefaultNamespace = cmdNamespace
v.Writer = out
v.Mapper = mapper
v.Typer = typer
v.RESTClientFactory = f.Factory.RESTClient
v.UpdatePodSpecForObject = f.UpdatePodSpecForObject
if v.Add && len(v.Name) == 0 {
v.Name = kapi.SimpleNameGenerator.GenerateName(volumePrefix)
if len(v.Output) == 0 {
fmt.Fprintf(v.Writer, "Generated volume name: %s\n", v.Name)
}
}
// In case of volume source ignore the default volume type
if len(v.AddOpts.Source) > 0 {
v.AddOpts.Type = ""
}
return nil
}
示例5: Complete
func (v *VolumeOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, out, errOut io.Writer) error {
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
v.OutputVersion, err = kcmdutil.OutputVersion(cmd, clientConfig.GroupVersion)
if err != nil {
return err
}
_, kc, err := f.Clients()
if err != nil {
return err
}
v.Client = kc
cmdNamespace, explicit, err := f.DefaultNamespace()
if err != nil {
return err
}
mapper, typer := f.Object(false)
v.DefaultNamespace = cmdNamespace
v.ExplicitNamespace = explicit
v.Out = out
v.Err = errOut
v.Mapper = mapper
v.Typer = typer
v.RESTClientFactory = f.Factory.ClientForMapping
v.UpdatePodSpecForObject = f.UpdatePodSpecForObject
v.Encoder = f.JSONEncoder()
// In case of volume source ignore the default volume type
if len(v.AddOpts.Source) > 0 {
v.AddOpts.Type = ""
}
if len(v.AddOpts.ClaimSize) > 0 {
v.AddOpts.CreateClaim = true
if len(v.AddOpts.ClaimName) == 0 {
v.AddOpts.ClaimName = kapi.SimpleNameGenerator.GenerateName("pvc-")
}
q, err := kresource.ParseQuantity(v.AddOpts.ClaimSize)
if err != nil {
return fmt.Errorf("--claim-size is not valid: %v", err)
}
v.AddOpts.ClaimSize = q.String()
}
switch strings.ToLower(v.AddOpts.ClaimMode) {
case strings.ToLower(string(kapi.ReadOnlyMany)), "rom":
v.AddOpts.ClaimMode = string(kapi.ReadOnlyMany)
case strings.ToLower(string(kapi.ReadWriteOnce)), "rwo":
v.AddOpts.ClaimMode = string(kapi.ReadWriteOnce)
case strings.ToLower(string(kapi.ReadWriteMany)), "rwm":
v.AddOpts.ClaimMode = string(kapi.ReadWriteMany)
case "":
default:
return errors.New("--claim-mode must be one of ReadWriteOnce (rwo), ReadWriteMany (rwm), or ReadOnlyMany (rom)")
}
return nil
}
示例6: CompleteAppConfig
func CompleteAppConfig(config *newcmd.AppConfig, f *clientcmd.Factory, c *cobra.Command, args []string) error {
mapper, typer := f.Object()
if config.Mapper == nil {
config.Mapper = mapper
}
if config.Typer == nil {
config.Typer = typer
}
if config.ClientMapper == nil {
config.ClientMapper = resource.ClientMapperFunc(f.ClientForMapping)
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
osclient, kclient, err := f.Clients()
if err != nil {
return err
}
config.KubeClient = kclient
dockerClient, _ := getDockerClient()
config.SetOpenShiftClient(osclient, namespace, dockerClient)
if config.AllowSecretUse {
cfg, err := f.ClientConfig()
if err != nil {
return err
}
config.SecretAccessor = newConfigSecretRetriever(cfg)
}
unknown := config.AddArguments(args)
if len(unknown) != 0 {
return kcmdutil.UsageError(c, "Did not recognize the following arguments: %v", unknown)
}
if config.AllowMissingImages && config.AsSearch {
return kcmdutil.UsageError(c, "--allow-missing-images and --search are mutually exclusive.")
}
if len(config.SourceImage) != 0 && len(config.SourceImagePath) == 0 {
return kcmdutil.UsageError(c, "--source-image-path must be specified when --source-image is specified.")
}
if len(config.SourceImage) == 0 && len(config.SourceImagePath) != 0 {
return kcmdutil.UsageError(c, "--source-image must be specified when --source-image-path is specified.")
}
if config.BinaryBuild && config.Strategy == generate.StrategyPipeline {
return kcmdutil.UsageError(c, "specifying binary builds and the pipeline strategy at the same time is not allowed.")
}
return nil
}
示例7: Complete
// Complete takes command line information to fill out BackendOptions or returns an error.
func (o *BackendsOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
cmdNamespace, explicit, err := f.DefaultNamespace()
if err != nil {
return err
}
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
o.OutputVersion, err = kcmdutil.OutputVersion(cmd, clientConfig.GroupVersion)
if err != nil {
return err
}
var resources []string
for _, arg := range args {
if !strings.Contains(arg, "=") {
resources = append(resources, arg)
continue
}
input, err := ParseBackendInput(arg)
if err != nil {
return fmt.Errorf("invalid argument %q: %v", arg, err)
}
o.Transform.Inputs = append(o.Transform.Inputs, *input)
}
o.PrintTable = o.Transform.Empty()
mapper, typer := f.Object(false)
o.Builder = resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), kapi.Codecs.UniversalDecoder()).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, false, o.Filenames...).
SelectorParam(o.Selector).
SelectAllParam(o.All).
ResourceNames("route", resources...).
Flatten()
if len(resources) == 0 {
o.Builder.ResourceTypes("routes")
}
output := kcmdutil.GetFlagString(cmd, "output")
if len(output) != 0 {
o.PrintObject = func(obj runtime.Object) error { return f.PrintObject(cmd, mapper, obj, o.Out) }
}
o.Encoder = f.JSONEncoder()
o.ShortOutput = kcmdutil.GetFlagString(cmd, "output") == "name"
o.Mapper = mapper
return nil
}
示例8: Complete
func (o *BuildHookOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
resources := args
if i := cmd.ArgsLenAtDash(); i != -1 {
resources = args[:i]
o.Command = args[i:]
}
if len(o.Filenames) == 0 && len(args) < 1 {
return kcmdutil.UsageError(cmd, "one or more build configs must be specified as <name> or <resource>/<name>")
}
cmdNamespace, explicit, err := f.DefaultNamespace()
if err != nil {
return err
}
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
o.OutputVersion, err = kcmdutil.OutputVersion(cmd, clientConfig.GroupVersion)
if err != nil {
return err
}
mapper, typer := f.Object(false)
o.Builder = resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), kapi.Codecs.UniversalDecoder()).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, false, o.Filenames...).
SelectorParam(o.Selector).
ResourceNames("buildconfigs", resources...).
Flatten()
if o.All {
o.Builder.ResourceTypes("buildconfigs").SelectAllParam(o.All)
}
output := kcmdutil.GetFlagString(cmd, "output")
if len(output) != 0 {
o.PrintObject = func(infos []*resource.Info) error {
return f.PrintResourceInfos(cmd, infos, o.Out)
}
}
o.Encoder = f.JSONEncoder()
o.ShortOutput = kcmdutil.GetFlagString(cmd, "output") == "name"
o.Mapper = mapper
return nil
}
示例9: newPortForwarder
// newPortForwarder creates a new forwarder for use with rsync
func newPortForwarder(f *clientcmd.Factory, o *RsyncOptions) (forwarder, error) {
client, err := f.Client()
if err != nil {
return nil, err
}
config, err := f.ClientConfig()
if err != nil {
return nil, err
}
return &portForwarder{
Namespace: o.Namespace,
PodName: o.PodName(),
Client: client,
Config: config,
}, nil
}
示例10: Complete
// Complete applies the command environment to RshOptions
func (o *RshOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
switch {
case o.ForceTTY && o.DisableTTY:
return kcmdutil.UsageError(cmd, "you may not specify -t and -T together")
case o.ForceTTY:
o.TTY = true
case o.DisableTTY:
o.TTY = false
default:
o.TTY = term.IsTerminal(o.In)
}
if len(args) < 1 {
return kcmdutil.UsageError(cmd, "rsh requires a single Pod to connect to")
}
resource := args[0]
args = args[1:]
if len(args) > 0 {
o.Command = args
} else {
o.Command = []string{o.Executable}
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
o.Namespace = namespace
config, err := f.ClientConfig()
if err != nil {
return err
}
o.Config = config
client, err := f.Client()
if err != nil {
return err
}
o.Client = client
// TODO: Consider making the timeout configurable
o.PodName, err = f.PodForResource(resource, 10*time.Second)
return err
}
示例11: newRemoteExecutor
func newRemoteExecutor(f *clientcmd.Factory, o *RsyncOptions) (executor, error) {
config, err := f.ClientConfig()
if err != nil {
return nil, err
}
client, err := f.Client()
if err != nil {
return nil, err
}
return &remoteExecutor{
Namespace: o.Namespace,
PodName: o.PodName(),
ContainerName: o.ContainerName,
Config: config,
Client: client,
}, nil
}
示例12: Complete
// Complete completes struct variables.
func (o *EditOptions) Complete(fullName string, f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
o.fullName = fullName
o.args = args
o.out = out
switch format := cmdutil.GetFlagString(cmd, "output"); format {
case "json":
o.printer = &kubectl.JSONPrinter{}
o.ext = ".json"
case "yaml":
o.printer = &kubectl.YAMLPrinter{}
o.ext = ".yaml"
default:
return cmdutil.UsageError(cmd, "The flag 'output' must be one of yaml|json")
}
cmdNamespace, explicit, err := f.DefaultNamespace()
if err != nil {
return err
}
o.namespace = cmdNamespace
mapper, typer := f.Object()
o.rmap = &resource.Mapper{
ObjectTyper: typer,
RESTMapper: mapper,
ClientMapper: f.ClientMapperForCommand(),
}
o.builder = resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
NamespaceParam(o.namespace).DefaultNamespace().
FilenameParam(explicit, o.filenames...).
// SelectorParam(selector).
ResourceTypeOrNameArgs(true, o.args...).
Latest()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
o.version = cmdutil.OutputVersion(cmd, clientConfig.Version)
return nil
}
示例13: RunRsh
// RunRsh starts a remote shell session on the server
func RunRsh(options *kubecmd.ExecOptions, f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
_, client, err := f.Clients()
if err != nil {
return err
}
options.Client = client
namespace, _, err := f.DefaultNamespace()
if err != nil {
return nil
}
options.Namespace = namespace
config, err := f.ClientConfig()
if err != nil {
return err
}
options.Config = config
if err := options.Validate(); err != nil {
return err
}
return options.Run()
}
示例14: Complete
func (o *ProbeOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
resources := args
if i := cmd.ArgsLenAtDash(); i != -1 {
resources = args[:i]
o.Command = args[i:]
}
if len(o.Filenames) == 0 && len(args) < 1 {
return kcmdutil.UsageError(cmd, "one or more resources must be specified as <resource> <name> or <resource>/<name>")
}
cmdNamespace, explicit, err := f.DefaultNamespace()
if err != nil {
return err
}
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
o.OutputVersion, err = kcmdutil.OutputVersion(cmd, clientConfig.GroupVersion)
if err != nil {
return err
}
mapper, typer := f.Object(false)
o.Builder = resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), kapi.Codecs.UniversalDecoder()).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, false, o.Filenames...).
SelectorParam(o.Selector).
ResourceTypeOrNameArgs(o.All, resources...).
Flatten()
output := kcmdutil.GetFlagString(cmd, "output")
if len(output) != 0 {
o.PrintObject = func(obj runtime.Object) error { return f.PrintObject(cmd, mapper, obj, o.Out) }
}
o.Encoder = f.JSONEncoder()
o.UpdatePodSpecForObject = f.UpdatePodSpecForObject
o.ShortOutput = kcmdutil.GetFlagString(cmd, "output") == "name"
o.Mapper = mapper
if !cmd.Flags().Lookup("initial-delay-seconds").Changed {
o.InitialDelaySeconds = nil
}
if !cmd.Flags().Lookup("timeout-seconds").Changed {
o.TimeoutSeconds = nil
}
if !cmd.Flags().Lookup("period-seconds").Changed {
o.PeriodSeconds = nil
}
if !cmd.Flags().Lookup("success-threshold").Changed {
o.SuccessThreshold = nil
}
if !cmd.Flags().Lookup("failure-threshold").Changed {
o.FailureThreshold = nil
}
if len(o.HTTPGet) > 0 {
url, err := url.Parse(o.HTTPGet)
if err != nil {
return fmt.Errorf("--get-url could not be parsed as a valid URL: %v", err)
}
var host, port string
if strings.Contains(url.Host, ":") {
if host, port, err = net.SplitHostPort(url.Host); err != nil {
return fmt.Errorf("--get-url did not have a valid port specification: %v", err)
}
}
if host == "localhost" {
host = ""
}
o.HTTPGetAction = &kapi.HTTPGetAction{
Scheme: kapi.URIScheme(strings.ToUpper(url.Scheme)),
Host: host,
Port: intOrString(port),
Path: url.Path,
}
}
return nil
}
示例15: RunEnv
// RunEnv contains all the necessary functionality for the OpenShift cli env command
// TODO: refactor to share the common "patch resource" pattern of probe
func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Command, args []string, envParams, filenames []string) error {
resources, envArgs, ok := cmdutil.SplitEnvironmentFromResources(args)
if !ok {
return kcmdutil.UsageError(cmd, "all resources must be specified before environment changes: %s", strings.Join(args, " "))
}
if len(filenames) == 0 && len(resources) < 1 {
return kcmdutil.UsageError(cmd, "one or more resources must be specified as <resource> <name> or <resource>/<name>")
}
containerMatch := kcmdutil.GetFlagString(cmd, "containers")
list := kcmdutil.GetFlagBool(cmd, "list")
selector := kcmdutil.GetFlagString(cmd, "selector")
all := kcmdutil.GetFlagBool(cmd, "all")
//overwrite := kcmdutil.GetFlagBool(cmd, "overwrite")
resourceVersion := kcmdutil.GetFlagString(cmd, "resource-version")
outputFormat := kcmdutil.GetFlagString(cmd, "output")
if list && len(outputFormat) > 0 {
return kcmdutil.UsageError(cmd, "--list and --output may not be specified together")
}
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
cmdNamespace, explicit, err := f.DefaultNamespace()
if err != nil {
return err
}
env, remove, err := cmdutil.ParseEnv(append(envParams, envArgs...), in)
if err != nil {
return err
}
mapper, typer := f.Object()
b := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), kapi.Codecs.UniversalDecoder()).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, filenames...).
SelectorParam(selector).
ResourceTypeOrNameArgs(all, resources...).
Flatten()
one := false
infos, err := b.Do().IntoSingular(&one).Infos()
if err != nil {
return err
}
// only apply resource version locking on a single resource
if !one && len(resourceVersion) > 0 {
return kcmdutil.UsageError(cmd, "--resource-version may only be used with a single resource")
}
// Keep a copy of the original objects prior to updating their environment.
// Used in constructing the patch(es) that will be applied in the server.
oldObjects, err := resource.AsVersionedObjects(infos, clientConfig.GroupVersion.String(), kapi.Codecs.LegacyCodec(*clientConfig.GroupVersion))
if err != nil {
return err
}
if len(oldObjects) != len(infos) {
return fmt.Errorf("could not convert all objects to API version %q", clientConfig.GroupVersion)
}
oldData := make([][]byte, len(infos))
for i := range oldObjects {
old, err := json.Marshal(oldObjects[i])
if err != nil {
return err
}
oldData[i] = old
}
skipped := 0
for _, info := range infos {
ok, err := f.UpdatePodSpecForObject(info.Object, func(spec *kapi.PodSpec) error {
containers, _ := selectContainers(spec.Containers, containerMatch)
if len(containers) == 0 {
fmt.Fprintf(cmd.Out(), "warning: %s/%s does not have any containers matching %q\n", info.Mapping.Resource, info.Name, containerMatch)
return nil
}
for _, c := range containers {
c.Env = updateEnv(c.Env, env, remove)
if list {
fmt.Fprintf(out, "# %s %s, container %s\n", info.Mapping.Resource, info.Name, c.Name)
for _, env := range c.Env {
// if env.ValueFrom != nil && env.ValueFrom.FieldRef != nil {
// fmt.Fprintf(cmd.Out(), "%s= # calculated from pod %s %s\n", env.Name, env.ValueFrom.FieldRef.FieldPath, env.ValueFrom.FieldRef.APIVersion)
// continue
// }
fmt.Fprintf(out, "%s=%s\n", env.Name, env.Value)
}
}
}
return nil
})
//.........這裏部分代碼省略.........