Merge pull request #68754 from bradhoekstra/optional-service-env-variables

kubelet: Make service environment variables optional
pull/58/head
k8s-ci-robot 2018-09-24 10:59:32 -07:00 committed by GitHub
commit 170dcc2ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 1425 additions and 879 deletions

View File

@ -83057,6 +83057,10 @@
"description": "Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.",
"type": "string"
},
"enableServiceLinks": {
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links.",
"type": "boolean"
},
"hostAliases": {
"description": "HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts file if specified. This is only valid for non-hostNetwork pods.",
"type": "array",

View File

@ -6826,6 +6826,10 @@
"runtimeClassName": {
"type": "string",
"description": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future."
},
"enableServiceLinks": {
"type": "boolean",
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links."
}
}
},

View File

@ -4434,6 +4434,10 @@
"runtimeClassName": {
"type": "string",
"description": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future."
},
"enableServiceLinks": {
"type": "boolean",
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links."
}
}
},

View File

@ -6826,6 +6826,10 @@
"runtimeClassName": {
"type": "string",
"description": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future."
},
"enableServiceLinks": {
"type": "boolean",
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links."
}
}
},

View File

@ -1746,6 +1746,10 @@
"runtimeClassName": {
"type": "string",
"description": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future."
},
"enableServiceLinks": {
"type": "boolean",
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links."
}
}
},

View File

@ -1801,6 +1801,10 @@
"runtimeClassName": {
"type": "string",
"description": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future."
},
"enableServiceLinks": {
"type": "boolean",
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links."
}
}
},

View File

@ -1801,6 +1801,10 @@
"runtimeClassName": {
"type": "string",
"description": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future."
},
"enableServiceLinks": {
"type": "boolean",
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links."
}
}
},

View File

@ -7474,6 +7474,10 @@
"runtimeClassName": {
"type": "string",
"description": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future."
},
"enableServiceLinks": {
"type": "boolean",
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links."
}
}
},

View File

@ -20607,6 +20607,10 @@
"runtimeClassName": {
"type": "string",
"description": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future."
},
"enableServiceLinks": {
"type": "boolean",
"description": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links."
}
}
},

View File

@ -4090,6 +4090,13 @@ When an object is created, the system will populate this list with the current s
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enableServiceLinks</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">EnableServiceLinks indicates whether information about services should be injected into pod&#8217;s environment variables, matching the syntax of Docker links.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>

View File

@ -4143,6 +4143,13 @@ The StatefulSet guarantees that a given network identity will always map to the
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enableServiceLinks</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">EnableServiceLinks indicates whether information about services should be injected into pod&#8217;s environment variables, matching the syntax of Docker links.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>

View File

@ -4759,6 +4759,13 @@ The StatefulSet guarantees that a given network identity will always map to the
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enableServiceLinks</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">EnableServiceLinks indicates whether information about services should be injected into pod&#8217;s environment variables, matching the syntax of Docker links.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>

View File

@ -3375,6 +3375,13 @@ When an object is created, the system will populate this list with the current s
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enableServiceLinks</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">EnableServiceLinks indicates whether information about services should be injected into pod&#8217;s environment variables, matching the syntax of Docker links.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>

View File

@ -3409,6 +3409,13 @@ When an object is created, the system will populate this list with the current s
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enableServiceLinks</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">EnableServiceLinks indicates whether information about services should be injected into pod&#8217;s environment variables, matching the syntax of Docker links.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>

View File

@ -3382,6 +3382,13 @@ When an object is created, the system will populate this list with the current s
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enableServiceLinks</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">EnableServiceLinks indicates whether information about services should be injected into pod&#8217;s environment variables, matching the syntax of Docker links.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>

View File

@ -4734,6 +4734,13 @@ When an object is created, the system will populate this list with the current s
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enableServiceLinks</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">EnableServiceLinks indicates whether information about services should be injected into pod&#8217;s environment variables, matching the syntax of Docker links.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>

View File

@ -9780,6 +9780,13 @@ More info: <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifec
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enableServiceLinks</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">EnableServiceLinks indicates whether information about services should be injected into pod&#8217;s environment variables, matching the syntax of Docker links.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>

View File

