本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/typed/discovery.NewDiscoveryClientForConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDiscoveryClientForConfig函数的具体用法?Golang NewDiscoveryClientForConfig怎么用?Golang NewDiscoveryClientForConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDiscoveryClientForConfig函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: UnstructuredObject
func (f *factory) UnstructuredObject() (meta.RESTMapper, runtime.ObjectTyper, error) {
cfg, err := f.clients.ClientConfigForVersion(nil)
if err != nil {
return nil, nil, err
}
dc, err := discovery.NewDiscoveryClientForConfig(cfg)
if err != nil {
return nil, nil, err
}
groupResources, err := discovery.GetAPIGroupResources(dc)
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)
}
}
}
mapper := discovery.NewRESTMapper(groupResources, meta.InterfacesForUnstructured)
typer := discovery.NewUnstructuredObjectTyper(groupResources)
return NewShortcutExpander(mapper, dc), typer, nil
}
开发者ID:Random-Liu,项目名称:kubernetes,代码行数:34,代码来源:factory.go
示例2: NewForConfig
// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *restclient.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var cs Clientset
var err error
cs.CoreV1Client, err = v1core.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
cs.BatchV1Client, err = v1batch.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
cs.ExtensionsV1beta1Client, err = v1beta1extensions.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
cs.FederationV1beta1Client, err = v1beta1federation.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
if err != nil {
glog.Errorf("failed to create the DiscoveryClient: %v", err)
return nil, err
}
return &cs, nil
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:32,代码来源:clientset.go
示例3: NewForConfig
// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *restclient.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var clientset Clientset
var err error
clientset.CoreClient, err = unversionedcore.NewForConfig(&configShallowCopy)
if err != nil {
return &clientset, err
}
clientset.ExtensionsClient, err = unversionedextensions.NewForConfig(&configShallowCopy)
if err != nil {
return &clientset, err
}
clientset.AutoscalingClient, err = unversionedautoscaling.NewForConfig(&configShallowCopy)
if err != nil {
return &clientset, err
}
clientset.BatchClient, err = unversionedbatch.NewForConfig(&configShallowCopy)
if err != nil {
return &clientset, err
}
clientset.RbacClient, err = unversionedrbac.NewForConfig(&configShallowCopy)
if err != nil {
return &clientset, err
}
clientset.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
if err != nil {
glog.Errorf("failed to create the DiscoveryClient: %v", err)
}
return &clientset, err
}
开发者ID:40a,项目名称:bootkube,代码行数:35,代码来源:clientset.go
示例4: checkCertsAPI
func checkCertsAPI(config *restclient.Config) error {
discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
if err != nil {
return fmt.Errorf("failed to create API discovery client [%v]", err)
}
serverGroups, err := discoveryClient.ServerGroups()
if err != nil {
return fmt.Errorf("failed to retrieve a list of supported API objects [%v]", err)
}
for _, group := range serverGroups.Groups {
if group.Name == certificates.GroupName {
return nil
}
}
version, err := discoveryClient.ServerVersion()
if err != nil {
return fmt.Errorf("unable to obtain API version [%v]", err)
}
return fmt.Errorf("API version %s does not support certificates API, use v1.4.0 or newer", version.String())
}
开发者ID:ravihansa3000,项目名称:kubernetes,代码行数:26,代码来源:csr.go
示例5: getDefaultConfig
// also looks up the discovery client. We can't do this during init because the flags won't have been set
// because this is constructed pre-command execution before the command tree is even set up
func (c *ClientCache) getDefaultConfig() (restclient.Config, discovery.DiscoveryInterface, error) {
c.defaultConfigLock.Lock()
defer c.defaultConfigLock.Unlock()
if c.defaultConfig != nil && c.discoveryClient != nil {
return *c.defaultConfig, c.discoveryClient, nil
}
config, err := c.loader.ClientConfig()
if err != nil {
return restclient.Config{}, nil, err
}
discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
if err != nil {
return restclient.Config{}, nil, err
}
if c.matchVersion {
if err := discovery.MatchesServerVersion(discoveryClient); err != nil {
return restclient.Config{}, nil, err
}
}
c.defaultConfig = config
c.discoveryClient = discoveryClient
return *c.defaultConfig, c.discoveryClient, nil
}
开发者ID:eljefedelrodeodeljefe,项目名称:kubernetes,代码行数:28,代码来源:clientcache.go
示例6: DiscoveryClient
func (f *FakeFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
discoveryClient, err := discovery.NewDiscoveryClientForConfig(f.tf.ClientConfig)
if err != nil {
return nil, err
}
return &fakeCachedDiscoveryClient{DiscoveryInterface: discoveryClient}, nil
}
开发者ID:nak3,项目名称:kubernetes,代码行数:7,代码来源:fake.go
示例7: Object
func (f *factory) Object() (meta.RESTMapper, runtime.ObjectTyper) {
cfg, err := f.clientConfig.ClientConfig()
checkErrWithPrefix("failed to get client config: ", err)
cmdApiVersion := unversioned.GroupVersion{}
if cfg.GroupVersion != nil {
cmdApiVersion = *cfg.GroupVersion
}
mapper := registered.RESTMapper()
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
if err == nil {
mapper = meta.FirstHitRESTMapper{
MultiRESTMapper: meta.MultiRESTMapper{
discovery.NewDeferredDiscoveryRESTMapper(discoveryClient, registered.InterfacesFor),
registered.RESTMapper(), // hardcoded fall back
},
}
}
// wrap with shortcuts
mapper = NewShortcutExpander(mapper, discoveryClient)
// wrap with output preferences
mapper = kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []unversioned.GroupVersion{cmdApiVersion}}
return mapper, api.Scheme
}
开发者ID:oszi,项目名称:kubernetes,代码行数:25,代码来源:factory.go
示例8: NewForConfig
// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *restclient.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var clientset Clientset
var err error
clientset.CoreClient, err = v1core.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.AppsClient, err = v1alpha1apps.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.AuthenticationClient, err = v1beta1authentication.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.AuthorizationClient, err = v1beta1authorization.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.AutoscalingClient, err = v1autoscaling.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.BatchClient, err = v1batch.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.CertificatesClient, err = v1alpha1certificates.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.ExtensionsClient, err = v1beta1extensions.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.PolicyClient, err = v1alpha1policy.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.RbacClient, err = v1alpha1rbac.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.StorageClient, err = v1beta1storage.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
clientset.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
if err != nil {
glog.Errorf("failed to create the DiscoveryClient: %v", err)
return nil, err
}
return &clientset, nil
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:60,代码来源:clientset.go
示例9: New
// New creates a Kubernetes client for the given config. This client works with pods,
// replication controllers, daemons, and services. It allows operations such as list, get, update
// and delete on these objects. An error is returned if the provided configuration
// is not valid.
func New(c *restclient.Config) (*Client, error) {
config := *c
if err := SetKubernetesDefaults(&config); err != nil {
return nil, err
}
client, err := restclient.RESTClientFor(&config)
if err != nil {
return nil, err
}
discoveryConfig := *c
discoveryClient, err := discovery.NewDiscoveryClientForConfig(&discoveryConfig)
if err != nil {
return nil, err
}
var autoscalingClient *AutoscalingClient
if registered.IsRegistered(autoscaling.GroupName) {
autoscalingConfig := *c
autoscalingClient, err = NewAutoscaling(&autoscalingConfig)
if err != nil {
return nil, err
}
}
var batchClient *BatchClient
if registered.IsRegistered(batch.GroupName) {
batchConfig := *c
batchClient, err = NewBatch(&batchConfig)
if err != nil {
return nil, err
}
}
var extensionsClient *ExtensionsClient
if registered.IsRegistered(extensions.GroupName) {
extensionsConfig := *c
extensionsClient, err = NewExtensions(&extensionsConfig)
if err != nil {
return nil, err
}
}
var appsClient *AppsClient
if registered.IsRegistered(apps.GroupName) {
appsConfig := *c
appsClient, err = NewApps(&appsConfig)
if err != nil {
return nil, err
}
}
return &Client{RESTClient: client, AutoscalingClient: autoscalingClient, BatchClient: batchClient, ExtensionsClient: extensionsClient, DiscoveryClient: discoveryClient, AppsClient: appsClient}, nil
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:57,代码来源:helper.go
示例10: NewForConfig
// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *restclient.Config) (*Clientset, error) {
var clientset Clientset
var err error
clientset.TestgroupClient, err = unversionedtestgroup.NewForConfig(c)
if err != nil {
return &clientset, err
}
clientset.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(c)
if err != nil {
glog.Errorf("failed to create the DiscoveryClient: %v", err)
}
return &clientset, err
}
开发者ID:jwforres,项目名称:origin,代码行数:15,代码来源:clientset.go
示例11: NewForConfig
// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *restclient.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var clientset Clientset
var err error
clientset.TestgroupClient, err = unversionedtestgroup.NewForConfig(&configShallowCopy)
if err != nil {
return &clientset, err
}
clientset.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
if err != nil {
glog.Errorf("failed to create the DiscoveryClient: %v", err)
}
return &clientset, err
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:19,代码来源:clientset.go
示例12: NewForConfig
// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *restclient.Config) (*Clientset, error) {
var clientset Clientset
var err error
clientset.CoreClient, err = v1core.NewForConfig(c)
if err != nil {
return &clientset, err
}
clientset.ExtensionsClient, err = v1beta1extensions.NewForConfig(c)
if err != nil {
return &clientset, err
}
clientset.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(c)
if err != nil {
glog.Errorf("failed to create the DiscoveryClient: %v", err)
}
return &clientset, err
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:19,代码来源:clientset.go
示例13: NewForConfig
// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *restclient.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var cs Clientset
var err error
cs.ApiregistrationV1alpha1Client, err = v1alpha1apiregistration.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
if err != nil {
glog.Errorf("failed to create the DiscoveryClient: %v", err)
return nil, err
}
return &cs, nil
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:20,代码来源:clientset.go
示例14: Object
func (f *factory) Object() (meta.RESTMapper, runtime.ObjectTyper) {
cfg, err := f.clientConfig.ClientConfig()
checkErrWithPrefix("failed to get client config: ", err)
cmdApiVersion := unversioned.GroupVersion{}
if cfg.GroupVersion != nil {
cmdApiVersion = *cfg.GroupVersion
}
mapper := registered.RESTMapper()
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
if err == nil {
// register third party resources with the api machinery groups. This probably should be done, but
// its consistent with old code, so we'll start with it.
if err := registerThirdPartyResources(discoveryClient); err != nil {
fmt.Fprintf(os.Stderr, "Unable to register third party resources: %v\n", err)
}
// ThirdPartyResourceData is special. It's not discoverable, but needed for thirdparty resource listing
// TODO eliminate this once we're truly generic.
thirdPartyResourceDataMapper := meta.NewDefaultRESTMapper([]unversioned.GroupVersion{extensionsv1beta1.SchemeGroupVersion}, registered.InterfacesFor)
thirdPartyResourceDataMapper.Add(extensionsv1beta1.SchemeGroupVersion.WithKind("ThirdPartyResourceData"), meta.RESTScopeNamespace)
mapper = meta.FirstHitRESTMapper{
MultiRESTMapper: meta.MultiRESTMapper{
discovery.NewDeferredDiscoveryRESTMapper(discoveryClient, registered.InterfacesFor),
thirdPartyResourceDataMapper, // needed for TPR printing
registered.RESTMapper(), // hardcoded fall back
},
}
}
// wrap with shortcuts
mapper = NewShortcutExpander(mapper, discoveryClient)
// wrap with output preferences
mapper = kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []unversioned.GroupVersion{cmdApiVersion}}
return mapper, api.Scheme
}
开发者ID:Random-Liu,项目名称:kubernetes,代码行数:36,代码来源:factory.go
示例15: 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)
//.........这里部分代码省略.........
开发者ID:juanluisvaladas,项目名称:origin,代码行数:101,代码来源:factory.go
示例16: TestCheckAPIEndpoint
func TestCheckAPIEndpoint(t *testing.T) {
expect := version.Info{
Major: "foo",
Minor: "bar",
GitCommit: "baz",
}
tests := []struct {
s *httptest.Server
expect bool
}{
{
s: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {})),
expect: false,
},
{
s: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
var obj interface{}
switch req.URL.Path {
case "/api":
obj = &metav1.APIVersions{
Versions: []string{
"v1.4",
},
}
output, err := json.Marshal(obj)
if err != nil {
t.Fatalf("unexpected encoding error: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
default:
output, err := json.Marshal(expect)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
}
})),
expect: false,
},
{
s: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
var obj interface{}
switch req.URL.Path {
case "/api":
obj = &metav1.APIVersions{
Versions: []string{
"v1.4",
},
}
output, err := json.Marshal(obj)
if err != nil {
t.Fatalf("unexpected encoding error: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
case "/apis":
obj = &metav1.APIGroupList{
Groups: []metav1.APIGroup{
{
Name: "certificates.k8s.io",
Versions: []metav1.GroupVersionForDiscovery{
{GroupVersion: "extensions/v1beta1"},
},
},
},
}
output, err := json.Marshal(obj)
if err != nil {
t.Fatalf("unexpected encoding error: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
default:
output, err := json.Marshal(expect)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
}
})),
expect: true,
},
}
for _, rt := range tests {
defer rt.s.Close()
rc := &restclient.Config{Host: rt.s.URL}
c, err := discovery.NewDiscoveryClientForConfig(rc)
//.........这里部分代码省略.........
开发者ID:ConnorDoyle,项目名称:kubernetes,代码行数:101,代码来源:bootstrap_test.go
示例17: NewFactory
// NewFactory creates a factory with the default Kubernetes resources defined
// if optionalClientConfig is nil, then flags will be bound to a new clientcmd.ClientConfig.
// if optionalClientConfig is not nil, then this factory will make use of it.
func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
flags.SetNormalizeFunc(utilflag.WarnWordSepNormalizeFunc) // Warn for "_" flags
clientConfig := optionalClientConfig
if optionalClientConfig == nil {
clientConfig = DefaultClientConfig(flags)
}
clients := NewClientCache(clientConfig)
return &Factory{
clients: clients,
flags: flags,
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
cfg, err := clientConfig.ClientConfig()
checkErrWithPrefix("failed to get client config: ", err)
cmdApiVersion := unversioned.GroupVersion{}
if cfg.GroupVersion != nil {
cmdApiVersion = *cfg.GroupVersion
}
mapper := registered.RESTMapper()
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
// if we can find the server version and it's current enough to have discovery information, use it. Otherwise,
// fallback to our hardcoded list
if err == nil {
if serverVersion, err := discoveryClient.ServerVersion(); err == nil && useDiscoveryRESTMapper(serverVersion.GitVersion) {
// register third party resources with the api machinery groups. This probably should be done, but
// its consistent with old code, so we'll start with it.
if err := registerThirdPartyResources(discoveryClient); err != nil {
fmt.Fprintf(os.Stderr, "Unable to register third party resources: %v\n", err)
}
// ThirdPartyResourceData is special. It's not discoverable, but needed for thirdparty resource listing
// TODO eliminate this once we're truly generic.
thirdPartyResourceDataMapper := meta.NewDefaultRESTMapper([]unversioned.GroupVersion{extensionsv1beta1.SchemeGroupVersion}, registered.InterfacesFor)
thirdPartyResourceDataMapper.Add(extensionsv1beta1.SchemeGroupVersion.WithKind("ThirdPartyResourceData"), meta.RESTScopeNamespace)
mapper = meta.FirstHitRESTMapper{
MultiRESTMapper: meta.MultiRESTMapper{
discovery.NewDeferredDiscoveryRESTMapper(discoveryClient, registered.InterfacesFor),
thirdPartyResourceDataMapper,
},
}
}
}
// wrap with shortcuts
mapper = NewShortcutExpander(mapper, discoveryClient)
// wrap with output preferences
mapper = kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []unversioned.GroupVersion{cmdApiVersion}}
return mapper, api.Scheme
},
UnstructuredObject: func() (meta.RESTMapper, runtime.ObjectTyper, error) {
cfg, err := clients.ClientConfigForVersion(nil)
if err != nil {
return nil, nil, err
}
dc, err := discovery.NewDiscoveryClientForConfig(cfg)
if err != nil {
return nil, nil, err
}
groupResources, err := discovery.GetAPIGroupResources(dc)
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)
}
}
}
mapper := discovery.NewRESTMapper(groupResources, meta.InterfacesForUnstructured)
typer := discovery.NewUnstructuredObjectTyper(groupResources)
return NewShortcutExpander(mapper, dc), typer, nil
},
RESTClient: func() (*restclient.RESTClient, error) {
clientConfig, err := clients.ClientConfigForVersion(nil)
if err != nil {
return nil, err
}
return restclient.RESTClientFor(clientConfig)
},
ClientSet: func() (*internalclientset.Clientset, error) {
return clients.ClientSetForVersion(nil)
//.........这里部分代码省略.........
开发者ID:PeterLamar,项目名称:kubernetes,代码行数:101,代码来源:factory.go
示例18: New
// New creates a Kubernetes client for the given config. This client works with pods,
// replication controllers, daemons, and services. It allows operations such as list, get, update
// and delete on these objects. An error is returned if the provided configuration
// is not valid.
func New(c *restclient.Config) (*Client, error) {
config := *c
if err := SetKubernetesDefaults(&config); err != nil {
return nil, err
}
client, err := restclient.RESTClientFor(&config)
if err != nil {
return nil, err
}
discoveryConfig := *c
discoveryClient, err := discovery.NewDiscoveryClientForConfig(&discoveryConfig)
if err != nil {
return nil, err
}
var autoscalingClient *AutoscalingClient
if registered.IsRegistered(autoscaling.GroupName) {
autoscalingConfig := *c
autoscalingClient, err = NewAutoscaling(&autoscalingConfig)
if err != nil {
return nil, err
}
}
var batchClient *BatchClient
if registered.IsRegistered(batch.GroupName) {
batchConfig := *c
batchClient, err = NewBatch(&batchConfig)
if err != nil {
return nil, err
}
}
var extensionsClient *ExtensionsClient
if registered.IsRegistered(extensions.GroupName) {
extensionsConfig := *c
extensionsClient, err = NewExtensions(&extensionsConfig)
if err != nil {
return nil, err
}
}
var policyClient *PolicyClient
if registered.IsRegistered(policy.GroupName) {
policyConfig := *c
policyClient, err = NewPolicy(&policyConfig)
if err != nil {
return nil, err
}
}
var certsClient *CertificatesClient
if registered.IsRegistered(certificates.GroupName) {
certsConfig := *c
certsClient, err = NewCertificates(&certsConfig)
if err != nil {
return nil, err
}
}
var appsClient *AppsClient
if registered.IsRegistered(apps.GroupName) {
appsConfig := *c
appsClient, err = NewApps(&appsConfig)
if err != nil {
return nil, err
}
}
var rbacClient *RbacClient
if registered.IsRegistered(rbac.GroupName) {
rbacConfig := *c
rbacClient, err = NewRbac(&rbacConfig)
if err != nil {
return nil, err
}
}
return &Client{RESTClient: client, AutoscalingClient: autoscalingClient, BatchClient: batchClient, CertificatesClient: certsClient, ExtensionsClient: extensionsClient, DiscoveryClient: discoveryClient, AppsClient: appsClient, PolicyClient: policyClient, RbacClient: rbacClient}, nil
}
开发者ID:rlugojr,项目名称:kubernetes,代码行数:83,代码来源:helper.go
示例19: NewFactory
//.........这里部分代码省略.........
priorityMapper.Delegate = multiMapper
// Reassign to the RESTMapper here because priorityMapper is actually a copy, so if we
// don't reassign, the above assignement won't actually update mapper.RESTMapper
mapper.RESTMapper = priorityMapper
}
}
outputRESTMapper := kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []unversioned.GroupVersion{cmdApiVersion}}
priorityRESTMapper := meta.PriorityRESTMapper{
Delegate: outputRESTMapper,
}
// TODO: this should come from registered versions
groups := []string{api.GroupName, autoscaling.GroupName, extensions.GroupName, federation.GroupName, batch.GroupName}
// set a preferred version
for _, group := range groups {
gvs := registered.EnabledVersionsForGroup(group)
if len(gvs) == 0 {
continue
}
priorityRESTMapper.ResourcePriority = append(priorityRESTMapper.ResourcePriority, unversioned.GroupVersionResource{Group: group, Version: gvs[0].Version, Resource: meta.AnyResource})
priorityRESTMapper.KindPriority = append(priorityRESTMapper.KindPriority, unversioned.GroupVersionKind{Group: group, Version: gvs[0].Version, Kind: meta.AnyKind})
}
for _, group := range groups {
priorityRESTMapper.ResourcePriority = append(priorityRESTMapper.ResourcePriority, unversioned.GroupVersionResource{Group: group, Version: meta.AnyVersion, Resource: meta.AnyResource})
priorityRESTMapper.KindPriority = append(priorityRESTMapper.KindPriority, unversioned.GroupVersionKind{Group: group, Version: meta.AnyVersion, Kind: meta.AnyKind})
}
return priorityRESTMapper, api.Scheme
},
UnstructuredObject: func() (meta.RESTMapper, runtime.ObjectTyper, error) {
cfg, err := clients.ClientConfigForVersion(nil)
if err != nil {
return nil, nil, err
}
dc, err := discovery.NewDiscoveryClientForConfig(cfg)
if err != nil {
return nil, nil, err
}
groupResources, err := discovery.GetAPIGroupResources(dc)
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)
}
}
}
mapper := discovery.NewRESTMapper(groupResources, meta.InterfacesForUnstructured)
typer := discovery.NewUnstructuredObjectTyper(groupResources)
return kubectl.ShortcutExpander{RESTMapper: mapper}, typer, nil
},
RESTClient: func() (*restclient.RESTClient, error) {
clientConfig, err := clients.ClientConfigForVersion(nil)
if err != nil {
return nil, err
}
开发者ID:huang195,项目名称:kubernetes,代码行数:67,代码来源:factory.go
注:本文中的k8s/io/kubernetes/pkg/client/typed/discovery.NewDiscoveryClientForConfig函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论