diff --git a/pkg/registry/service_registry.go b/pkg/registry/service_registry.go index 316a60fc9d7..b859c50899f 100644 --- a/pkg/registry/service_registry.go +++ b/pkg/registry/service_registry.go @@ -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", diff --git a/pkg/registry/service_registry_test.go b/pkg/registry/service_registry_test.go index ae117bdf777..02d5f67d7f3 100644 --- a/pkg/registry/service_registry_test.go +++ b/pkg/registry/service_registry_test.go @@ -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) + } + } +}