本文整理汇总了Golang中k8s/io/kubernetes/pkg/kubectl/cmd/util.DefaultGenerators函数的典型用法代码示例。如果您正苦于以下问题:Golang DefaultGenerators函数的具体用法?Golang DefaultGenerators怎么用?Golang DefaultGenerators使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultGenerators函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewAPIFactory
func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec, runtime.NegotiatedSerializer) {
t := &testFactory{
Validator: validation.NullSchema{},
}
f := &cmdutil.Factory{
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
return testapi.Default.RESTMapper(), api.Scheme
},
UnstructuredObject: func() (meta.RESTMapper, runtime.ObjectTyper, error) {
groupResources := testDynamicResources()
mapper := discovery.NewRESTMapper(groupResources, meta.InterfacesForUnstructured)
typer := discovery.NewUnstructuredObjectTyper(groupResources)
return cmdutil.NewShortcutExpander(mapper, nil), typer, nil
},
ClientSet: func() (*internalclientset.Clientset, error) {
// Swap out the HTTP client out of the client with the fake's version.
fakeClient := t.Client.(*fake.RESTClient)
restClient, err := restclient.RESTClientFor(t.ClientConfig)
if err != nil {
panic(err)
}
restClient.Client = fakeClient.Client
return internalclientset.New(restClient), t.Err
},
RESTClient: func() (*restclient.RESTClient, error) {
// Swap out the HTTP client out of the client with the fake's version.
fakeClient := t.Client.(*fake.RESTClient)
restClient, err := restclient.RESTClientFor(t.ClientConfig)
if err != nil {
panic(err)
}
restClient.Client = fakeClient.Client
return restClient, t.Err
},
ClientForMapping: func(*meta.RESTMapping) (resource.RESTClient, error) {
return t.Client, t.Err
},
UnstructuredClientForMapping: func(*meta.RESTMapping) (resource.RESTClient, error) {
return t.Client, t.Err
},
Decoder: func(bool) runtime.Decoder {
return testapi.Default.Codec()
},
JSONEncoder: func() runtime.Encoder {
return testapi.Default.Codec()
},
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
return t.Describer, t.Err
},
Printer: func(mapping *meta.RESTMapping, options kubectl.PrintOptions) (kubectl.ResourcePrinter, error) {
return t.Printer, t.Err
},
Validator: func(validate bool, cacheDir string) (validation.Schema, error) {
return t.Validator, t.Err
},
DefaultNamespace: func() (string, bool, error) {
return t.Namespace, false, t.Err
},
ClientConfig: func() (*restclient.Config, error) {
return t.ClientConfig, t.Err
},
Generators: func(cmdName string) map[string]kubectl.Generator {
return cmdutil.DefaultGenerators(cmdName)
},
LogsForObject: func(object, options runtime.Object) (*restclient.Request, error) {
fakeClient := t.Client.(*fake.RESTClient)
c := client.NewOrDie(t.ClientConfig)
c.Client = fakeClient.Client
switch t := object.(type) {
case *api.Pod:
opts, ok := options.(*api.PodLogOptions)
if !ok {
return nil, errors.New("provided options object is not a PodLogOptions")
}
return c.Pods(t.Namespace).GetLogs(t.Name, opts), nil
default:
fqKinds, _, err := api.Scheme.ObjectKinds(object)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("cannot get the logs from %v", fqKinds[0])
}
},
}
rf := cmdutil.NewFactory(nil)
f.MapBasedSelectorForObject = rf.MapBasedSelectorForObject
f.PortsForObject = rf.PortsForObject
f.ProtocolsForObject = rf.ProtocolsForObject
f.LabelsForObject = rf.LabelsForObject
f.CanBeExposed = rf.CanBeExposed
f.PrintObjectSpecificMessage = rf.PrintObjectSpecificMessage
return f, t, testapi.Default.Codec(), testapi.Default.NegotiatedSerializer()
}
示例2: NewAPIFactory
func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
t := &testFactory{
Validator: validation.NullSchema{},
}
f := &cmdutil.Factory{
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
return testapi.Default.RESTMapper(), api.Scheme
},
Client: func() (*client.Client, error) {
// Swap out the HTTP client out of the client with the fake's version.
fakeClient := t.Client.(*fake.RESTClient)
c := client.NewOrDie(t.ClientConfig)
c.Client = fakeClient.Client
c.ExtensionsClient.Client = fakeClient.Client
return c, t.Err
},
ClientForMapping: func(*meta.RESTMapping) (resource.RESTClient, error) {
return t.Client, t.Err
},
Decoder: func(bool) runtime.Decoder {
return testapi.Default.Codec()
},
JSONEncoder: func() runtime.Encoder {
return testapi.Default.Codec()
},
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
return t.Describer, t.Err
},
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, showLabels bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
return t.Printer, t.Err
},
Validator: func(validate bool, cacheDir string) (validation.Schema, error) {
return t.Validator, t.Err
},
DefaultNamespace: func() (string, bool, error) {
return t.Namespace, false, t.Err
},
ClientConfig: func() (*restclient.Config, error) {
return t.ClientConfig, t.Err
},
Generators: func(cmdName string) map[string]kubectl.Generator {
return cmdutil.DefaultGenerators(cmdName)
},
LogsForObject: func(object, options runtime.Object) (*restclient.Request, error) {
fakeClient := t.Client.(*fake.RESTClient)
c := client.NewOrDie(t.ClientConfig)
c.Client = fakeClient.Client
switch t := object.(type) {
case *api.Pod:
opts, ok := options.(*api.PodLogOptions)
if !ok {
return nil, errors.New("provided options object is not a PodLogOptions")
}
return c.Pods(t.Namespace).GetLogs(t.Name, opts), nil
default:
fqKind, err := api.Scheme.ObjectKind(object)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("cannot get the logs from %v", fqKind)
}
},
}
rf := cmdutil.NewFactory(nil)
f.PodSelectorForObject = rf.PodSelectorForObject
f.MapBasedSelectorForObject = rf.MapBasedSelectorForObject
f.PortsForObject = rf.PortsForObject
f.LabelsForObject = rf.LabelsForObject
f.CanBeExposed = rf.CanBeExposed
return f, t, testapi.Default.Codec()
}
示例3: Generators
func (f *fakeAPIFactory) Generators(cmdName string) map[string]kubectl.Generator {
return cmdutil.DefaultGenerators(cmdName)
}