Merge pull request #628 from jdef/master

named container ports should have sane env var names
This commit is contained in:
Daniel Smith 2014-07-28 23:05:48 -07:00
commit f87bd6b8f9
2 changed files with 16 additions and 1 deletions

View File

@ -50,7 +50,7 @@ func makeLinkVariables(service api.Service, machine string) []api.EnvVar {
} else {
port = strconv.Itoa(service.ContainerPort.IntVal)
}
portPrefix := prefix + "_PORT_" + port + "_TCP"
portPrefix := prefix + "_PORT_" + strings.ToUpper(strings.Replace(port,"-","_",-1)) + "_TCP"
return []api.EnvVar{
{
Name: prefix + "_PORT",

View File

@ -23,6 +23,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
func TestServiceRegistry(t *testing.T) {
@ -216,3 +217,17 @@ func TestServiceRegistryDeleteExternal(t *testing.T) {
}
}
}
func TestServiceRegistryMakeLinkVariables(t *testing.T) {
service := api.Service {
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
ContainerPort: util.IntOrString { Kind: util.IntstrString, StrVal: "a-b-c" },
}
vars := makeLinkVariables(service, "mars")
for _, v := range vars {
if !util.IsCIdentifier(v.Name) {
t.Errorf("Environment variable name is not valid: %v", v.Name)
}
}
}