returnnil,fmt.Errorf("no description has been implemented for %q",mapping.Kind)
}
returndescriber,nil
}
// BindFlags adds any flags that are common to all kubectl sub commands.
func(f*Factory)BindFlags(flags*pflag.FlagSet){
// any flags defined by external projects (not part of pflags)
util.AddAllFlagsToPFlagSet(flags)
iff.flags!=nil{
f.flags.VisitAll(func(flag*pflag.Flag){
flags.AddFlag(flag)
})
}
returnret
// Globally persistent flags across all subcommands.
// TODO Change flag names to consts to allow safer lookup from subcommands.
// TODO Add a verbose flag that turns on glog logging. Probably need a way
// to do that automatically for every subcommand.
flags.BoolVar(&f.clients.matchVersion,FlagMatchBinaryVersion,false,"Require server version to match client version")
flags.String("ns-path",os.Getenv("HOME")+"/.kubernetes_ns","Path to the namespace info file that holds the namespace context to use for CLI requests.")
flags.StringP("namespace","n","","If present, the namespace scope for this CLI request.")
flags.Bool("validate",false,"If true, use a schema to validate the input before sending it")
}
func(f*Factory)Run(outio.Writer){
// NewKubectlCommand creates the `kubectl` command and its nested children.
// Globally persistent flags across all subcommands.
// TODO Change flag names to consts to allow safer lookup from subcommands.
cmds.PersistentFlags().Bool(FlagMatchBinaryVersion,false,"Require server version to match client version")
cmds.PersistentFlags().String("ns-path",os.Getenv("HOME")+"/.kubernetes_ns","Path to the namespace info file that holds the namespace context to use for CLI requests.")
cmds.PersistentFlags().StringP("namespace","n","","If present, the namespace scope for this CLI request.")
cmds.PersistentFlags().Bool("validate",false,"If true, use a schema to validate the input before sending it")
f.BindFlags(cmds.PersistentFlags())
cmds.AddCommand(f.NewCmdVersion(out))
cmds.AddCommand(f.NewCmdProxy(out))
...
...
@@ -125,12 +171,10 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`,
cmds.AddCommand(f.NewCmdLog(out))
cmds.AddCommand(f.NewCmdRollingUpdate(out))
iferr:=cmds.Execute();err!=nil{
os.Exit(1)
}
returncmds
}
// getClientBuilder creates a clientcmd.ClientConfig that has a hierarchy like this:
// DefaultClientConfig creates a clientcmd.ClientConfig with the following hierarchy:
// 1. Use the kubeconfig builder. The number of merges and overrides here gets a little crazy. Stay with me.
// 1. Merge together the kubeconfig itself. This is done with the following hierarchy and merge rules:
// 1. CommandLineLocation - this parsed from the command line, so it must be late bound
...
...
@@ -162,13 +206,13 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`,
// 2. If the command line does not specify one, and the auth info has conflicting techniques, fail.
// 3. If the command line specifies one and the auth info specifies another, honor the command line technique.
// 2. Use default values and potentially prompt for auth information
// SetNamespace ensures that every Info object visited will have a namespace
// set. If info.Object is set, it will be mutated as well.
funcSetNamespace(namespacestring)VisitorFunc{
returnfunc(info*Info)error{
iflen(info.Namespace)==0{
info.Namespace=namespace
UpdateObjectNamespace(info)
}
returnnil
}
}
// RequireNamespace will either set a namespace if none is provided on the
// Info object, or if the namespace is set and does not match the provided
// value, returns an error. This is intended to guard against administrators
// accidentally operating on resources outside their namespace.
funcRequireNamespace(namespacestring)VisitorFunc{
returnfunc(info*Info)error{
iflen(info.Namespace)==0{
info.Namespace=namespace
UpdateObjectNamespace(info)
returnnil
}
ifinfo.Namespace!=namespace{
returnfmt.Errorf("the namespace from the provided object %q does not match the namespace %q. You must pass '--namespace=%s' to perform this operation.",info.Namespace,namespace,info.Namespace)
}
returnnil
}
}
// RetrieveLatest updates the Object on each Info by invoking a standard client