// getServiceEnvironmentVariables populates a list of environment variables that are used
// in the container environment to get access to services.
func (b *BasicBoundPodFactory) getServiceEnvironmentVariables(ctx api.Context, registry service.Registry, machine string) ([]api.EnvVar, error) {
	var result []api.EnvVar
	servicesInNs, err := registry.ListServices(ctx)
	if err != nil {
		return result, err
	}

	masterServices, err := registry.ListServices(api.WithNamespace(api.NewContext(), b.MasterServiceNamespace))
	if err != nil {
		return result, err
	}

	projection := map[string]api.Service{}
	services := []api.Service{}
	for _, service := range masterServices.Items {
		if masterServiceNames.Has(service.Name) {
			projection[service.Name] = service
		}
	}
	for _, service := range servicesInNs.Items {
		projection[service.Name] = service
	}
	for _, service := range projection {
		services = append(services, service)
	}

	return envvars.FromServices(&api.ServiceList{Items: services}), nil
}
示例#2
0
// getServiceEnvironmentVariables populates a list of environment variables that are use
// in the container environment to get access to services.
func getServiceEnvironmentVariables(ctx api.Context, registry service.Registry, machine string) ([]api.EnvVar, error) {
	var result []api.EnvVar
	services, err := registry.ListServices(ctx)
	if err != nil {
		return result, err
	}
	return envvars.FromServices(services), nil
}