expose: Use separate parameters for default and custom name

This commit is contained in:
kargakis
2015-05-26 14:03:11 +02:00
parent 6fa2777e26
commit 6c85040cef
4 changed files with 77 additions and 22 deletions

View File

@@ -29,7 +29,8 @@ type BasicReplicationController struct{}
func (BasicReplicationController) ParamNames() []GeneratorParam {
return []GeneratorParam{
{"labels", false},
{"name", true},
{"default-name", true},
{"name", false},
{"replicas", true},
{"image", true},
{"port", false},
@@ -38,6 +39,13 @@ func (BasicReplicationController) ParamNames() []GeneratorParam {
}
func (BasicReplicationController) Generate(params map[string]string) (runtime.Object, error) {
name, found := params["name"]
if !found || len(name) == 0 {
name, found = params["default-name"]
if !found || len(name) == 0 {
return nil, fmt.Errorf("'name' is a required parameter.")
}
}
// TODO: extract this flag to a central location.
labelString, found := params["labels"]
var labels map[string]string
@@ -49,7 +57,7 @@ func (BasicReplicationController) Generate(params map[string]string) (runtime.Ob
}
} else {
labels = map[string]string{
"run": params["name"],
"run": name,
}
}
count, err := strconv.Atoi(params["replicas"])
@@ -58,7 +66,7 @@ func (BasicReplicationController) Generate(params map[string]string) (runtime.Ob
}
controller := api.ReplicationController{
ObjectMeta: api.ObjectMeta{
Name: params["name"],
Name: name,
Labels: labels,
},
Spec: api.ReplicationControllerSpec{
@@ -71,7 +79,7 @@ func (BasicReplicationController) Generate(params map[string]string) (runtime.Ob
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: params["name"],
Name: name,
Image: params["image"],
},
},