divide statically known typer from dynamically derive restmapper

This commit is contained in:
David Eads
2018-04-27 09:27:19 -04:00
parent 6fbcbc994f
commit 5432ef5c45
27 changed files with 47 additions and 75 deletions

View File

@@ -389,9 +389,10 @@ func RunCreateSubcommand(f cmdutil.Factory, options *CreateSubcommandOptions) er
if err != nil {
return err
}
mapper, typer := f.Object()
mapper := f.RESTMapper()
if !options.DryRun {
gvks, _, err := typer.ObjectKinds(obj)
// create subcommands have compiled knowledge of things they create, so type them directly
gvks, _, err := legacyscheme.Scheme.ObjectKinds(obj)
if err != nil {
return err
}

View File

@@ -437,7 +437,7 @@ func TestClusterRoleValidate(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
test.clusterRoleOptions.Mapper, _ = tf.Object()
test.clusterRoleOptions.Mapper = tf.RESTMapper()
err := test.clusterRoleOptions.Validate()
if test.expectErr && err == nil {
t.Errorf("%s: expect error happens, but validate passes.", name)

View File

@@ -205,7 +205,7 @@ func (o *CreateRoleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
o.ResourceNames = resourceNames
// Complete other options for Run.
o.Mapper, _ = f.Object()
o.Mapper = f.RESTMapper()
o.DryRun = cmdutil.GetDryRunFlag(cmd)
o.OutputFormat = cmdutil.GetFlagString(cmd, "output")

View File

@@ -339,7 +339,7 @@ func TestValidate(t *testing.T) {
}
for name, test := range tests {
test.roleOptions.Mapper, _ = tf.Object()
test.roleOptions.Mapper = tf.RESTMapper()
err := test.roleOptions.Validate()
if test.expectErr && err == nil {
t.Errorf("%s: expect error happens but validate passes.", name)