本文整理汇总了Golang中github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory类的典型用法代码示例。如果您正苦于以下问题:Golang Factory类的具体用法?Golang Factory怎么用?Golang Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: Complete
// Complete verifies command line arguments and loads data from the command environment
func (o *RsyncOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
switch n := len(args); {
case n == 0:
cmd.Help()
fallthrough
case n < 2:
return kcmdutil.UsageError(cmd, "SOURCE_DIR and POD:DESTINATION_DIR are required arguments")
case n > 2:
return kcmdutil.UsageError(cmd, "only SOURCE_DIR and POD:DESTINATION_DIR should be specified as arguments")
}
// Set main command arguments
var err error
o.Source, err = parsePathSpec(args[0])
if err != nil {
return err
}
o.Destination, err = parsePathSpec(args[1])
if err != nil {
return err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
o.Namespace = namespace
o.Strategy, err = o.determineStrategy(f, cmd, o.StrategyName)
if err != nil {
return err
}
return nil
}
示例3: NewCmdNewBuild
// NewCmdNewBuild implements the OpenShift cli new-build command
func NewCmdNewBuild(fullName string, f *clientcmd.Factory, in io.Reader, 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) {
config.AddEnvironmentToBuild = true
err := RunNewBuild(fullName, f, out, in, 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 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().VarP(&config.Environment, "env", "e", "Specify key value pairs of environment variables to set into resulting image.")
cmd.Flags().StringVar(&config.Strategy, "strategy", "", "Specify the build strategy to use if you don't want to detect (docker|source).")
cmd.Flags().StringVarP(&config.Dockerfile, "dockerfile", "D", "", "Specify the contents of a Dockerfile to build directly, implies --strategy=docker. Pass '-' to read from STDIN.")
cmd.Flags().BoolVar(&config.OutputDocker, "to-docker", false, "Have the build output push to a Docker repository.")
cmd.Flags().StringP("labels", "l", "", "Label to set in all generated resources.")
cmdutil.AddPrinterFlags(cmd)
return cmd
}
示例4: 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
}
示例5: 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
}
示例6: Complete
// Complete turns a partially defined TopImagesOptions into a solvent structure
// which can be validated and used for showing limits usage.
func (o *TopImagesOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
osClient, kClient, err := f.Clients()
if err != nil {
return err
}
namespace := cmd.Flag("namespace").Value.String()
if len(namespace) == 0 {
namespace = kapi.NamespaceAll
}
o.out = out
allImages, err := osClient.Images().List(kapi.ListOptions{})
if err != nil {
return err
}
o.Images = allImages
allStreams, err := osClient.ImageStreams(namespace).List(kapi.ListOptions{})
if err != nil {
return err
}
o.Streams = allStreams
allPods, err := kClient.Pods(namespace).List(kapi.ListOptions{})
if err != nil {
return err
}
o.Pods = allPods
return nil
}
示例7: Complete
func (o *MigrateImageReferenceOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args []string) error {
var remainingArgs []string
for _, s := range args {
if !strings.Contains(s, "=") {
remainingArgs = append(remainingArgs, s)
continue
}
mapping, err := ParseMapping(s)
if err != nil {
return err
}
o.Mappings = append(o.Mappings, mapping)
}
o.UpdatePodSpecFn = f.UpdatePodSpecForObject
if len(remainingArgs) > 0 {
return fmt.Errorf("all arguments must be valid FROM=TO mappings")
}
o.ResourceOptions.SaveFn = o.save
if err := o.ResourceOptions.Complete(f, c); err != nil {
return err
}
osclient, _, err := f.Clients()
if err != nil {
return err
}
o.Client = osclient
return nil
}
示例8: Run
func (o *NewApplicationOptions) Run(f *clientcmd.Factory) error {
application := &applicationapi.Application{}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
_, err = o.Client.Applications(namespace).Get(o.Name)
if err == nil {
return errors.New(fmt.Sprintf("application %s already exists", o.Name))
}
application.Spec.Items = o.Items
application.Annotations = make(map[string]string)
application.Labels = map[string]string{}
application.Name = o.Name
application.GenerateName = o.Name
if _, err = o.Client.Applications(namespace).Create(application); err != nil {
return err
}
return nil
}
示例9: NewCmdApplication
func NewCmdApplication(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
options := &NewApplicationOptions{}
options.Out = out
cmd := &cobra.Command{
Use: `new-application NAME [--items="KIND=KINDNAME,KIND=KINDNAME"]`,
Short: "create a new application",
Long: newApplicationLong,
Example: fmt.Sprintf(newApplicationExample, fullName),
Run: func(cmd *cobra.Command, args []string) {
var err error
if err = options.complete(cmd, f); err != nil {
kcmdutil.CheckErr(err)
return
}
if options.Client, _, err = f.Clients(); err != nil {
kcmdutil.CheckErr(err)
}
if err := options.Run(f); err != nil {
fmt.Printf("run err %s\n", err.Error())
} else {
fmt.Printf("create application %s success.\n", options.Name)
}
},
}
cmd.Flags().StringVar(&options.Item, "items", "", "application items")
return cmd
}
示例10: RunGraph
// RunGraph contains all the necessary functionality for the OpenShift cli graph command
func RunGraph(f *clientcmd.Factory, out io.Writer) error {
client, kclient, err := f.Clients()
if err != nil {
return err
}
config, err := f.OpenShiftClientConfig.ClientConfig()
if err != nil {
return err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
describer := &describe.ProjectStatusDescriber{K: kclient, C: client, Server: config.Host}
g, _, err := describer.MakeGraph(namespace)
if err != nil {
return err
}
data, err := dot.Marshal(g, namespace, "", " ", false)
if err != nil {
return err
}
fmt.Fprintf(out, "%s", string(data))
return nil
}
示例11: Complete
func (o *NewServiceAccountTokenOptions) Complete(args []string, requestedLabels string, f *clientcmd.Factory, cmd *cobra.Command) error {
if len(args) != 1 {
return cmdutil.UsageError(cmd, fmt.Sprintf("expected one service account name as an argument, got %q", args))
}
o.SAName = args[0]
if len(requestedLabels) > 0 {
labels, err := kubectl.ParseLabels(requestedLabels)
if err != nil {
return cmdutil.UsageError(cmd, err.Error())
}
o.Labels = labels
}
client, err := f.Client()
if err != nil {
return err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return fmt.Errorf("could not retrieve default namespace: %v", err)
}
o.SAClient = client.ServiceAccounts(namespace)
o.SecretsClient = client.Secrets(namespace)
return nil
}
示例12: RunStatus
// RunStatus contains all the necessary functionality for the OpenShift cli status command
func RunStatus(f *clientcmd.Factory, out io.Writer) error {
client, kclient, err := f.Clients()
if err != nil {
return err
}
config, err := f.OpenShiftClientConfig.ClientConfig()
if err != nil {
return err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
describer := &describe.ProjectStatusDescriber{K: kclient, C: client, Server: config.Host}
s, err := describer.Describe(namespace, "")
if err != nil {
return err
}
fmt.Fprintf(out, s)
return nil
}
示例13: 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
}
示例14: RunReconcileSCCs
// RunReconcileSCCs contains the functionality for the reconcile-sccs command for making or
// previewing changes.
func (o *ReconcileSCCOptions) RunReconcileSCCs(cmd *cobra.Command, f *clientcmd.Factory) error {
// get sccs that need updated
changedSCCs, err := o.ChangedSCCs()
if err != nil {
return err
}
if len(changedSCCs) == 0 {
return nil
}
if !o.Confirmed {
list := &kapi.List{}
for _, item := range changedSCCs {
list.Items = append(list.Items, item)
}
mapper, _ := f.Object(false)
fn := cmdutil.VersionedPrintObject(f.PrintObject, cmd, mapper, o.Out)
if err := fn(list); err != nil {
return err
}
}
if o.Confirmed {
return o.ReplaceChangedSCCs(changedSCCs)
}
return nil
}
示例15: 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
}