Headless Services: Adding option to specify None for PortalIP

This commit is contained in:
Abhishek Gupta
2015-03-16 14:36:30 -07:00
parent 7f02e110f4
commit b0c23c1046
16 changed files with 237 additions and 16 deletions

View File

@@ -30,6 +30,12 @@ import (
func FromServices(services *api.ServiceList) []api.EnvVar {
var result []api.EnvVar
for _, service := range services.Items {
// ignore services where PortalIP is "None" or empty
// the services passed to this method should be pre-filtered
// only services that have the portal IP set should be included here
if !api.IsServiceIPSet(&service) {
continue
}
// Host
name := makeEnvVariableName(service.Name) + "_SERVICE_HOST"
result = append(result, api.EnvVar{Name: name, Value: service.Spec.PortalIP})

View File

@@ -54,6 +54,24 @@ func TestFromServices(t *testing.T) {
PortalIP: "9.8.7.6",
},
},
{
ObjectMeta: api.ObjectMeta{Name: "svrc-portalip-none"},
Spec: api.ServiceSpec{
Port: 8082,
Selector: map[string]string{"bar": "baz"},
Protocol: "TCP",
PortalIP: "None",
},
},
{
ObjectMeta: api.ObjectMeta{Name: "svrc-portalip-empty"},
Spec: api.ServiceSpec{
Port: 8082,
Selector: map[string]string{"bar": "baz"},
Protocol: "TCP",
PortalIP: "",
},
},
},
}
vars := envvars.FromServices(&sl)