本文整理汇总了Golang中github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory.OpenShiftClientConfig方法的典型用法代码示例。如果您正苦于以下问题:Golang Factory.OpenShiftClientConfig方法的具体用法?Golang Factory.OpenShiftClientConfig怎么用?Golang Factory.OpenShiftClientConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory
的用法示例。
在下文中一共展示了Factory.OpenShiftClientConfig方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Complete
func (o *LogoutOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args []string) error {
kubeconfig, err := f.OpenShiftClientConfig().RawConfig()
o.StartingKubeConfig = &kubeconfig
if err != nil {
return err
}
o.Config, err = f.OpenShiftClientConfig().ClientConfig()
if err != nil {
return err
}
o.PathOptions = config.NewPathOptions(cmd)
return nil
}
示例2: Complete
// Complete completes all the required options.
func (o *NewProjectOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
if len(args) != 1 {
cmd.Help()
return errors.New("must have exactly one argument")
}
o.ProjectName = args[0]
if !o.SkipConfigWrite {
o.ProjectOptions = &ProjectOptions{}
o.ProjectOptions.PathOptions = cliconfig.NewPathOptions(cmd)
if err := o.ProjectOptions.Complete(f, []string{""}, o.Out); err != nil {
return err
}
} else {
clientConfig, err := f.OpenShiftClientConfig().ClientConfig()
if err != nil {
return err
}
o.Server = clientConfig.Host
}
return nil
}
示例3: Complete
func (o *LoginOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args []string, commandName string) error {
kubeconfig, err := f.OpenShiftClientConfig().RawConfig()
o.StartingKubeConfig = &kubeconfig
if err != nil {
if !os.IsNotExist(err) {
return err
}
// build a valid object to use if we failed on a non-existent file
o.StartingKubeConfig = kclientcmdapi.NewConfig()
}
o.CommandName = commandName
if o.CommandName == "" {
o.CommandName = "oc"
}
parsedDefaultClusterURL, err := url.Parse(defaultClusterURL)
if err != nil {
return err
}
addr := flagtypes.Addr{Value: parsedDefaultClusterURL.Host, DefaultScheme: parsedDefaultClusterURL.Scheme, AllowPrefix: true}.Default()
if serverFlag := kcmdutil.GetFlagString(cmd, "server"); len(serverFlag) > 0 {
if err := addr.Set(serverFlag); err != nil {
return err
}
o.Server = addr.String()
} else if len(args) == 1 {
if err := addr.Set(args[0]); err != nil {
return err
}
o.Server = addr.String()
} else if len(o.Server) == 0 {
if defaultContext, defaultContextExists := o.StartingKubeConfig.Contexts[o.StartingKubeConfig.CurrentContext]; defaultContextExists {
if cluster, exists := o.StartingKubeConfig.Clusters[defaultContext.Cluster]; exists {
o.Server = cluster.Server
}
}
}
o.CertFile = kcmdutil.GetFlagString(cmd, "client-certificate")
o.KeyFile = kcmdutil.GetFlagString(cmd, "client-key")
apiVersionString := kcmdutil.GetFlagString(cmd, "api-version")
o.APIVersion = unversioned.GroupVersion{}
// if the API version isn't explicitly passed, use the API version from the default context (same rules as the server above)
if len(apiVersionString) == 0 {
if defaultContext, defaultContextExists := o.StartingKubeConfig.Contexts[o.StartingKubeConfig.CurrentContext]; defaultContextExists {
if cluster, exists := o.StartingKubeConfig.Clusters[defaultContext.Cluster]; exists {
apiVersionString = cluster.APIVersion
}
}
}
o.APIVersion, err = unversioned.ParseGroupVersion(apiVersionString)
if err != nil {
return err
}
o.CAFile = kcmdutil.GetFlagString(cmd, "certificate-authority")
o.InsecureTLS = kcmdutil.GetFlagBool(cmd, "insecure-skip-tls-verify")
o.Token = kcmdutil.GetFlagString(cmd, "token")
o.DefaultNamespace, _, _ = f.DefaultNamespace()
o.PathOptions = config.NewPathOptions(cmd)
return nil
}