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,8 +18,10 @@ package kubectl
import (
"fmt"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/golang/glog"
"github.com/spf13/cobra"
)
@@ -42,6 +44,7 @@ type Generator interface {
// 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
@@ -68,3 +71,29 @@ func MakeParams(cmd *cobra.Command, params []GeneratorParam) map[string]string {
}
return result
}
func MakeLabels(labels map[string]string) string {
out := []string{}
for key, value := range labels {
out = append(out, fmt.Sprintf("%s=%s", key, value))
}
return strings.Join(out, ",")
}
// ParseLabels turns a string representation of a label set into a map[string]string
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
}