mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Merge pull request #7760 from kargakis/move-generators-in-factory
Setup generators in factory
This commit is contained in:
commit
1e55bc6b95
@ -88,7 +88,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
|
||||
|
||||
generatorName := cmdutil.GetFlagString(cmd, "generator")
|
||||
|
||||
generator, found := kubectl.Generators[generatorName]
|
||||
generator, found := f.Generator(generatorName)
|
||||
if !found {
|
||||
return cmdutil.UsageError(cmd, fmt.Sprintf("generator %q not found.", generator))
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func RunRunContainer(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
|
||||
}
|
||||
|
||||
generatorName := cmdutil.GetFlagString(cmd, "generator")
|
||||
generator, found := kubectl.Generators[generatorName]
|
||||
generator, found := f.Generator(generatorName)
|
||||
if !found {
|
||||
return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not found.", generator))
|
||||
}
|
||||
|
@ -48,8 +48,9 @@ const (
|
||||
// TODO: pass the various interfaces on the factory directly into the command constructors (so the
|
||||
// commands are decoupled from the factory).
|
||||
type Factory struct {
|
||||
clients *clientCache
|
||||
flags *pflag.FlagSet
|
||||
clients *clientCache
|
||||
flags *pflag.FlagSet
|
||||
generators map[string]kubectl.Generator
|
||||
|
||||
// Returns interfaces for dealing with arbitrary runtime.Objects.
|
||||
Object func() (meta.RESTMapper, runtime.ObjectTyper)
|
||||
@ -77,6 +78,8 @@ type Factory struct {
|
||||
Validator func() (validation.Schema, error)
|
||||
// Returns the default namespace to use in cases where no other namespace is specified
|
||||
DefaultNamespace func() (string, error)
|
||||
// Returns the generator for the provided generator name
|
||||
Generator func(name string) (kubectl.Generator, bool)
|
||||
}
|
||||
|
||||
// NewFactory creates a factory with the default Kubernetes resources defined
|
||||
@ -88,6 +91,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
|
||||
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
|
||||
flags.SetNormalizeFunc(util.WordSepNormalizeFunc)
|
||||
|
||||
generators := map[string]kubectl.Generator{
|
||||
"run-container/v1": kubectl.BasicReplicationController{},
|
||||
"service/v1": kubectl.ServiceGenerator{},
|
||||
}
|
||||
|
||||
clientConfig := optionalClientConfig
|
||||
if optionalClientConfig == nil {
|
||||
clientConfig = DefaultClientConfig(flags)
|
||||
@ -99,8 +107,9 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
|
||||
}
|
||||
|
||||
return &Factory{
|
||||
clients: clients,
|
||||
flags: flags,
|
||||
clients: clients,
|
||||
flags: flags,
|
||||
generators: generators,
|
||||
|
||||
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
|
||||
cfg, err := clientConfig.ClientConfig()
|
||||
@ -221,6 +230,10 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
|
||||
DefaultNamespace: func() (string, error) {
|
||||
return clientConfig.Namespace()
|
||||
},
|
||||
Generator: func(name string) (kubectl.Generator, bool) {
|
||||
generator, ok := generators[name]
|
||||
return generator, ok
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,13 +39,6 @@ type Generator interface {
|
||||
ParamNames() []GeneratorParam
|
||||
}
|
||||
|
||||
// Generators is a global list of known generators.
|
||||
// TODO: Dynamically create this from a list of template files?
|
||||
var Generators map[string]Generator = map[string]Generator{
|
||||
"run-container/v1": BasicReplicationController{},
|
||||
"service/v1": ServiceGenerator{},
|
||||
}
|
||||
|
||||
// ValidateParams ensures that all required params are present in the params map
|
||||
func ValidateParams(paramSpec []GeneratorParam, params map[string]string) error {
|
||||
for ix := range paramSpec {
|
||||
|
Loading…
Reference in New Issue
Block a user