mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 02:38:12 +00:00
bind filenames var instead of looking up
This commit is contained in:
@@ -30,6 +30,12 @@ import (
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// CreateOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
|
||||
// referencing the cmd.Flags()
|
||||
type CreateOptions struct {
|
||||
Filenames []string
|
||||
}
|
||||
|
||||
const (
|
||||
create_long = `Create a resource by filename or stdin.
|
||||
|
||||
@@ -42,6 +48,8 @@ $ cat pod.json | kubectl create -f -`
|
||||
)
|
||||
|
||||
func NewCmdCreate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
options := &CreateOptions{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "create -f FILENAME",
|
||||
Short: "Create a resource by filename or stdin",
|
||||
@@ -50,12 +58,12 @@ func NewCmdCreate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(ValidateArgs(cmd, args))
|
||||
cmdutil.CheckErr(cmdutil.ValidateOutputArgs(cmd))
|
||||
cmdutil.CheckErr(RunCreate(f, cmd, out))
|
||||
cmdutil.CheckErr(RunCreate(f, cmd, out, options))
|
||||
},
|
||||
}
|
||||
|
||||
usage := "Filename, directory, or URL to file to use to create the resource"
|
||||
kubectl.AddJsonFilenameFlag(cmd, usage)
|
||||
kubectl.AddJsonFilenameFlag(cmd, &options.Filenames, usage)
|
||||
cmd.MarkFlagRequired("filename")
|
||||
cmdutil.AddValidateFlag(cmd)
|
||||
cmdutil.AddOutputFlagsForMutation(cmd)
|
||||
@@ -69,7 +77,7 @@ func ValidateArgs(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RunCreate(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer) error {
|
||||
func RunCreate(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *CreateOptions) error {
|
||||
schema, err := f.Validator(cmdutil.GetFlagBool(cmd, "validate"))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -80,13 +88,12 @@ func RunCreate(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
filenames := cmdutil.GetFlagStringSlice(cmd, "filename")
|
||||
mapper, typer := f.Object()
|
||||
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
|
||||
Schema(schema).
|
||||
ContinueOnError().
|
||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||
FilenameParam(enforceNamespace, filenames...).
|
||||
FilenameParam(enforceNamespace, options.Filenames...).
|
||||
Flatten().
|
||||
Do()
|
||||
err = r.Err()
|
||||
|
||||
Reference in New Issue
Block a user