add user-specified ns to --dry-run created obj

pull/6/head
juanvallejo 2017-10-09 15:44:02 -04:00
parent c7f970c560
commit 1d54dc4136
No known key found for this signature in database
GPG Key ID: 7D2C958002D6448D
1 changed files with 7 additions and 1 deletions

View File

@ -23,7 +23,9 @@ import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
@ -242,7 +244,7 @@ type CreateSubcommandOptions struct {
// RunCreateSubcommand executes a create subcommand using the specified options
func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *CreateSubcommandOptions) error {
namespace, _, err := f.DefaultNamespace()
namespace, nsOverriden, err := f.DefaultNamespace()
if err != nil {
return err
}
@ -283,6 +285,10 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
if err != nil {
return err
}
} else {
if meta, err := meta.Accessor(obj); err == nil && nsOverriden {
meta.SetNamespace(namespace)
}
}
if useShortOutput := options.OutputFormat == "name"; useShortOutput || len(options.OutputFormat) == 0 {