本文整理汇总了Golang中k8s/io/kubernetes/pkg/kubectl/cmd/util.Factory.ClientSet方法的典型用法代码示例。如果您正苦于以下问题:Golang Factory.ClientSet方法的具体用法?Golang Factory.ClientSet怎么用?Golang Factory.ClientSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/kubectl/cmd/util.Factory
的用法示例。
在下文中一共展示了Factory.ClientSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Complete
// Complete fills CreateBasicAuthSecretOptions fields with data and checks for mutual exclusivity
// between flags from different option groups.
func (o *CreateBasicAuthSecretOptions) Complete(f kcmdutil.Factory, args []string) error {
if len(args) != 1 {
return errors.New("must have exactly one argument: secret name")
}
o.SecretName = args[0]
if o.PromptForPassword {
if len(o.Password) != 0 {
return errors.New("must provide either --prompt or --password flag")
}
if !kterm.IsTerminal(o.Reader) {
return errors.New("provided reader is not a terminal")
}
o.Password = term.PromptForPasswordString(o.Reader, o.Out, "Password: ")
if len(o.Password) == 0 {
return errors.New("password must be provided")
}
}
if f != nil {
client, err := f.ClientSet()
if err != nil {
return err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
o.SecretsInterface = client.Core().Secrets(namespace)
}
return nil
}
示例2: execute
func execute(f cmdutil.Factory, cmd *cobra.Command, options *ExecOptions) error {
if len(options.Namespace) == 0 {
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
options.Namespace = namespace
}
container := cmdutil.GetFlagString(cmd, "container")
if len(container) > 0 {
options.ContainerName = container
}
config, err := f.ClientConfig()
if err != nil {
return err
}
options.Config = config
clientset, err := f.ClientSet()
if err != nil {
return err
}
options.PodClient = clientset.Core()
if err := options.Validate(); err != nil {
return err
}
if err := options.Run(); err != nil {
return err
}
return nil
}
示例3: createSecret
// createSecret extracts the kubeconfig for a given cluster and populates
// a secret with that kubeconfig.
func createSecret(hostFactory cmdutil.Factory, clientConfig *clientcmdapi.Config, namespace, contextName, secretName string, dryRun bool) (runtime.Object, error) {
// Minify the kubeconfig to ensure that there is only information
// relevant to the cluster we are registering.
newClientConfig, err := minifyConfig(clientConfig, contextName)
if err != nil {
glog.V(2).Infof("Failed to minify the kubeconfig for the given context %q: %v", contextName, err)
return nil, err
}
// Flatten the kubeconfig to ensure that all the referenced file
// contents are inlined.
err = clientcmdapi.FlattenConfig(newClientConfig)
if err != nil {
glog.V(2).Infof("Failed to flatten the kubeconfig for the given context %q: %v", contextName, err)
return nil, err
}
// Boilerplate to create the secret in the host cluster.
clientset, err := hostFactory.ClientSet()
if err != nil {
glog.V(2).Infof("Failed to serialize the kubeconfig for the given context %q: %v", contextName, err)
return nil, err
}
return util.CreateKubeconfigSecret(clientset, newClientConfig, namespace, secretName, dryRun)
}
示例4: RunVersion
func RunVersion(f cmdutil.Factory, out io.Writer, cmd *cobra.Command) error {
v := fmt.Sprintf("%#v", version.Get())
if cmdutil.GetFlagBool(cmd, "short") {
v = version.Get().GitVersion
}
fmt.Fprintf(out, "Client Version: %s\n", v)
if cmdutil.GetFlagBool(cmd, "client") {
return nil
}
clientset, err := f.ClientSet()
if err != nil {
return err
}
serverVersion, err := clientset.Discovery().ServerVersion()
if err != nil {
return err
}
v = fmt.Sprintf("%#v", *serverVersion)
if cmdutil.GetFlagBool(cmd, "short") {
v = serverVersion.GitVersion
}
fmt.Fprintf(out, "Server Version: %s\n", v)
return nil
}
示例5: deleteSecret
// deleteSecret deletes the secret with the given name from the host
// cluster.
func deleteSecret(hostFactory cmdutil.Factory, name, namespace string) error {
clientset, err := hostFactory.ClientSet()
if err != nil {
return err
}
return clientset.Core().Secrets(namespace).Delete(name, &api.DeleteOptions{})
}
示例6: Complete
// Complete verifies command line arguments and loads data from the command environment
func (p *AttachOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn []string) error {
if len(argsIn) == 0 {
return cmdutil.UsageError(cmd, "POD is required for attach")
}
if len(argsIn) > 1 {
return cmdutil.UsageError(cmd, fmt.Sprintf("expected a single argument: POD, saw %d: %s", len(argsIn), argsIn))
}
p.PodName = argsIn[0]
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
p.Namespace = namespace
config, err := f.ClientConfig()
if err != nil {
return err
}
p.Config = config
clientset, err := f.ClientSet()
if err != nil {
return err
}
p.PodClient = clientset.Core()
if p.CommandName == "" {
p.CommandName = cmd.CommandPath()
}
return nil
}
示例7: handleAttachPod
func handleAttachPod(f *cmdutil.Factory, c *client.Client, ns, name string, opts *AttachOptions, quiet bool) error {
pod, err := waitForPodRunning(c, ns, name, opts.Out, quiet)
if err != nil {
return err
}
ctrName, err := opts.GetContainerName(pod)
if err != nil {
return err
}
if pod.Status.Phase == api.PodSucceeded || pod.Status.Phase == api.PodFailed {
req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: ctrName})
if err != nil {
return err
}
readCloser, err := req.Stream()
if err != nil {
return err
}
defer readCloser.Close()
_, err = io.Copy(opts.Out, readCloser)
return err
}
clientset, err := f.ClientSet()
if err != nil {
return nil
}
opts.PodClient = clientset.Core()
opts.PodName = name
opts.Namespace = ns
// TODO: opts.Run sets opts.Err to nil, we need to find a better way
stderr := opts.Err
if err := opts.Run(); err != nil {
fmt.Fprintf(stderr, "Error attaching, falling back to logs: %v\n", err)
req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: ctrName})
if err != nil {
return err
}
readCloser, err := req.Stream()
if err != nil {
return err
}
defer readCloser.Close()
_, err = io.Copy(opts.Out, readCloser)
return err
}
return nil
}
示例8: Complete
// Complete verifies command line arguments and loads data from the command environment
func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
// Let kubectl exec follow rules for `--`, see #13004 issue
if len(p.PodName) == 0 && (len(argsIn) == 0 || argsLenAtDash == 0) {
return cmdutil.UsageError(cmd, execUsageStr)
}
if len(p.PodName) != 0 {
printDeprecationWarning("exec POD_NAME", "-p POD_NAME")
if len(argsIn) < 1 {
return cmdutil.UsageError(cmd, execUsageStr)
}
p.Command = argsIn
} else {
p.PodName = argsIn[0]
p.Command = argsIn[1:]
if len(p.Command) < 1 {
return cmdutil.UsageError(cmd, execUsageStr)
}
}
cmdParent := cmd.Parent()
if cmdParent != nil {
p.FullCmdName = cmdParent.CommandPath()
}
if len(p.FullCmdName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "describe") {
p.SuggestedCmdUsage = fmt.Sprintf("Use '%s describe pod/%s' to see all of the containers in this pod.", p.FullCmdName, p.PodName)
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
p.Namespace = namespace
config, err := f.ClientConfig()
if err != nil {
return err
}
p.Config = config
clientset, err := f.ClientSet()
if err != nil {
return err
}
p.PodClient = clientset.Core()
return nil
}
示例9: Complete
func (o *TopNodeOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
var err error
if len(args) == 1 {
o.ResourceName = args[0]
} else if len(args) > 1 {
return cmdutil.UsageError(cmd, cmd.Use)
}
clientset, err := f.ClientSet()
if err != nil {
return err
}
o.NodeClient = clientset.Core()
o.Client = metricsutil.DefaultHeapsterMetricsClient(clientset.Core())
o.Printer = metricsutil.NewTopCmdPrinter(out)
return nil
}
示例10: RunVersion
func RunVersion(f cmdutil.Factory, out io.Writer, cmd *cobra.Command) error {
kubectl.GetClientVersion(out)
if cmdutil.GetFlagBool(cmd, "client") {
return nil
}
clientset, err := f.ClientSet()
if err != nil {
return err
}
serverVersion, err := clientset.Discovery().ServerVersion()
if err != nil {
return err
}
fmt.Fprintf(out, "Server Version: %#v\n", *serverVersion)
return nil
}
示例11: Complete
// Complete verifies command line arguments and loads data from the command environment
func (p *ExecOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
if len(p.FullCmdName) == 0 {
p.FullCmdName = "kubectl"
}
// Let kubectl exec follow rules for `--`, see #13004 issue
if len(p.PodName) == 0 && (len(argsIn) == 0 || argsLenAtDash == 0) {
return cmdutil.UsageError(cmd, execUsageStr)
}
if len(p.PodName) != 0 {
printDeprecationWarning("exec POD_NAME", "-p POD_NAME")
if len(argsIn) < 1 {
return cmdutil.UsageError(cmd, execUsageStr)
}
p.Command = argsIn
} else {
p.PodName = argsIn[0]
p.Command = argsIn[1:]
if len(p.Command) < 1 {
return cmdutil.UsageError(cmd, execUsageStr)
}
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
p.Namespace = namespace
config, err := f.ClientConfig()
if err != nil {
return err
}
p.Config = config
clientset, err := f.ClientSet()
if err != nil {
return err
}
p.PodClient = clientset.Core()
return nil
}
示例12: RunApiVersions
func RunApiVersions(f cmdutil.Factory, w io.Writer) error {
if len(os.Args) > 1 && os.Args[1] == "apiversions" {
printDeprecationWarning("api-versions", "apiversions")
}
clientset, err := f.ClientSet()
if err != nil {
return err
}
groupList, err := clientset.Discovery().ServerGroups()
if err != nil {
return fmt.Errorf("Couldn't get available api versions from server: %v\n", err)
}
apiVersions := unversioned.ExtractGroupVersions(groupList)
sort.Strings(apiVersions)
for _, v := range apiVersions {
fmt.Fprintln(w, v)
}
return nil
}
示例13: Complete
func (o *TopPodOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
var err error
if len(args) == 1 {
o.ResourceName = args[0]
} else if len(args) > 1 {
return cmdutil.UsageError(cmd, cmd.Use)
}
o.Namespace, _, err = f.DefaultNamespace()
if err != nil {
return err
}
clientset, err := f.ClientSet()
if err != nil {
return err
}
o.PodClient = clientset.Core()
o.Client = metricsutil.NewHeapsterMetricsClient(clientset.Core(), o.HeapsterOptions.Namespace, o.HeapsterOptions.Scheme, o.HeapsterOptions.Service, o.HeapsterOptions.Port)
o.Printer = metricsutil.NewTopCmdPrinter(out)
return nil
}
示例14: Complete
// Complete completes all the required options for port-forward cmd.
func (o *PortForwardOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string, cmdOut io.Writer, cmdErr io.Writer) error {
var err error
o.PodName = cmdutil.GetFlagString(cmd, "pod")
if len(o.PodName) == 0 && len(args) == 0 {
return cmdutil.UsageError(cmd, "POD is required for port-forward")
}
if len(o.PodName) != 0 {
printDeprecationWarning("port-forward POD", "-p POD")
o.Ports = args
} else {
o.PodName = args[0]
o.Ports = args[1:]
}
o.Namespace, _, err = f.DefaultNamespace()
if err != nil {
return err
}
clientset, err := f.ClientSet()
if err != nil {
return err
}
o.PodClient = clientset.Core()
o.Config, err = f.ClientConfig()
if err != nil {
return err
}
o.RESTClient, err = f.RESTClient()
if err != nil {
return err
}
o.StopChannel = make(chan struct{}, 1)
o.ReadyChannel = make(chan struct{})
return nil
}
示例15: modifyCertificateCondition
func (options *CertificateOptions) modifyCertificateCondition(f cmdutil.Factory, out io.Writer, modify func(csr *certificates.CertificateSigningRequest) (*certificates.CertificateSigningRequest, string)) error {
var found int
mapper, typer := f.Object()
c, err := f.ClientSet()
if err != nil {
return err
}
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
FilenameParam(false, &options.FilenameOptions).
ResourceNames("certificatesigningrequest", options.csrNames...).
RequireObject(true).
Flatten().
Latest().
Do()
err = r.Visit(func(info *resource.Info, err error) error {
if err != nil {
return err
}
csr := info.Object.(*certificates.CertificateSigningRequest)
csr, verb := modify(csr)
csr, err = c.Certificates().
CertificateSigningRequests().
UpdateApproval(csr)
if err != nil {
return err
}
found++
cmdutil.PrintSuccess(mapper, options.outputStyle == "name", out, info.Mapping.Resource, info.Name, false, verb)
return nil
})
if found == 0 {
fmt.Fprintf(out, "No resources found\n")
}
return err
}