Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
1e55bc6b
Commit
1e55bc6b
authored
May 05, 2015
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7760 from kargakis/move-generators-in-factory
Setup generators in factory
parents
02bce106
c9e79a3c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
13 deletions
+19
-13
expose.go
pkg/kubectl/cmd/expose.go
+1
-1
run.go
pkg/kubectl/cmd/run.go
+1
-1
factory.go
pkg/kubectl/cmd/util/factory.go
+17
-4
generate.go
pkg/kubectl/generate.go
+0
-7
No files found.
pkg/kubectl/cmd/expose.go
View file @
1e55bc6b
...
...
@@ -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
))
}
...
...
pkg/kubectl/cmd/run.go
View file @
1e55bc6b
...
...
@@ -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
))
}
...
...
pkg/kubectl/cmd/util/factory.go
View file @
1e55bc6b
...
...
@@ -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
},
}
}
...
...
pkg/kubectl/generate.go
View file @
1e55bc6b
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment