本文整理汇总了Golang中github.com/projectatomic/atomic-enterprise/pkg/cmd/util/clientcmd.Factory类的典型用法代码示例。如果您正苦于以下问题:Golang Factory类的具体用法?Golang Factory怎么用?Golang Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunWhoAmI
func RunWhoAmI(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string, o *WhoAmIOptions) error {
if kcmdutil.GetFlagBool(cmd, "token") {
cfg, err := f.OpenShiftClientConfig.ClientConfig()
if err != nil {
return err
}
if len(cfg.BearerToken) == 0 {
return fmt.Errorf("no token is currently in use for this session")
}
fmt.Fprintf(out, "%s\n", cfg.BearerToken)
return nil
}
if kcmdutil.GetFlagBool(cmd, "context") {
cfg, err := f.OpenShiftClientConfig.RawConfig()
if err != nil {
return err
}
if len(cfg.CurrentContext) == 0 {
return fmt.Errorf("no context has been set")
}
fmt.Fprintf(out, "%s\n", cfg.CurrentContext)
return nil
}
client, _, err := f.Clients()
if err != nil {
return err
}
o.UserInterface = client.Users()
o.Out = out
_, err = o.WhoAmI()
return err
}
示例2: Complete
func (o *ProjectOptions) Complete(f *clientcmd.Factory, args []string, out io.Writer) error {
var err error
argsLength := len(args)
switch {
case argsLength > 1:
return errors.New("Only one argument is supported (project name or context name).")
case argsLength == 1:
o.ProjectName = args[0]
}
o.Config, err = f.OpenShiftClientConfig.RawConfig()
if err != nil {
return err
}
o.ClientConfig, err = f.OpenShiftClientConfig.ClientConfig()
if err != nil {
return err
}
o.Client, _, err = f.Clients()
if err != nil {
return err
}
o.Out = out
return nil
}
示例3: setupAppConfig
func setupAppConfig(f *clientcmd.Factory, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
namespace, err := f.DefaultNamespace()
if err != nil {
return err
}
dockerClient, _, err := dockerutil.NewHelper().GetClient()
if err == nil {
if err = dockerClient.Ping(); err == nil {
config.SetDockerClient(dockerClient)
}
}
if err != nil {
glog.V(2).Infof("No local Docker daemon detected: %v", err)
}
osclient, _, err := f.Clients()
if err != nil {
return err
}
config.SetOpenShiftClient(osclient, namespace)
unknown := config.AddArguments(args)
if len(unknown) != 0 {
return cmdutil.UsageError(c, "Did not recognize the following arguments: %v", unknown)
}
return nil
}
示例4: NewCmdWhoCan
// NewCmdWhoCan implements the OpenShift cli who-can command
func NewCmdWhoCan(name, fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
options := &whoCanOptions{}
cmd := &cobra.Command{
Use: "who-can VERB RESOURCE",
Short: "List who can perform the specified action on a resource",
Long: "List who can perform the specified action on a resource",
Run: func(cmd *cobra.Command, args []string) {
if err := options.complete(args); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error()))
}
var err error
if options.client, _, err = f.Clients(); err != nil {
kcmdutil.CheckErr(err)
}
if options.bindingNamespace, err = f.DefaultNamespace(); err != nil {
kcmdutil.CheckErr(err)
}
if err := options.run(); err != nil {
kcmdutil.CheckErr(err)
}
},
}
return cmd
}
示例5: NewCmdRequestProject
func NewCmdRequestProject(name, fullName, oscLoginName, oscProjectName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
options := &NewProjectOptions{}
options.Out = out
cmd := &cobra.Command{
Use: fmt.Sprintf("%s NAME [--display-name=DISPLAYNAME] [--description=DESCRIPTION]", name),
Short: "Request a new project",
Long: fmt.Sprintf(requestProjectLong, oscLoginName, oscProjectName),
Example: fmt.Sprintf(requestProjectExample, fullName),
Run: func(cmd *cobra.Command, args []string) {
if err := options.complete(cmd, f); err != nil {
kcmdutil.CheckErr(err)
}
var err error
if options.Client, _, err = f.Clients(); err != nil {
kcmdutil.CheckErr(err)
}
if err := options.Run(); err != nil {
kcmdutil.CheckErr(err)
}
},
}
cmd.Flags().StringVar(&options.DisplayName, "display-name", "", "Project display name")
cmd.Flags().StringVar(&options.Description, "description", "", "Project description")
return cmd
}
示例6: NewCmdNewProject
// NewCmdNewProject implements the OpenShift cli new-project command
func NewCmdNewProject(name, fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
options := &NewProjectOptions{}
cmd := &cobra.Command{
Use: name + " NAME [--display-name=DISPLAYNAME] [--description=DESCRIPTION]",
Short: "Create a new project",
Long: newProjectLong,
Run: func(cmd *cobra.Command, args []string) {
if err := options.complete(args); err != nil {
kcmdutil.CheckErr(kcmdutil.UsageError(cmd, err.Error()))
}
var err error
if options.Client, _, err = f.Clients(); err != nil {
kcmdutil.CheckErr(err)
}
// We can't depend on len(options.NodeSelector) > 0 as node-selector="" is valid
// and we want to populate node selector as project annotation only if explicitly set by user
useNodeSelector := cmd.Flag("node-selector").Changed
if err := options.Run(useNodeSelector); err != nil {
kcmdutil.CheckErr(err)
}
},
}
cmd.Flags().StringVar(&options.AdminRole, "admin-role", bootstrappolicy.AdminRoleName, "Project admin role name in the cluster policy")
cmd.Flags().StringVar(&options.AdminUser, "admin", "", "Project admin username")
cmd.Flags().StringVar(&options.DisplayName, "display-name", "", "Project display name")
cmd.Flags().StringVar(&options.Description, "description", "", "Project description")
cmd.Flags().StringVar(&options.NodeSelector, "node-selector", "", "Restrict pods onto nodes matching given label selector. Format: '<key1>=<value1>, <key2>=<value2>...'. Specifying \"\" means any node, not default. If unspecified, cluster default node selector will be used.")
return cmd
}
示例7: NewCmdNewBuild
// NewCmdNewBuild implements the OpenShift cli new-build command
func NewCmdNewBuild(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
mapper, typer := f.Object()
clientMapper := f.ClientMapperForCommand()
config := newcmd.NewAppConfig(typer, mapper, clientMapper)
cmd := &cobra.Command{
Use: "new-build (IMAGE | IMAGESTREAM | PATH | URL ...)",
Short: "Create a new build configuration",
Long: newBuildLong,
Example: fmt.Sprintf(newBuildExample, fullName),
Run: func(c *cobra.Command, args []string) {
err := RunNewBuild(fullName, f, out, c, args, config)
if err == errExit {
os.Exit(1)
}
cmdutil.CheckErr(err)
},
}
cmd.Flags().Var(&config.SourceRepositories, "code", "Source code in the build configuration.")
cmd.Flags().VarP(&config.ImageStreams, "image", "i", "Name of an OpenShift image stream to to use as a builder.")
cmd.Flags().Var(&config.DockerImages, "docker-image", "Name of a Docker image to use as a builder.")
cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated build artifacts")
cmd.Flags().StringVar(&config.Strategy, "strategy", "", "Specify the build strategy to use if you don't want to detect (docker|source).")
cmd.Flags().BoolVar(&config.OutputDocker, "to-docker", false, "Force the Build output to be DockerImage.")
cmd.Flags().StringP("labels", "l", "", "Label to set in all generated resources.")
cmdutil.AddPrinterFlags(cmd)
return cmd
}
示例8: Complete
func (o *RoleModificationOptions) Complete(f *clientcmd.Factory, args []string, target *[]string, targetName string, isNamespaced bool) error {
if len(args) < 2 {
return fmt.Errorf("You must specify at least two arguments: <role> <%s> [%s]...", targetName, targetName)
}
o.RoleName = args[0]
*target = append(*target, args[1:]...)
osClient, _, err := f.Clients()
if err != nil {
return err
}
if isNamespaced {
roleBindingNamespace, err := f.DefaultNamespace()
if err != nil {
return err
}
o.RoleBindingAccessor = NewLocalRoleBindingAccessor(roleBindingNamespace, osClient)
} else {
o.RoleBindingAccessor = NewClusterRoleBindingAccessor(osClient)
}
return nil
}
示例9: RunImportImage
// RunImportImage contains all the necessary functionality for the OpenShift cli import-image command.
func RunImportImage(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
if len(args) == 0 || len(args[0]) == 0 {
return cmdutil.UsageError(cmd, "you must specify the name of an image stream.")
}
streamName := args[0]
namespace, err := f.DefaultNamespace()
if err != nil {
return err
}
osClient, _, err := f.Clients()
if err != nil {
return err
}
imageStreamClient := osClient.ImageStreams(namespace)
stream, err := imageStreamClient.Get(streamName)
if err != nil {
return err
}
if len(stream.Spec.DockerImageRepository) == 0 {
return errors.New("only image streams with spec.dockerImageRepository set may have images imported")
}
if stream.Annotations == nil {
stream.Annotations = make(map[string]string)
}
stream.Annotations[imageapi.DockerImageRepositoryCheckAnnotation] = ""
updatedStream, err := imageStreamClient.Update(stream)
if err != nil {
return err
}
resourceVersion := updatedStream.ResourceVersion
fmt.Fprintln(cmd.Out(), "Waiting for the import to complete, CTRL+C to stop waiting.")
updatedStream, err = waitForImport(imageStreamClient, stream.Name, resourceVersion)
if err != nil {
return fmt.Errorf("unable to determine if the import completed successfully - please run 'oc describe -n %s imagestream/%s' to see if the tags were updated as expected: %v", stream.Namespace, stream.Name, err)
}
fmt.Fprintln(cmd.Out(), "The import completed successfully.\n")
d := describe.ImageStreamDescriber{osClient}
info, err := d.Describe(updatedStream.Namespace, updatedStream.Name)
if err != nil {
return err
}
fmt.Fprintln(out, info)
return nil
}
示例10: determineSourceKind
func determineSourceKind(f *clientcmd.Factory, input string) string {
mapper, _ := f.Object()
_, kind, err := mapper.VersionAndKindForResource(input)
if err == nil {
return kind
}
// DockerImage isn't in RESTMapper
switch strings.ToLower(input) {
case "docker", "dockerimage":
return "DockerImage"
}
return input
}
示例11: Complete
func (o *RemoveFromProjectOptions) Complete(f *clientcmd.Factory, args []string, target *[]string, targetName string) error {
if len(args) < 1 {
return fmt.Errorf("You must specify at least one argument: <%s> [%s]...", targetName, targetName)
}
*target = append(*target, args...)
var err error
if o.Client, _, err = f.Clients(); err != nil {
return err
}
if o.BindingNamespace, err = f.DefaultNamespace(); err != nil {
return err
}
return nil
}
示例12: NewCmdNewApplication
// NewCmdNewApplication implements the OpenShift cli new-app command
func NewCmdNewApplication(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
mapper, typer := f.Object()
clientMapper := f.ClientMapperForCommand()
config := newcmd.NewAppConfig(typer, mapper, clientMapper)
cmd := &cobra.Command{
Use: "new-app (IMAGE | IMAGESTREAM | TEMPLATE | PATH | URL ...)",
Short: "Create a new application",
Long: newAppLong,
Example: fmt.Sprintf(newAppExample, fullName),
Run: func(c *cobra.Command, args []string) {
err := RunNewApplication(fullName, f, out, c, args, config)
if err == errExit {
os.Exit(1)
}
cmdutil.CheckErr(err)
},
}
cmd.Flags().Var(&config.SourceRepositories, "code", "Source code to use to build this application.")
cmd.Flags().StringVar(&config.ContextDir, "context-dir", "", "Context directory to be used for the build.")
cmd.Flags().VarP(&config.ImageStreams, "image", "i", "Name of an OpenShift image stream to use in the app.")
cmd.Flags().Var(&config.DockerImages, "docker-image", "Name of a Docker image to include in the app.")
cmd.Flags().Var(&config.Templates, "template", "Name of an OpenShift stored template to use in the app.")
cmd.Flags().VarP(&config.TemplateFiles, "file", "f", "Path to a template file to use for the app.")
cmd.Flags().VarP(&config.TemplateParameters, "param", "p", "Specify a list of key value pairs (eg. -p FOO=BAR,BAR=FOO) to set/override parameter values in the template.")
cmd.Flags().Var(&config.Groups, "group", "Indicate components that should be grouped together as <comp1>+<comp2>.")
cmd.Flags().VarP(&config.Environment, "env", "e", "Specify key value pairs of environment variables to set into each container.")
cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated application artifacts")
cmd.Flags().StringVar(&config.Strategy, "strategy", "", "Specify the build strategy to use if you don't want to detect (docker|source).")
cmd.Flags().StringP("labels", "l", "", "Label to set in all resources for this application.")
cmd.Flags().BoolVar(&config.InsecureRegistry, "insecure-registry", false, "If true, indicates that the referenced Docker images are on insecure registries and should bypass certificate checking")
// TODO AddPrinterFlags disabled so that it doesn't conflict with our own "template" flag.
// Need a better solution.
// cmdutil.AddPrinterFlags(cmd)
cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml|template|templatefile.")
cmd.Flags().String("output-version", "", "Output the formatted object with the given version (default api-version).")
cmd.Flags().Bool("no-headers", false, "When using the default output, don't print headers.")
cmd.Flags().String("output-template", "", "Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]")
return cmd
}
示例13: Complete
func (o *DeployOptions) Complete(f *clientcmd.Factory, args []string, out io.Writer) error {
var err error
o.osClient, o.kubeClient, err = f.Clients()
if err != nil {
return err
}
o.namespace, err = f.DefaultNamespace()
if err != nil {
return err
}
o.out = out
if len(args) > 0 {
o.deploymentConfigName = args[0]
}
return nil
}
示例14: 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 = string(kutil.NewUUID())
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
}
示例15: Complete
func (n *NodeOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args []string, out io.Writer) error {
defaultNamespace, err := f.DefaultNamespace()
if err != nil {
return err
}
_, kc, err := f.Clients()
if err != nil {
return err
}
cmdPrinter, output, err := kcmdutil.PrinterForCommand(c)
if err != nil {
return err
}
mapper, typer := f.Object()
n.DefaultNamespace = defaultNamespace
n.Kclient = kc
n.Writer = out
n.Mapper = mapper
n.Typer = typer
n.RESTClientFactory = f.Factory.RESTClient
n.Printer = f.Printer
n.NodeNames = []string{}
n.CmdPrinter = cmdPrinter
n.CmdPrinterOutput = false
if output {
n.CmdPrinterOutput = true
}
if len(args) != 0 {
n.NodeNames = append(n.NodeNames, args...)
}
return nil
}