mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 02:34:03 +00:00
Merge pull request #4359 from erictune/no_bound_pod_envs
Stop putting env vars into BoundPods.
This commit is contained in:
commit
3bc8f4e793
@ -253,12 +253,7 @@ func setDefaults(c *Config) {
|
|||||||
// any unhandled paths to "Handler".
|
// any unhandled paths to "Handler".
|
||||||
func New(c *Config) *Master {
|
func New(c *Config) *Master {
|
||||||
setDefaults(c)
|
setDefaults(c)
|
||||||
minionRegistry := etcd.NewRegistry(c.EtcdHelper, nil)
|
boundPodFactory := &pod.BasicBoundPodFactory{}
|
||||||
serviceRegistry := etcd.NewRegistry(c.EtcdHelper, nil)
|
|
||||||
boundPodFactory := &pod.BasicBoundPodFactory{
|
|
||||||
ServiceRegistry: serviceRegistry,
|
|
||||||
MasterServiceNamespace: c.MasterServiceNamespace,
|
|
||||||
}
|
|
||||||
if c.KubeletClient == nil {
|
if c.KubeletClient == nil {
|
||||||
glog.Fatalf("master.New() called with config.KubeletClient == nil")
|
glog.Fatalf("master.New() called with config.KubeletClient == nil")
|
||||||
}
|
}
|
||||||
@ -277,12 +272,12 @@ func New(c *Config) *Master {
|
|||||||
m := &Master{
|
m := &Master{
|
||||||
podRegistry: etcd.NewRegistry(c.EtcdHelper, boundPodFactory),
|
podRegistry: etcd.NewRegistry(c.EtcdHelper, boundPodFactory),
|
||||||
controllerRegistry: etcd.NewRegistry(c.EtcdHelper, nil),
|
controllerRegistry: etcd.NewRegistry(c.EtcdHelper, nil),
|
||||||
serviceRegistry: serviceRegistry,
|
serviceRegistry: etcd.NewRegistry(c.EtcdHelper, nil),
|
||||||
endpointRegistry: etcd.NewRegistry(c.EtcdHelper, nil),
|
endpointRegistry: etcd.NewRegistry(c.EtcdHelper, nil),
|
||||||
bindingRegistry: etcd.NewRegistry(c.EtcdHelper, boundPodFactory),
|
bindingRegistry: etcd.NewRegistry(c.EtcdHelper, boundPodFactory),
|
||||||
eventRegistry: event.NewEtcdRegistry(c.EtcdHelper, uint64(c.EventTTL.Seconds())),
|
eventRegistry: event.NewEtcdRegistry(c.EtcdHelper, uint64(c.EventTTL.Seconds())),
|
||||||
namespaceRegistry: namespace.NewEtcdRegistry(c.EtcdHelper),
|
namespaceRegistry: namespace.NewEtcdRegistry(c.EtcdHelper),
|
||||||
minionRegistry: minionRegistry,
|
minionRegistry: etcd.NewRegistry(c.EtcdHelper, nil),
|
||||||
limitRangeRegistry: limitrange.NewEtcdRegistry(c.EtcdHelper),
|
limitRangeRegistry: limitrange.NewEtcdRegistry(c.EtcdHelper),
|
||||||
resourceQuotaRegistry: resourcequota.NewEtcdRegistry(c.EtcdHelper),
|
resourceQuotaRegistry: resourcequota.NewEtcdRegistry(c.EtcdHelper),
|
||||||
client: c.Client,
|
client: c.Client,
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||||
|
|
||||||
@ -36,9 +35,7 @@ import (
|
|||||||
|
|
||||||
func NewTestEtcdRegistry(client tools.EtcdClient) *Registry {
|
func NewTestEtcdRegistry(client tools.EtcdClient) *Registry {
|
||||||
registry := NewRegistry(tools.EtcdHelper{client, latest.Codec, tools.RuntimeVersionAdapter{latest.ResourceVersioner}},
|
registry := NewRegistry(tools.EtcdHelper{client, latest.Codec, tools.RuntimeVersionAdapter{latest.ResourceVersioner}},
|
||||||
&pod.BasicBoundPodFactory{
|
&pod.BasicBoundPodFactory{})
|
||||||
ServiceRegistry: ®istrytest.ServiceRegistry{},
|
|
||||||
})
|
|
||||||
return registry
|
return registry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,6 @@ package pod
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/envvars"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/service"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BoundPodFactory interface {
|
type BoundPodFactory interface {
|
||||||
@ -28,58 +25,13 @@ type BoundPodFactory interface {
|
|||||||
MakeBoundPod(machine string, pod *api.Pod) (*api.BoundPod, error)
|
MakeBoundPod(machine string, pod *api.Pod) (*api.BoundPod, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasicBoundPodFactory struct {
|
type BasicBoundPodFactory struct{}
|
||||||
// TODO: this should really point at the API rather than a registry
|
|
||||||
ServiceRegistry service.Registry
|
|
||||||
MasterServiceNamespace string
|
|
||||||
}
|
|
||||||
|
|
||||||
var masterServiceNames = util.NewStringSet("kubernetes", "kubernetes-ro")
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *BasicBoundPodFactory) MakeBoundPod(machine string, pod *api.Pod) (*api.BoundPod, error) {
|
func (b *BasicBoundPodFactory) MakeBoundPod(machine string, pod *api.Pod) (*api.BoundPod, error) {
|
||||||
envVars, err := b.getServiceEnvironmentVariables(api.WithNamespace(api.NewContext(), pod.Namespace), b.ServiceRegistry, machine)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
boundPod := &api.BoundPod{}
|
boundPod := &api.BoundPod{}
|
||||||
if err := api.Scheme.Convert(pod, boundPod); err != nil {
|
if err := api.Scheme.Convert(pod, boundPod); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for ix, container := range boundPod.Spec.Containers {
|
|
||||||
boundPod.Spec.Containers[ix].Env = append(container.Env, envVars...)
|
|
||||||
}
|
|
||||||
// Make a dummy self link so that references to this bound pod will work.
|
// Make a dummy self link so that references to this bound pod will work.
|
||||||
boundPod.SelfLink = "/api/v1beta1/boundPods/" + boundPod.Name
|
boundPod.SelfLink = "/api/v1beta1/boundPods/" + boundPod.Name
|
||||||
return boundPod, nil
|
return boundPod, nil
|
||||||
|
@ -17,19 +17,13 @@ limitations under the License.
|
|||||||
package pod
|
package pod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMakeBoundPodNoServices(t *testing.T) {
|
func TestMakeBoundPodNoServices(t *testing.T) {
|
||||||
registry := registrytest.ServiceRegistry{}
|
factory := &BasicBoundPodFactory{}
|
||||||
factory := &BasicBoundPodFactory{
|
|
||||||
ServiceRegistry: ®istry,
|
|
||||||
MasterServiceNamespace: api.NamespaceDefault,
|
|
||||||
}
|
|
||||||
|
|
||||||
pod, err := factory.MakeBoundPod("machine", &api.Pod{
|
pod, err := factory.MakeBoundPod("machine", &api.Pod{
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foobar"},
|
ObjectMeta: api.ObjectMeta{Name: "foobar"},
|
||||||
@ -57,396 +51,3 @@ func TestMakeBoundPodNoServices(t *testing.T) {
|
|||||||
t.Errorf("Unable to get a reference to bound pod: %v", err)
|
t.Errorf("Unable to get a reference to bound pod: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMakeBoundPodServices(t *testing.T) {
|
|
||||||
registry := registrytest.ServiceRegistry{
|
|
||||||
List: api.ServiceList{
|
|
||||||
Items: []api.Service{
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8080,
|
|
||||||
PortalIP: "1.2.3.4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
factory := &BasicBoundPodFactory{
|
|
||||||
ServiceRegistry: ®istry,
|
|
||||||
MasterServiceNamespace: api.NamespaceDefault,
|
|
||||||
}
|
|
||||||
|
|
||||||
pod, err := factory.MakeBoundPod("machine", &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foobar", Namespace: "test"},
|
|
||||||
Spec: api.PodSpec{
|
|
||||||
Containers: []api.Container{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
container := pod.Spec.Containers[0]
|
|
||||||
envs := []api.EnvVar{
|
|
||||||
{
|
|
||||||
Name: "TEST_SERVICE_HOST",
|
|
||||||
Value: "1.2.3.4",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_SERVICE_PORT",
|
|
||||||
Value: "8080",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT",
|
|
||||||
Value: "tcp://1.2.3.4:8080",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT_8080_TCP",
|
|
||||||
Value: "tcp://1.2.3.4:8080",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT_8080_TCP_PROTO",
|
|
||||||
Value: "tcp",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT_8080_TCP_PORT",
|
|
||||||
Value: "8080",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT_8080_TCP_ADDR",
|
|
||||||
Value: "1.2.3.4",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if len(container.Env) != len(envs) {
|
|
||||||
t.Fatalf("Expected %d env vars, got %d: %#v", len(envs), len(container.Env), pod)
|
|
||||||
}
|
|
||||||
for ix := range container.Env {
|
|
||||||
if !reflect.DeepEqual(envs[ix], container.Env[ix]) {
|
|
||||||
t.Errorf("expected %#v, got %#v", envs[ix], container.Env[ix])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMakeBoundPodServicesExistingEnvVar(t *testing.T) {
|
|
||||||
registry := registrytest.ServiceRegistry{
|
|
||||||
List: api.ServiceList{
|
|
||||||
Items: []api.Service{
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8080,
|
|
||||||
PortalIP: "1.2.3.4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
factory := &BasicBoundPodFactory{
|
|
||||||
ServiceRegistry: ®istry,
|
|
||||||
MasterServiceNamespace: api.NamespaceDefault,
|
|
||||||
}
|
|
||||||
|
|
||||||
pod, err := factory.MakeBoundPod("machine", &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foobar", Namespace: "test"},
|
|
||||||
Spec: api.PodSpec{
|
|
||||||
Containers: []api.Container{
|
|
||||||
{
|
|
||||||
Env: []api.EnvVar{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
Value: "bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
container := pod.Spec.Containers[0]
|
|
||||||
|
|
||||||
envs := []api.EnvVar{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
Value: "bar",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_SERVICE_HOST",
|
|
||||||
Value: "1.2.3.4",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_SERVICE_PORT",
|
|
||||||
Value: "8080",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT",
|
|
||||||
Value: "tcp://1.2.3.4:8080",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT_8080_TCP",
|
|
||||||
Value: "tcp://1.2.3.4:8080",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT_8080_TCP_PROTO",
|
|
||||||
Value: "tcp",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT_8080_TCP_PORT",
|
|
||||||
Value: "8080",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "TEST_PORT_8080_TCP_ADDR",
|
|
||||||
Value: "1.2.3.4",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if len(container.Env) != len(envs) {
|
|
||||||
t.Fatalf("Expected %d env vars, got: %#v", len(envs), pod)
|
|
||||||
}
|
|
||||||
for ix := range container.Env {
|
|
||||||
if !reflect.DeepEqual(envs[ix], container.Env[ix]) {
|
|
||||||
t.Errorf("expected %#v, got %#v", envs[ix], container.Env[ix])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMakeBoundPodOnlyVisibleServices(t *testing.T) {
|
|
||||||
registry := registrytest.ServiceRegistry{
|
|
||||||
List: api.ServiceList{
|
|
||||||
Items: []api.Service{
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test", Namespace: api.NamespaceDefault},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8080,
|
|
||||||
PortalIP: "1.2.3.4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8081,
|
|
||||||
PortalIP: "1.2.3.5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test3", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8083,
|
|
||||||
PortalIP: "1.2.3.7",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
factory := &BasicBoundPodFactory{
|
|
||||||
ServiceRegistry: ®istry,
|
|
||||||
MasterServiceNamespace: api.NamespaceDefault,
|
|
||||||
}
|
|
||||||
|
|
||||||
pod, err := factory.MakeBoundPod("machine", &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foobar", Namespace: "test"},
|
|
||||||
Spec: api.PodSpec{
|
|
||||||
Containers: []api.Container{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
container := pod.Spec.Containers[0]
|
|
||||||
envs := map[string]string{
|
|
||||||
"TEST_SERVICE_HOST": "1.2.3.5",
|
|
||||||
"TEST_SERVICE_PORT": "8081",
|
|
||||||
"TEST_PORT": "tcp://1.2.3.5:8081",
|
|
||||||
"TEST_PORT_8081_TCP": "tcp://1.2.3.5:8081",
|
|
||||||
"TEST_PORT_8081_TCP_PROTO": "tcp",
|
|
||||||
"TEST_PORT_8081_TCP_PORT": "8081",
|
|
||||||
"TEST_PORT_8081_TCP_ADDR": "1.2.3.5",
|
|
||||||
"TEST3_SERVICE_HOST": "1.2.3.7",
|
|
||||||
"TEST3_SERVICE_PORT": "8083",
|
|
||||||
"TEST3_PORT": "tcp://1.2.3.7:8083",
|
|
||||||
"TEST3_PORT_8083_TCP": "tcp://1.2.3.7:8083",
|
|
||||||
"TEST3_PORT_8083_TCP_PROTO": "tcp",
|
|
||||||
"TEST3_PORT_8083_TCP_PORT": "8083",
|
|
||||||
"TEST3_PORT_8083_TCP_ADDR": "1.2.3.7",
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(container.Env) != len(envs) {
|
|
||||||
t.Fatalf("Expected %d env vars, got %d: %#v", len(envs), len(container.Env), pod)
|
|
||||||
}
|
|
||||||
for _, env := range container.Env {
|
|
||||||
expectedValue := envs[env.Name]
|
|
||||||
if expectedValue != env.Value {
|
|
||||||
t.Errorf("expected env %v value %v, got %v", env.Name, expectedValue, env.Value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMakeBoundPodMasterServices(t *testing.T) {
|
|
||||||
registry := registrytest.ServiceRegistry{
|
|
||||||
List: api.ServiceList{
|
|
||||||
Items: []api.Service{
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "kubernetes", Namespace: api.NamespaceDefault},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8080,
|
|
||||||
PortalIP: "1.2.3.4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8081,
|
|
||||||
PortalIP: "1.2.3.5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test3", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8083,
|
|
||||||
PortalIP: "1.2.3.7",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
factory := &BasicBoundPodFactory{
|
|
||||||
ServiceRegistry: ®istry,
|
|
||||||
MasterServiceNamespace: api.NamespaceDefault,
|
|
||||||
}
|
|
||||||
|
|
||||||
pod, err := factory.MakeBoundPod("machine", &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foobar", Namespace: "test"},
|
|
||||||
Spec: api.PodSpec{
|
|
||||||
Containers: []api.Container{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
container := pod.Spec.Containers[0]
|
|
||||||
envs := map[string]string{
|
|
||||||
"TEST_SERVICE_HOST": "1.2.3.5",
|
|
||||||
"TEST_SERVICE_PORT": "8081",
|
|
||||||
"TEST_PORT": "tcp://1.2.3.5:8081",
|
|
||||||
"TEST_PORT_8081_TCP": "tcp://1.2.3.5:8081",
|
|
||||||
"TEST_PORT_8081_TCP_PROTO": "tcp",
|
|
||||||
"TEST_PORT_8081_TCP_PORT": "8081",
|
|
||||||
"TEST_PORT_8081_TCP_ADDR": "1.2.3.5",
|
|
||||||
"TEST3_SERVICE_HOST": "1.2.3.7",
|
|
||||||
"TEST3_SERVICE_PORT": "8083",
|
|
||||||
"TEST3_PORT": "tcp://1.2.3.7:8083",
|
|
||||||
"TEST3_PORT_8083_TCP": "tcp://1.2.3.7:8083",
|
|
||||||
"TEST3_PORT_8083_TCP_PROTO": "tcp",
|
|
||||||
"TEST3_PORT_8083_TCP_PORT": "8083",
|
|
||||||
"TEST3_PORT_8083_TCP_ADDR": "1.2.3.7",
|
|
||||||
"KUBERNETES_SERVICE_HOST": "1.2.3.4",
|
|
||||||
"KUBERNETES_SERVICE_PORT": "8080",
|
|
||||||
"KUBERNETES_PORT": "tcp://1.2.3.4:8080",
|
|
||||||
"KUBERNETES_PORT_8080_TCP": "tcp://1.2.3.4:8080",
|
|
||||||
"KUBERNETES_PORT_8080_TCP_PROTO": "tcp",
|
|
||||||
"KUBERNETES_PORT_8080_TCP_PORT": "8080",
|
|
||||||
"KUBERNETES_PORT_8080_TCP_ADDR": "1.2.3.4",
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(container.Env) != len(envs) {
|
|
||||||
t.Fatalf("Expected %d env vars, got %d: %#v", len(envs), len(container.Env), pod)
|
|
||||||
}
|
|
||||||
for _, env := range container.Env {
|
|
||||||
expectedValue := envs[env.Name]
|
|
||||||
if expectedValue != env.Value {
|
|
||||||
t.Errorf("expected env %v value %v, got %v", env.Name, expectedValue, env.Value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMakeBoundPodMasterServiceInNs(t *testing.T) {
|
|
||||||
registry := registrytest.ServiceRegistry{
|
|
||||||
List: api.ServiceList{
|
|
||||||
Items: []api.Service{
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "kubernetes", Namespace: api.NamespaceDefault},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8080,
|
|
||||||
PortalIP: "1.2.3.4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "test", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8081,
|
|
||||||
PortalIP: "1.2.3.5",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "kubernetes", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Port: 8083,
|
|
||||||
PortalIP: "1.2.3.7",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
factory := &BasicBoundPodFactory{
|
|
||||||
ServiceRegistry: ®istry,
|
|
||||||
MasterServiceNamespace: api.NamespaceDefault,
|
|
||||||
}
|
|
||||||
|
|
||||||
pod, err := factory.MakeBoundPod("machine", &api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "foobar", Namespace: "test"},
|
|
||||||
Spec: api.PodSpec{
|
|
||||||
Containers: []api.Container{
|
|
||||||
{
|
|
||||||
Name: "foo",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
container := pod.Spec.Containers[0]
|
|
||||||
envs := map[string]string{
|
|
||||||
"TEST_SERVICE_HOST": "1.2.3.5",
|
|
||||||
"TEST_SERVICE_PORT": "8081",
|
|
||||||
"TEST_PORT": "tcp://1.2.3.5:8081",
|
|
||||||
"TEST_PORT_8081_TCP": "tcp://1.2.3.5:8081",
|
|
||||||
"TEST_PORT_8081_TCP_PROTO": "tcp",
|
|
||||||
"TEST_PORT_8081_TCP_PORT": "8081",
|
|
||||||
"TEST_PORT_8081_TCP_ADDR": "1.2.3.5",
|
|
||||||
"KUBERNETES_SERVICE_HOST": "1.2.3.7",
|
|
||||||
"KUBERNETES_SERVICE_PORT": "8083",
|
|
||||||
"KUBERNETES_PORT": "tcp://1.2.3.7:8083",
|
|
||||||
"KUBERNETES_PORT_8083_TCP": "tcp://1.2.3.7:8083",
|
|
||||||
"KUBERNETES_PORT_8083_TCP_PROTO": "tcp",
|
|
||||||
"KUBERNETES_PORT_8083_TCP_PORT": "8083",
|
|
||||||
"KUBERNETES_PORT_8083_TCP_ADDR": "1.2.3.7",
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(container.Env) != len(envs) {
|
|
||||||
t.Fatalf("Expected %d env vars, got %d: %#v", len(envs), len(container.Env), pod)
|
|
||||||
}
|
|
||||||
for _, env := range container.Env {
|
|
||||||
expectedValue := envs[env.Name]
|
|
||||||
if expectedValue != env.Value {
|
|
||||||
t.Errorf("expected env %v value %v, got %v", env.Name, expectedValue, env.Value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user