make --include-extended-apis deprecated and remove plumbing

pull/6/head
deads2k 2016-09-16 15:50:34 -04:00
parent 9bc7e36f4b
commit 862415aaa2
31 changed files with 49 additions and 56 deletions

View File

@ -164,7 +164,7 @@ func (o *AnnotateOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra
o.recordChangeCause = cmdutil.GetRecordFlag(cmd)
o.changeCause = f.Command()
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
o.builder = resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(namespace).DefaultNamespace().
@ -252,7 +252,7 @@ func (o AnnotateOptions) RunAnnotate() error {
return err
}
mapper, _ := o.f.Object(cmdutil.GetIncludeThirdPartyAPIs(o.cmd))
mapper, _ := o.f.Object()
outputFormat := cmdutil.GetFlagString(o.cmd, "output")
if outputFormat != "" {
return o.f.PrintObject(o.cmd, mapper, outputObj, o.out)

View File

@ -114,7 +114,7 @@ func RunApply(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *Ap
return err
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
Schema(schema).
ContinueOnError().

View File

@ -98,7 +98,7 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
return err
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(namespace).DefaultNamespace().

View File

@ -61,7 +61,7 @@ func RunClusterInfo(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command) error
}
printService(out, "Kubernetes master", client.Host)
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
cmdNamespace := cmdutil.GetFlagString(cmd, "namespace")
if cmdNamespace == "" {
cmdNamespace = api.NamespaceSystem

View File

@ -220,7 +220,7 @@ func NewTestFactory() (*cmdutil.Factory, *testFactory, runtime.Codec, runtime.Ne
runtime.SerializerInfo{Serializer: codec},
runtime.StreamSerializerInfo{})
return &cmdutil.Factory{
Object: func(discovery bool) (meta.RESTMapper, runtime.ObjectTyper) {
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
priorityRESTMapper := meta.PriorityRESTMapper{
Delegate: t.Mapper,
ResourcePriority: []unversioned.GroupVersionResource{
@ -264,7 +264,7 @@ func NewMixedFactory(apiClient resource.RESTClient) (*cmdutil.Factory, *testFact
var multiRESTMapper meta.MultiRESTMapper
multiRESTMapper = append(multiRESTMapper, t.Mapper)
multiRESTMapper = append(multiRESTMapper, testapi.Default.RESTMapper())
f.Object = func(discovery bool) (meta.RESTMapper, runtime.ObjectTyper) {
f.Object = func() (meta.RESTMapper, runtime.ObjectTyper) {
priorityRESTMapper := meta.PriorityRESTMapper{
Delegate: multiRESTMapper,
ResourcePriority: []unversioned.GroupVersionResource{
@ -291,7 +291,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec, runtime.Neg
}
f := &cmdutil.Factory{
Object: func(discovery bool) (meta.RESTMapper, runtime.ObjectTyper) {
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
return testapi.Default.RESTMapper(), api.Scheme
},
UnstructuredObject: func() (meta.RESTMapper, runtime.ObjectTyper, error) {
@ -450,7 +450,7 @@ func Example_printReplicationControllerWithNamespace() {
ReadyReplicas: 1,
},
}
mapper, _ := f.Object(false)
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, ctrl, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
@ -502,7 +502,7 @@ func Example_printMultiContainersReplicationControllerWithWide() {
Replicas: 1,
},
}
mapper, _ := f.Object(false)
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, ctrl, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
@ -553,7 +553,7 @@ func Example_printReplicationController() {
Replicas: 1,
},
}
mapper, _ := f.Object(false)
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, ctrl, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
@ -593,7 +593,7 @@ func Example_printPodWithWideFormat() {
PodIP: "10.1.1.3",
},
}
mapper, _ := f.Object(false)
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, pod, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
@ -636,7 +636,7 @@ func Example_printPodWithShowLabels() {
},
},
}
mapper, _ := f.Object(false)
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, pod, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
@ -749,7 +749,7 @@ func Example_printPodHideTerminated() {
}
cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr)
podList := newAllPhasePodList()
mapper, _ := f.Object(false)
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, podList, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
@ -773,7 +773,7 @@ func Example_printPodShowAll() {
}
cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr)
podList := newAllPhasePodList()
mapper, _ := f.Object(false)
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, podList, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
@ -846,7 +846,7 @@ func Example_printServiceWithNamespacesAndLabels() {
ld := strings.NewLineDelimiter(os.Stdout, "|")
defer ld.Flush()
mapper, _ := f.Object(false)
mapper, _ := f.Object()
err := f.PrintObject(cmd, mapper, svc, ld)
if err != nil {
fmt.Printf("Unexpected error: %v", err)

View File

@ -115,7 +115,7 @@ func (o *ConvertOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra.
}
// build the builder
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
clientMapper := resource.ClientMapperFunc(f.ClientForMapping)
if o.local {

View File

@ -200,7 +200,7 @@ func RunCreateSubcommand(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer,
if err != nil {
return err
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
gvks, _, err := typer.ObjectKinds(obj)
if err != nil {
return err

View File

@ -122,7 +122,7 @@ func RunDelete(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
return err
}
deleteAll := cmdutil.GetFlagBool(cmd, "all")
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().

View File

@ -118,7 +118,7 @@ func RunDescribe(f *cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command,
return cmdutil.UsageError(cmd, "Required resource not specified.")
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(allNamespaces).

View File

@ -188,14 +188,14 @@ func (o *DrainOptions) SetupDrain(cmd *cobra.Command, args []string) error {
return err
}
o.mapper, o.typer = o.factory.Object(false)
o.mapper, o.typer = o.factory.Object()
cmdNamespace, _, err := o.factory.DefaultNamespace()
if err != nil {
return err
}
r := o.factory.NewBuilder(cmdutil.GetIncludeThirdPartyAPIs(cmd)).
r := o.factory.NewBuilder().
NamespaceParam(cmdNamespace).DefaultNamespace().
ResourceNames("node", args[0]).
Do()

View File

@ -151,7 +151,7 @@ func RunEdit(f *cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args
return err
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
resourceMapper := &resource.Mapper{
ObjectTyper: typer,
RESTMapper: mapper,

View File

@ -74,7 +74,7 @@ func RunExplain(f *cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, a
apiVersionString := cmdutil.GetFlagString(cmd, "api-version")
apiVersion := unversioned.GroupVersion{}
mapper, _ := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, _ := f.Object()
// TODO: After we figured out the new syntax to separate group and resource, allow
// the users to use it in explain (kubectl explain <group><syntax><resource>).
// Refer to issue #16039 for why we do this. Refer to PR #15808 that used "/" syntax.

View File

@ -137,7 +137,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
return err
}
mapper, typer := f.Object(false)
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(namespace).DefaultNamespace().

View File

@ -156,7 +156,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, errOut io.Writer, cmd *cobra.Comm
selector := cmdutil.GetFlagString(cmd, "selector")
allNamespaces := cmdutil.GetFlagBool(cmd, "all-namespaces")
showKind := cmdutil.GetFlagBool(cmd, "show-kind")
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
printAll := false
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()

View File

@ -206,7 +206,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
if err != nil {
return cmdutil.UsageError(cmd, err.Error())
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
b := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().

View File

@ -162,7 +162,7 @@ func (o *LogsOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra.Com
o.ClientMapper = resource.ClientMapperFunc(f.ClientForMapping)
o.Out = out
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
decoder := f.Decoder(true)
if o.Object == nil {
infos, err := resource.NewBuilder(mapper, typer, o.ClientMapper, decoder).

View File

@ -142,7 +142,7 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
return fmt.Errorf("unable to parse %q: %v", patch, err)
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().

View File

@ -130,7 +130,7 @@ func RunReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
return fmt.Errorf("--timeout must have --force specified")
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
Schema(schema).
ContinueOnError().

View File

@ -202,7 +202,7 @@ func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, arg
var keepOldName bool
var replicasDefaulted bool
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
if len(filename) != 0 {
schema, err := f.Validator(cmdutil.GetFlagBool(cmd, "validate"), cmdutil.GetFlagString(cmd, "schema-cache-dir"))

View File

@ -77,7 +77,7 @@ func RunHistory(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []st
}
revision := cmdutil.GetFlagInt64(cmd, "revision")
mapper, typer := f.Object(false)
mapper, typer := f.Object()
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil {

View File

@ -96,7 +96,7 @@ func (o *PauseConfig) CompletePause(f *cmdutil.Factory, cmd *cobra.Command, out
return cmdutil.UsageError(cmd, cmd.Use)
}
o.Mapper, o.Typer = f.Object(false)
o.Mapper, o.Typer = f.Object()
o.PauseObject = f.PauseObject
o.Out = out

View File

@ -94,7 +94,7 @@ func (o *ResumeConfig) CompleteResume(f *cmdutil.Factory, cmd *cobra.Command, ou
return cmdutil.UsageError(cmd, cmd.Use)
}
o.Mapper, o.Typer = f.Object(false)
o.Mapper, o.Typer = f.Object()
o.ResumeObject = f.ResumeObject
o.Out = out

View File

@ -73,7 +73,7 @@ func RunStatus(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []str
return cmdutil.UsageError(cmd, "Required resource not specified.")
}
mapper, typer := f.Object(false)
mapper, typer := f.Object()
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil {

View File

@ -100,7 +100,7 @@ func (o *UndoOptions) CompleteUndo(f *cmdutil.Factory, cmd *cobra.Command, out i
}
o.ToRevision = cmdutil.GetFlagInt64(cmd, "to-revision")
o.Mapper, o.Typer = f.Object(false)
o.Mapper, o.Typer = f.Object()
o.Out = out
o.DryRun = cmdutil.GetFlagBool(cmd, "dry-run")

View File

@ -305,7 +305,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
if err != nil {
return err
}
_, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
_, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(namespace).DefaultNamespace().
@ -592,7 +592,7 @@ func createGeneratedObject(f *cmdutil.Factory, cmd *cobra.Command, generator kub
return nil, "", nil, nil, err
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
groupVersionKinds, _, err := typer.ObjectKinds(obj)
if err != nil {
return nil, "", nil, nil, err

View File

@ -111,7 +111,7 @@ func RunScale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
return err
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().

View File

@ -108,7 +108,7 @@ func NewCmdImage(f *cmdutil.Factory, out io.Writer) *cobra.Command {
}
func (o *ImageOptions) Complete(f *cmdutil.Factory, cmd *cobra.Command, args []string) error {
o.Mapper, o.Typer = f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
o.Mapper, o.Typer = f.Object()
o.UpdatePodSpecForObject = f.UpdatePodSpecForObject
o.Encoder = f.JSONEncoder()
o.ShortOutput = cmdutil.GetFlagString(cmd, "output") == "name"

View File

@ -90,7 +90,7 @@ func RunStop(f *cmdutil.Factory, cmd *cobra.Command, args []string, out io.Write
return err
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().

View File

@ -256,7 +256,7 @@ func (o *TaintOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra.Co
return cmdutil.UsageError(cmd, err.Error())
}
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
mapper, typer := f.Object()
o.builder = resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
ContinueOnError().
NamespaceParam(namespace).DefaultNamespace()
@ -365,7 +365,7 @@ func (o TaintOptions) RunTaint() error {
return err
}
mapper, _ := o.f.Object(cmdutil.GetIncludeThirdPartyAPIs(o.cmd))
mapper, _ := o.f.Object()
outputFormat := cmdutil.GetFlagString(o.cmd, "output")
if outputFormat != "" {
return o.f.PrintObject(o.cmd, mapper, outputObj, o.out)

View File

@ -82,9 +82,8 @@ type Factory struct {
clients *ClientCache
flags *pflag.FlagSet
// Returns interfaces for dealing with arbitrary runtime.Objects. If thirdPartyDiscovery is true, performs API calls
// to discovery dynamic API objects registered by third parties.
Object func(thirdPartyDiscovery bool) (meta.RESTMapper, runtime.ObjectTyper)
// Returns interfaces for dealing with arbitrary runtime.Objects.
Object func() (meta.RESTMapper, runtime.ObjectTyper)
// Returns interfaces for dealing with arbitrary
// runtime.Unstructured. This performs API calls to discover types.
UnstructuredObject func() (meta.RESTMapper, runtime.ObjectTyper, error)
@ -293,7 +292,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
clients: clients,
flags: flags,
Object: func(discoverDynamicAPIs bool) (meta.RESTMapper, runtime.ObjectTyper) {
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
cfg, err := clientConfig.ClientConfig()
checkErrWithPrefix("failed to get client config: ", err)
cmdApiVersion := unversioned.GroupVersion{}
@ -1251,8 +1250,8 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
}
// One stop shopping for a Builder
func (f *Factory) NewBuilder(thirdPartyDiscovery bool) *resource.Builder {
mapper, typer := f.Object(thirdPartyDiscovery)
func (f *Factory) NewBuilder() *resource.Builder {
mapper, typer := f.Object()
return resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true))
}

View File

@ -554,15 +554,9 @@ func GetThirdPartyGroupVersions(discovery discovery.DiscoveryInterface) ([]unver
return result, gvks, nil
}
func GetIncludeThirdPartyAPIs(cmd *cobra.Command) bool {
if cmd.Flags().Lookup("include-extended-apis") == nil {
return false
}
return GetFlagBool(cmd, "include-extended-apis")
}
func AddInclude3rdPartyFlags(cmd *cobra.Command) {
cmd.Flags().Bool("include-extended-apis", true, "If true, include definitions of new APIs via calls to the API server. [default true]")
cmd.Flags().MarkDeprecated("include-extended-apis", "No longer required.")
}
// GetResourcesAndPairs retrieves resources and "KEY=VALUE or KEY-" pair args from given args