Fix to inject KUBERNETES_ env vars when enableServiceLinks is
false and the pod is in the master namespace.
This commit is contained in:
parent
ac8799a80d
commit
e8366c8e99
@ -514,24 +514,14 @@ func (kl *Kubelet) getServiceEnvVarMap(ns string, enableServiceLinks *bool) (map
|
||||
}
|
||||
serviceName := service.Name
|
||||
|
||||
switch service.Namespace {
|
||||
// for the case whether the master service namespace is the namespace the pod
|
||||
// is in, the pod should receive all the services in the namespace.
|
||||
//
|
||||
// ordering of the case clauses below enforces this
|
||||
case ns:
|
||||
// If service links are not enabled, we shouldn't add services from
|
||||
// the same namespace.
|
||||
if !*enableServiceLinks {
|
||||
continue
|
||||
if service.Namespace == kl.masterServiceNamespace && masterServices.Has(serviceName) {
|
||||
if _, exists := serviceMap[serviceName]; !exists {
|
||||
serviceMap[serviceName] = service
|
||||
}
|
||||
} else if service.Namespace == ns && *enableServiceLinks {
|
||||
serviceMap[serviceName] = service
|
||||
case kl.masterServiceNamespace:
|
||||
if masterServices.Has(serviceName) {
|
||||
if _, exists := serviceMap[serviceName]; !exists {
|
||||
serviceMap[serviceName] = service
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ import (
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
core "k8s.io/client-go/testing"
|
||||
"k8s.io/client-go/tools/record"
|
||||
|
||||
// TODO: remove this import if
|
||||
// api.Registry.GroupOrDie(v1.GroupName).GroupVersions[0].String() is changed
|
||||
// to "v1"?
|
||||
@ -625,7 +626,15 @@ func TestMakeEnvironmentVariables(t *testing.T) {
|
||||
container: &v1.Container{},
|
||||
masterServiceNs: "kubernetes",
|
||||
nilLister: false,
|
||||
expectedEnvs: nil,
|
||||
expectedEnvs: []kubecontainer.EnvVar{
|
||||
{Name: "KUBERNETES_SERVICE_HOST", Value: "1.2.3.6"},
|
||||
{Name: "KUBERNETES_SERVICE_PORT", Value: "8086"},
|
||||
{Name: "KUBERNETES_PORT", Value: "tcp://1.2.3.6:8086"},
|
||||
{Name: "KUBERNETES_PORT_8086_TCP", Value: "tcp://1.2.3.6:8086"},
|
||||
{Name: "KUBERNETES_PORT_8086_TCP_PROTO", Value: "tcp"},
|
||||
{Name: "KUBERNETES_PORT_8086_TCP_PORT", Value: "8086"},
|
||||
{Name: "KUBERNETES_PORT_8086_TCP_ADDR", Value: "1.2.3.6"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pod in master service ns, service env vars",
|
||||
|
Loading…
Reference in New Issue
Block a user