mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #628 from jdef/master
named container ports should have sane env var names
This commit is contained in:
commit
f87bd6b8f9
@ -50,7 +50,7 @@ func makeLinkVariables(service api.Service, machine string) []api.EnvVar {
|
|||||||
} else {
|
} else {
|
||||||
port = strconv.Itoa(service.ContainerPort.IntVal)
|
port = strconv.Itoa(service.ContainerPort.IntVal)
|
||||||
}
|
}
|
||||||
portPrefix := prefix + "_PORT_" + port + "_TCP"
|
portPrefix := prefix + "_PORT_" + strings.ToUpper(strings.Replace(port,"-","_",-1)) + "_TCP"
|
||||||
return []api.EnvVar{
|
return []api.EnvVar{
|
||||||
{
|
{
|
||||||
Name: prefix + "_PORT",
|
Name: prefix + "_PORT",
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServiceRegistry(t *testing.T) {
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user