@ -24,22 +24,26 @@ import (
// DeepEqualSafePodSpec returns a PodSpec which is ready to be used with apiequality.Semantic.DeepEqual
func DeepEqualSafePodSpec() api.PodSpec {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
return api.PodSpec{
RestartPolicy: api.RestartPolicyAlways,
DNSPolicy: api.DNSClusterFirst,
TerminationGracePeriodSeconds: &grace,
SecurityContext: &api.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
}
}
// V1DeepEqualSafePodSpec returns a PodSpec which is ready to be used with apiequality.Semantic.DeepEqual
func V1DeepEqualSafePodSpec() v1.PodSpec {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
return v1.PodSpec{
RestartPolicy: v1.RestartPolicyAlways,
DNSPolicy: v1.DNSClusterFirst,
TerminationGracePeriodSeconds: &grace,
SecurityContext: &v1.PodSecurityContext{},
EnableServiceLinks: &enableServiceLinks,
}
}

View File

@ -214,6 +214,7 @@ func TestRoundTripTypes(t *testing.T) {
// decoded without information loss or mutation.
func TestEncodePtr(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
pod := &api.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"name": "foo"},
@ -226,6 +227,7 @@ func TestEncodePtr(t *testing.T) {
SecurityContext: &api.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
obj := runtime.Object(pod)

View File

@ -39,6 +39,7 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
defaultLabels := map[string]string{"foo": "bar"}
maxUnavailable := intstr.FromInt(1)
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -46,6 +47,7 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
ObjectMeta: metav1.ObjectMeta{
Labels: defaultLabels,
@ -58,6 +60,7 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
tests := []struct {
@ -175,6 +178,7 @@ func TestSetDefaultStatefulSet(t *testing.T) {
var defaultReplicas int32 = 1
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -182,6 +186,7 @@ func TestSetDefaultStatefulSet(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
ObjectMeta: metav1.ObjectMeta{
Labels: defaultLabels,
@ -286,6 +291,7 @@ func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := intstr.FromString("25%")
differentIntOrString := intstr.FromInt(5)
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -293,6 +299,7 @@ func TestSetDefaultDeployment(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
tests := []struct {

View File

@ -38,6 +38,7 @@ func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := intstr.FromString("25%")
differentIntOrString := intstr.FromInt(5)
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -45,6 +46,7 @@ func TestSetDefaultDeployment(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
tests := []struct {

View File

@ -39,6 +39,7 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
defaultLabels := map[string]string{"foo": "bar"}
maxUnavailable := intstr.FromInt(1)
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -46,6 +47,7 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
ObjectMeta: metav1.ObjectMeta{
Labels: defaultLabels,
@ -58,6 +60,7 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
tests := []struct {
@ -175,6 +178,7 @@ func TestSetDefaultStatefulSet(t *testing.T) {
var defaultReplicas int32 = 1
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -182,6 +186,7 @@ func TestSetDefaultStatefulSet(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
ObjectMeta: metav1.ObjectMeta{
Labels: defaultLabels,
@ -286,6 +291,7 @@ func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := intstr.FromString("25%")
differentIntOrString := intstr.FromInt(5)
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -293,6 +299,7 @@ func TestSetDefaultDeployment(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
tests := []struct {

View File

@ -11,6 +11,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/apis/core/fuzzer",
deps = [
"//pkg/apis/core:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",

View File

@ -23,6 +23,7 @@ import (
fuzz "github.com/google/gofuzz"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
@ -84,6 +85,10 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
if s.SchedulerName == "" {
s.SchedulerName = core.DefaultSchedulerName
}
if s.EnableServiceLinks == nil {
enableServiceLinks := corev1.DefaultEnableServiceLinks
s.EnableServiceLinks = &enableServiceLinks
}
},
func(j *core.PodPhase, c fuzz.Continue) {
statuses := []core.PodPhase{core.PodPending, core.PodRunning, core.PodFailed, core.PodUnknown}

View File

@ -2597,6 +2597,11 @@ type PodSpec struct {
// This is an alpha feature and may change in the future.
// +optional
RuntimeClassName *string
// EnableServiceLinks indicates whether information about services should be injected into pod's
// environment variables, matching the syntax of Docker links.
// If not specified, the default is true.
// +optional
EnableServiceLinks *bool
}
// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the

View File

@ -182,6 +182,10 @@ func SetDefaults_PodSpec(obj *v1.PodSpec) {
if obj.SchedulerName == "" {
obj.SchedulerName = v1.DefaultSchedulerName
}
if obj.EnableServiceLinks == nil {
enableServiceLinks := v1.DefaultEnableServiceLinks
obj.EnableServiceLinks = &enableServiceLinks
}
}
func SetDefaults_Probe(obj *v1.Probe) {
if obj.TimeoutSeconds == 0 {

View File

@ -1370,3 +1370,11 @@ func TestSetDefaultHostPathVolumeSource(t *testing.T) {
t.Errorf("Expected v1.HostPathVolumeSource default type %v, got %v", expectedType, defaultType)
}
}
func TestSetDefaultEnableServiceLinks(t *testing.T) {
pod := &v1.Pod{}
output := roundTrip(t, runtime.Object(pod)).(*v1.Pod)
if output.Spec.EnableServiceLinks == nil || *output.Spec.EnableServiceLinks != v1.DefaultEnableServiceLinks {
t.Errorf("Expected enableServiceLinks value: %+v\ngot: %+v\n", v1.DefaultEnableServiceLinks, *output.Spec.EnableServiceLinks)
}
}

View File

@ -5550,6 +5550,7 @@ func autoConvert_v1_PodSpec_To_core_PodSpec(in *v1.PodSpec, out *core.PodSpec, s
out.DNSConfig = (*core.PodDNSConfig)(unsafe.Pointer(in.DNSConfig))
out.ReadinessGates = *(*[]core.PodReadinessGate)(unsafe.Pointer(&in.ReadinessGates))
out.RuntimeClassName = (*string)(unsafe.Pointer(in.RuntimeClassName))
out.EnableServiceLinks = (*bool)(unsafe.Pointer(in.EnableServiceLinks))
return nil
}
@ -5616,6 +5617,7 @@ func autoConvert_core_PodSpec_To_v1_PodSpec(in *core.PodSpec, out *v1.PodSpec, s
out.DNSConfig = (*v1.PodDNSConfig)(unsafe.Pointer(in.DNSConfig))
out.ReadinessGates = *(*[]v1.PodReadinessGate)(unsafe.Pointer(&in.ReadinessGates))
out.RuntimeClassName = (*string)(unsafe.Pointer(in.RuntimeClassName))
out.EnableServiceLinks = (*bool)(unsafe.Pointer(in.EnableServiceLinks))
return nil
}

View File

@ -3556,6 +3556,11 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) {
*out = new(string)
**out = **in
}
if in.EnableServiceLinks != nil {
in, out := &in.EnableServiceLinks, &out.EnableServiceLinks
*out = new(bool)
**out = **in
}
return
}

View File

@ -40,6 +40,7 @@ import (
func TestSetDefaultDaemonSetSpec(t *testing.T) {
defaultLabels := map[string]string{"foo": "bar"}
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -47,6 +48,7 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
ObjectMeta: metav1.ObjectMeta{
Labels: defaultLabels,
@ -59,6 +61,7 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
tests := []struct {
@ -164,6 +167,7 @@ func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := intstr.FromInt(1)
differentIntOrString := intstr.FromInt(5)
period := int64(v1.DefaultTerminationGracePeriodSeconds)
enableServiceLinks := v1.DefaultEnableServiceLinks
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
@ -171,6 +175,7 @@ func TestSetDefaultDeployment(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
tests := []struct {

View File

@ -151,6 +151,7 @@ func randomUID() types.UID {
func generateDeployment(image string) apps.Deployment {
podLabels := map[string]string{"name": image}
terminationSec := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
return apps.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: image,
@ -176,6 +177,7 @@ func generateDeployment(image string) apps.Deployment {
TerminationGracePeriodSeconds: &terminationSec,
RestartPolicy: v1.RestartPolicyAlways,
SecurityContext: &v1.PodSecurityContext{},
EnableServiceLinks: &enableServiceLinks,
},
},
},

View File

@ -896,6 +896,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
"spec": {
"containers": null,
"dnsPolicy": "ClusterFirst",
"enableServiceLinks": true,
"restartPolicy": "Always",
"securityContext": {},
"terminationGracePeriodSeconds": 30
@ -914,6 +915,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
"spec": {
"containers": null,
"dnsPolicy": "ClusterFirst",
"enableServiceLinks": true,
"restartPolicy": "Always",
"securityContext": {},
"terminationGracePeriodSeconds": 30

View File

@ -64,6 +64,7 @@ go_test(
"//pkg/api/testapi:go_default_library",
"//pkg/api/testing:go_default_library",
"//pkg/apis/core:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",

View File

@ -24,6 +24,7 @@ import (
"syscall"
"testing"
"k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
@ -39,6 +40,7 @@ import (
func TestMerge(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
tests := []struct {
obj runtime.Object
fragment string
@ -125,6 +127,7 @@ func TestMerge(t *testing.T) {
TerminationGracePeriodSeconds: &grace,
SecurityContext: &api.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
},
},

View File

@ -37,6 +37,7 @@ func noDefault(*core.Pod) error { return nil }
func TestDecodeSinglePod(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
pod := &v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "",
@ -60,6 +61,7 @@ func TestDecodeSinglePod(t *testing.T) {
}},
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: core.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
json, err := runtime.Encode(testapi.Default.Codec(), pod)
@ -99,6 +101,7 @@ func TestDecodeSinglePod(t *testing.T) {
func TestDecodePodList(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
pod := &v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "",
@ -123,6 +126,7 @@ func TestDecodePodList(t *testing.T) {
}},
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: core.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
podList := &v1.PodList{

View File

@ -140,6 +140,7 @@ type testCase struct {
func getTestCases(hostname types.NodeName) []*testCase {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
return []*testCase{
{
lock: &sync.Mutex{},
@ -190,6 +191,7 @@ func getTestCases(hostname types.NodeName) []*testCase {
}},
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
Status: v1.PodStatus{
Phase: v1.PodPending,

View File

@ -129,6 +129,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
nodeName := "different-value"
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
var testCases = []struct {
desc string
pods runtime.Object
@ -173,6 +174,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &grace,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Containers: []v1.Container{{
Name: "1",
@ -244,6 +246,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
TerminationGracePeriodSeconds: &grace,
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Containers: []v1.Container{{
Name: "1",
@ -272,6 +275,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
TerminationGracePeriodSeconds: &grace,
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Containers: []v1.Container{{
Name: "2",

View File

@ -488,7 +488,7 @@ var masterServices = sets.NewString("kubernetes")
// getServiceEnvVarMap makes a map[string]string of env vars for services a
// pod in namespace ns should see.
func (kl *Kubelet) getServiceEnvVarMap(ns string) (map[string]string, error) {
func (kl *Kubelet) getServiceEnvVarMap(ns string, enableServiceLinks bool) (map[string]string, error) {
var (
serviceMap = make(map[string]*v1.Service)
m = make(map[string]string)
@ -514,19 +514,16 @@ func (kl *Kubelet) getServiceEnvVarMap(ns string) (map[string]string, error) {
}
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:
serviceMap[serviceName] = service
case kl.masterServiceNamespace:
if masterServices.Has(serviceName) {
// We always want to add environment variabled for master services
// from the master service namespace, even if enableServiceLinks is false.
// We also add environment variables for other services in the same
// namespace, if enableServiceLinks is true.
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
}
}
@ -553,7 +550,7 @@ func (kl *Kubelet) makeEnvironmentVariables(pod *v1.Pod, container *v1.Container
// To avoid this users can: (1) wait between starting a service and starting; or (2) detect
// missing service env var and exit and be restarted; or (3) use DNS instead of env vars
// and keep trying to resolve the DNS name of the service (recommended).
serviceEnv, err := kl.getServiceEnvVarMap(pod.Namespace)
serviceEnv, err := kl.getServiceEnvVarMap(pod.Namespace, *pod.Spec.EnableServiceLinks)
if err != nil {
return result, err
}

View File

@ -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"?
@ -441,6 +442,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
testCases := []struct {
name string // the name of the test case
ns string // the namespace to generate environment for
enableServiceLinks bool // enabling service links
container *v1.Container // the container to use
masterServiceNs string // the namespace to read master service info from
nilLister bool // whether the lister should be nil
@ -453,6 +455,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "api server = Y, kubelet = Y",
ns: "test1",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{Name: "FOO", Value: "BAR"},
@ -488,6 +491,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "api server = Y, kubelet = N",
ns: "test1",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{Name: "FOO", Value: "BAR"},
@ -516,6 +520,29 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "api server = N; kubelet = Y",
ns: "test1",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{Name: "FOO", Value: "BAZ"},
},
},
masterServiceNs: metav1.NamespaceDefault,
nilLister: false,
expectedEnvs: []kubecontainer.EnvVar{
{Name: "FOO", Value: "BAZ"},
{Name: "KUBERNETES_SERVICE_HOST", Value: "1.2.3.1"},
{Name: "KUBERNETES_SERVICE_PORT", Value: "8081"},
{Name: "KUBERNETES_PORT", Value: "tcp://1.2.3.1:8081"},
{Name: "KUBERNETES_PORT_8081_TCP", Value: "tcp://1.2.3.1:8081"},
{Name: "KUBERNETES_PORT_8081_TCP_PROTO", Value: "tcp"},
{Name: "KUBERNETES_PORT_8081_TCP_PORT", Value: "8081"},
{Name: "KUBERNETES_PORT_8081_TCP_ADDR", Value: "1.2.3.1"},
},
},
{
name: "api server = N; kubelet = Y; service env vars",
ns: "test1",
enableServiceLinks: true,
container: &v1.Container{
Env: []v1.EnvVar{
{Name: "FOO", Value: "BAZ"},
@ -544,6 +571,29 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "master service in pod ns",
ns: "test2",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{Name: "FOO", Value: "ZAP"},
},
},
masterServiceNs: "kubernetes",
nilLister: false,
expectedEnvs: []kubecontainer.EnvVar{
{Name: "FOO", Value: "ZAP"},
{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: "master service in pod ns, service env vars",
ns: "test2",
enableServiceLinks: true,
container: &v1.Container{
Env: []v1.EnvVar{
{Name: "FOO", Value: "ZAP"},
@ -572,6 +622,24 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "pod in master service ns",
ns: "kubernetes",
enableServiceLinks: false,
container: &v1.Container{},
masterServiceNs: "kubernetes",
nilLister: false,
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",
ns: "kubernetes",
enableServiceLinks: true,
container: &v1.Container{},
masterServiceNs: "kubernetes",
nilLister: false,
@ -595,6 +663,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "downward api pod",
ns: "downward-api",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{
@ -667,6 +736,103 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "env expansion",
ns: "test1",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{
Name: "TEST_LITERAL",
Value: "test-test-test",
},
{
Name: "POD_NAME",
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{
APIVersion: "v1", //legacyscheme.Registry.GroupOrDie(v1.GroupName).GroupVersion.String(),
FieldPath: "metadata.name",
},
},
},
{
Name: "OUT_OF_ORDER_TEST",
Value: "$(OUT_OF_ORDER_TARGET)",
},
{
Name: "OUT_OF_ORDER_TARGET",
Value: "FOO",
},
{
Name: "EMPTY_VAR",
},
{
Name: "EMPTY_TEST",
Value: "foo-$(EMPTY_VAR)",
},
{
Name: "POD_NAME_TEST2",
Value: "test2-$(POD_NAME)",
},
{
Name: "POD_NAME_TEST3",
Value: "$(POD_NAME_TEST2)-3",
},
{
Name: "LITERAL_TEST",
Value: "literal-$(TEST_LITERAL)",
},
{
Name: "TEST_UNDEFINED",
Value: "$(UNDEFINED_VAR)",
},
},
},
masterServiceNs: "nothing",
nilLister: false,
expectedEnvs: []kubecontainer.EnvVar{
{
Name: "TEST_LITERAL",
Value: "test-test-test",
},
{
Name: "POD_NAME",
Value: "dapi-test-pod-name",
},
{
Name: "POD_NAME_TEST2",
Value: "test2-dapi-test-pod-name",
},
{
Name: "POD_NAME_TEST3",
Value: "test2-dapi-test-pod-name-3",
},
{
Name: "LITERAL_TEST",
Value: "literal-test-test-test",
},
{
Name: "OUT_OF_ORDER_TEST",
Value: "$(OUT_OF_ORDER_TARGET)",
},
{
Name: "OUT_OF_ORDER_TARGET",
Value: "FOO",
},
{
Name: "TEST_UNDEFINED",
Value: "$(UNDEFINED_VAR)",
},
{
Name: "EMPTY_VAR",
},
{
Name: "EMPTY_TEST",
Value: "foo-",
},
},
},
{
name: "env expansion, service env vars",
ns: "test1",
enableServiceLinks: true,
container: &v1.Container{
Env: []v1.EnvVar{
{
@ -798,6 +964,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "configmapkeyref_missing_optional",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{
@ -818,6 +985,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "configmapkeyref_missing_key_optional",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{
@ -848,6 +1016,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "secretkeyref_missing_optional",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{
@ -868,6 +1037,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "secretkeyref_missing_key_optional",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
Env: []v1.EnvVar{
{
@ -898,6 +1068,75 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "configmap",
ns: "test1",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{
ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test-config-map"}},
},
{
Prefix: "p_",
ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test-config-map"}},
},
},
Env: []v1.EnvVar{
{
Name: "TEST_LITERAL",
Value: "test-test-test",
},
{
Name: "EXPANSION_TEST",
Value: "$(REPLACE_ME)",
},
{
Name: "DUPE_TEST",
Value: "ENV_VAR",
},
},
},
masterServiceNs: "nothing",
nilLister: false,
configMap: &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test1",
Name: "test-configmap",
},
Data: map[string]string{
"REPLACE_ME": "FROM_CONFIG_MAP",
"DUPE_TEST": "CONFIG_MAP",
},
},
expectedEnvs: []kubecontainer.EnvVar{
{
Name: "TEST_LITERAL",
Value: "test-test-test",
},
{
Name: "REPLACE_ME",
Value: "FROM_CONFIG_MAP",
},
{
Name: "EXPANSION_TEST",
Value: "FROM_CONFIG_MAP",
},
{
Name: "DUPE_TEST",
Value: "ENV_VAR",
},
{
Name: "p_REPLACE_ME",
Value: "FROM_CONFIG_MAP",
},
{
Name: "p_DUPE_TEST",
Value: "CONFIG_MAP",
},
},
},
{
name: "configmap, service env vars",
ns: "test1",
enableServiceLinks: true,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{
@ -993,6 +1232,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "configmap_missing",
ns: "test1",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test-config-map"}}},
@ -1004,6 +1244,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "configmap_missing_optional",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{ConfigMapRef: &v1.ConfigMapEnvSource{
@ -1017,6 +1258,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "configmap_invalid_keys",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{ConfigMapRef: &v1.ConfigMapEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test-config-map"}}},
@ -1045,6 +1287,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "configmap_invalid_keys_valid",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{
@ -1073,6 +1316,75 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "secret",
ns: "test1",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{
SecretRef: &v1.SecretEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test-secret"}},
},
{
Prefix: "p_",
SecretRef: &v1.SecretEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test-secret"}},
},
},
Env: []v1.EnvVar{
{
Name: "TEST_LITERAL",
Value: "test-test-test",
},
{
Name: "EXPANSION_TEST",
Value: "$(REPLACE_ME)",
},
{
Name: "DUPE_TEST",
Value: "ENV_VAR",
},
},
},
masterServiceNs: "nothing",
nilLister: false,
secret: &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test1",
Name: "test-secret",
},
Data: map[string][]byte{
"REPLACE_ME": []byte("FROM_SECRET"),
"DUPE_TEST": []byte("SECRET"),
},
},
expectedEnvs: []kubecontainer.EnvVar{
{
Name: "TEST_LITERAL",
Value: "test-test-test",
},
{
Name: "REPLACE_ME",
Value: "FROM_SECRET",
},
{
Name: "EXPANSION_TEST",
Value: "FROM_SECRET",
},
{
Name: "DUPE_TEST",
Value: "ENV_VAR",
},
{
Name: "p_REPLACE_ME",
Value: "FROM_SECRET",
},
{
Name: "p_DUPE_TEST",
Value: "SECRET",
},
},
},
{
name: "secret, service env vars",
ns: "test1",
enableServiceLinks: true,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{
@ -1168,6 +1480,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "secret_missing",
ns: "test1",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{SecretRef: &v1.SecretEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test-secret"}}},
@ -1179,6 +1492,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "secret_missing_optional",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{SecretRef: &v1.SecretEnvSource{
@ -1192,6 +1506,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "secret_invalid_keys",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{SecretRef: &v1.SecretEnvSource{LocalObjectReference: v1.LocalObjectReference{Name: "test-secret"}}},
@ -1220,6 +1535,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
{
name: "secret_invalid_keys_valid",
ns: "test",
enableServiceLinks: false,
container: &v1.Container{
EnvFrom: []v1.EnvFromSource{
{
@ -1291,6 +1607,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
Spec: v1.PodSpec{
ServiceAccountName: "special",
NodeName: "node-name",
EnableServiceLinks: &tc.enableServiceLinks,
},
}
podIP := "1.2.3.4"

View File

@ -61,6 +61,7 @@ func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *etcdtesting.Et
func validNewPod() *api.Pod {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
return &api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
@ -84,6 +85,7 @@ func validNewPod() *api.Pod {
},
SecurityContext: &api.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
}
@ -832,6 +834,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
}
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
podIn := api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
@ -855,6 +858,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
TerminationGracePeriodSeconds: &grace,
SecurityContext: &api.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
},
}
_, _, err = storage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
@ -932,9 +936,11 @@ func TestEtcdUpdateStatus(t *testing.T) {
expected := podStart
expected.ResourceVersion = "2"
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
expected.Spec.TerminationGracePeriodSeconds = &grace
expected.Spec.RestartPolicy = api.RestartPolicyAlways
expected.Spec.DNSPolicy = api.DNSClusterFirst
expected.Spec.EnableServiceLinks = &enableServiceLinks
expected.Spec.Containers[0].ImagePullPolicy = api.PullIfNotPresent
expected.Spec.Containers[0].TerminationMessagePath = api.TerminationMessagePathDefault
expected.Spec.Containers[0].TerminationMessagePolicy = api.TerminationMessageReadFile

File diff suppressed because it is too large Load Diff

View File

@ -3126,6 +3126,11 @@ message PodSpec {
// This is an alpha feature and may change in the future.
// +optional
optional string runtimeClassName = 29;
// EnableServiceLinks indicates whether information about services should be injected into pod's
// environment variables, matching the syntax of Docker links.
// +optional
optional bool enableServiceLinks = 30;
}
// PodStatus represents information about the status of a pod. Status may trail the actual

View File

@ -2891,8 +2891,17 @@ type PodSpec struct {
// This is an alpha feature and may change in the future.
// +optional
RuntimeClassName *string `json:"runtimeClassName,omitempty" protobuf:"bytes,29,opt,name=runtimeClassName"`
// EnableServiceLinks indicates whether information about services should be injected into pod's
// environment variables, matching the syntax of Docker links.
// +optional
EnableServiceLinks *bool `json:"enableServiceLinks,omitempty" protobuf:"varint,30,opt,name=enableServiceLinks"`
}
const (
// The default value for enableServiceLinks attribute.
DefaultEnableServiceLinks = true
)
// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
// pod's hosts file.
type HostAlias struct {

View File

@ -1528,6 +1528,7 @@ var map_PodSpec = map[string]string{
"dnsConfig": "Specifies the DNS parameters of a pod. Parameters specified here will be merged to the generated DNS configuration based on DNSPolicy.",
"readinessGates": "If specified, all readiness gates will be evaluated for pod readiness. A pod is ready when all its containers are ready AND all conditions specified in the readiness gates have status equal to \"True\" More info: https://github.com/kubernetes/community/blob/master/keps/sig-network/0007-pod-ready%2B%2B.md",
"runtimeClassName": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md This is an alpha feature and may change in the future.",
"enableServiceLinks": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links.",
}
func (PodSpec) SwaggerDoc() map[string]string {

View File

@ -3554,6 +3554,11 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) {
*out = new(string)
**out = **in
}
if in.EnableServiceLinks != nil {
in, out := &in.EnableServiceLinks, &out.EnableServiceLinks
*out = new(bool)
**out = **in
}
return
}