Add a service generator and a command to easily expose services.

This commit is contained in:
Brendan Burns
2015-01-16 17:52:27 -08:00
parent c65f83f424
commit 09166f5252
8 changed files with 291 additions and 28 deletions

View File

@@ -18,11 +18,9 @@ package kubectl
import (
"strconv"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/golang/glog"
)
type BasicReplicationController struct{}
@@ -33,6 +31,7 @@ func (BasicReplicationController) ParamNames() []GeneratorParam {
{"name", true},
{"replicas", true},
{"image", true},
{"port", false},
}
}
@@ -74,23 +73,13 @@ func (BasicReplicationController) Generate(params map[string]string) (runtime.Ob
},
},
}
port, err := strconv.Atoi(params["port"])
if err != nil {
controller.Spec.Template.Spec.Containers[0].Ports = []api.Port{
{
ContainerPort: port,
},
}
}
return &controller, nil
}
// TODO: extract this to a common location.
func ParseLabels(labelString string) map[string]string {
if len(labelString) == 0 {
return nil
}
labels := map[string]string{}
labelSpecs := strings.Split(labelString, ",")
for ix := range labelSpecs {
labelSpec := strings.Split(labelSpecs[ix], "=")
if len(labelSpec) != 2 {
glog.Errorf("unexpected label spec: %s", labelSpecs[ix])
continue
}
labels[labelSpec[0]] = labelSpec[1]
}
return labels
}