本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned/clientcmd.ClientConfig.ClientConfig方法的典型用法代码示例。如果您正苦于以下问题:Golang ClientConfig.ClientConfig方法的具体用法?Golang ClientConfig.ClientConfig怎么用?Golang ClientConfig.ClientConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/client/unversioned/clientcmd.ClientConfig
的用法示例。
在下文中一共展示了ClientConfig.ClientConfig方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Complete
// Complete verifies command line arguments and loads data from the command environment
func (app *App) Complete(clientConfig clientcmd.ClientConfig) error {
p := app.ExecOptions
// Let kubectl exec follow rules for `--`, see #13004 issue
if len(p.PodName) == 0 {
return fmt.Errorf("POD is required for exec")
}
if len(p.Command) < 1 {
return fmt.Errorf("COMMAND is required for exec")
}
if clientConfig == nil {
return fmt.Errorf("kubeconfig is required for exec")
}
namespace, _, err := clientConfig.Namespace() //f.DefaultNamespace()
if err != nil {
return err
}
p.Namespace = namespace
config, err := clientConfig.ClientConfig() //f.ClientConfig()
if err != nil {
return err
}
p.Config = config
client, err := kclient.New(config) //f.Client()
if err != nil {
return err
}
p.Client = client
return nil
}
示例2: NewFactory
// NewFactory creates an object that holds common methods across all OpenShift commands
func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
restMapper := registered.RESTMapper()
clients := &clientCache{
clients: make(map[string]*client.Client),
configs: make(map[string]*restclient.Config),
loader: clientConfig,
}
w := &Factory{
Factory: cmdutil.NewFactory(clientConfig),
OpenShiftClientConfig: clientConfig,
clients: clients,
ImageResolutionOptions: &imageResolutionOptions{},
}
w.Object = func(bool) (meta.RESTMapper, runtime.ObjectTyper) {
defaultMapper := ShortcutExpander{RESTMapper: kubectl.ShortcutExpander{RESTMapper: restMapper}}
defaultTyper := api.Scheme
// Output using whatever version was negotiated in the client cache. The
// version we decode with may not be the same as what the server requires.
cfg, err := clients.ClientConfigForVersion(nil)
if err != nil {
return defaultMapper, defaultTyper
}
cmdApiVersion := unversioned.GroupVersion{}
if cfg.GroupVersion != nil {
cmdApiVersion = *cfg.GroupVersion
}
// at this point we've negotiated and can get the client
oclient, err := clients.ClientForVersion(nil)
if err != nil {
return defaultMapper, defaultTyper
}
cacheDir := computeDiscoverCacheDir(filepath.Join(homedir.HomeDir(), ".kube"), cfg.Host)
cachedDiscoverClient := NewCachedDiscoveryClient(client.NewDiscoveryClient(oclient.RESTClient), cacheDir, time.Duration(10*time.Minute))
// if we can't find the server version or its too old to have Kind information in the discovery doc, skip the discovery RESTMapper
// and use our hardcoded levels
mapper := registered.RESTMapper()
if serverVersion, err := cachedDiscoverClient.ServerVersion(); err == nil && useDiscoveryRESTMapper(serverVersion.GitVersion) {
mapper = restmapper.NewDiscoveryRESTMapper(cachedDiscoverClient)
}
mapper = NewShortcutExpander(cachedDiscoverClient, kubectl.ShortcutExpander{RESTMapper: mapper})
return kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []unversioned.GroupVersion{cmdApiVersion}}, api.Scheme
}
w.UnstructuredObject = func() (meta.RESTMapper, runtime.ObjectTyper, error) {
// load a discovery client from the default config
cfg, err := clients.ClientConfigForVersion(nil)
if err != nil {
return nil, nil, err
}
dc, err := discovery.NewDiscoveryClientForConfig(cfg)
if err != nil {
return nil, nil, err
}
cacheDir := computeDiscoverCacheDir(filepath.Join(homedir.HomeDir(), ".kube"), cfg.Host)
cachedDiscoverClient := NewCachedDiscoveryClient(client.NewDiscoveryClient(dc.RESTClient), cacheDir, time.Duration(10*time.Minute))
// enumerate all group resources
groupResources, err := discovery.GetAPIGroupResources(cachedDiscoverClient)
if err != nil {
return nil, nil, err
}
// Register unknown APIs as third party for now to make
// validation happy. TODO perhaps make a dynamic schema
// validator to avoid this.
for _, group := range groupResources {
for _, version := range group.Group.Versions {
gv := unversioned.GroupVersion{Group: group.Group.Name, Version: version.Version}
if !registered.IsRegisteredVersion(gv) {
registered.AddThirdPartyAPIGroupVersions(gv)
}
}
}
// construct unstructured mapper and typer
mapper := discovery.NewRESTMapper(groupResources, meta.InterfacesForUnstructured)
typer := discovery.NewUnstructuredObjectTyper(groupResources)
return NewShortcutExpander(cachedDiscoverClient, kubectl.ShortcutExpander{RESTMapper: mapper}), typer, nil
}
kClientForMapping := w.Factory.ClientForMapping
w.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
if latest.OriginKind(mapping.GroupVersionKind) {
mappingVersion := mapping.GroupVersionKind.GroupVersion()
client, err := clients.ClientForVersion(&mappingVersion)
if err != nil {
return nil, err
}
return client.RESTClient, nil
}
return kClientForMapping(mapping)
//.........这里部分代码省略.........
示例3: NewFactory
// NewFactory creates an object that holds common methods across all OpenShift commands
func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
mapper := ShortcutExpander{kubectl.ShortcutExpander{latest.RESTMapper}}
clients := &clientCache{
clients: make(map[string]*client.Client),
loader: clientConfig,
}
generators := map[string]kubectl.Generator{
"route/v1": routegen.RouteGenerator{},
"run/v1": deploygen.BasicDeploymentConfigController{},
"run-controller/v1": kubectl.BasicReplicationController{},
}
w := &Factory{
Factory: cmdutil.NewFactory(clientConfig),
OpenShiftClientConfig: clientConfig,
clients: clients,
}
w.Object = func() (meta.RESTMapper, runtime.ObjectTyper) {
if cfg, err := clientConfig.ClientConfig(); err == nil {
return kubectl.OutputVersionMapper{mapper, cfg.Version}, api.Scheme
}
return mapper, api.Scheme
}
kRESTClient := w.Factory.RESTClient
w.RESTClient = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
if latest.OriginKind(mapping.Kind, mapping.APIVersion) {
client, err := clients.ClientForVersion(mapping.APIVersion)
if err != nil {
return nil, err
}
return client.RESTClient, nil
}
return kRESTClient(mapping)
}
// Save original Describer function
kDescriberFunc := w.Factory.Describer
w.Describer = func(mapping *meta.RESTMapping) (kubectl.Describer, error) {
if latest.OriginKind(mapping.Kind, mapping.APIVersion) {
oClient, kClient, err := w.Clients()
if err != nil {
return nil, fmt.Errorf("unable to create client %s: %v", mapping.Kind, err)
}
cfg, err := clients.ClientConfigForVersion(mapping.APIVersion)
if err != nil {
return nil, fmt.Errorf("unable to load a client %s: %v", mapping.Kind, err)
}
describer, ok := describe.DescriberFor(mapping.Kind, oClient, kClient, cfg.Host)
if !ok {
return nil, fmt.Errorf("no description has been implemented for %q", mapping.Kind)
}
return describer, nil
}
return kDescriberFunc(mapping)
}
kScalerFunc := w.Factory.Scaler
w.Scaler = func(mapping *meta.RESTMapping) (kubectl.Scaler, error) {
oc, kc, err := w.Clients()
if err != nil {
return nil, err
}
if mapping.Kind == "DeploymentConfig" {
return deployscaler.NewDeploymentConfigScaler(oc, kc), nil
}
return kScalerFunc(mapping)
}
kReaperFunc := w.Factory.Reaper
w.Reaper = func(mapping *meta.RESTMapping) (kubectl.Reaper, error) {
oc, kc, err := w.Clients()
if err != nil {
return nil, err
}
if mapping.Kind == "DeploymentConfig" {
return deployreaper.NewDeploymentConfigReaper(oc, kc), nil
}
return kReaperFunc(mapping)
}
kGeneratorFunc := w.Factory.Generator
w.Generator = func(name string) (kubectl.Generator, bool) {
if generator, ok := generators[name]; ok {
return generator, true
}
return kGeneratorFunc(name)
}
kPodSelectorForObjectFunc := w.Factory.PodSelectorForObject
w.PodSelectorForObject = func(object runtime.Object) (string, error) {
switch t := object.(type) {
case *deployapi.DeploymentConfig:
return kubectl.MakeLabels(t.Template.ControllerTemplate.Selector), nil
default:
return kPodSelectorForObjectFunc(object)
//.........这里部分代码省略.........