mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Set the default for EnableServiceLinks only in Pod
This commit is contained in:
parent
b5c25728ec
commit
409a48ef91
@ -24,26 +24,22 @@ import (
|
|||||||
// DeepEqualSafePodSpec returns a PodSpec which is ready to be used with apiequality.Semantic.DeepEqual
|
// DeepEqualSafePodSpec returns a PodSpec which is ready to be used with apiequality.Semantic.DeepEqual
|
||||||
func DeepEqualSafePodSpec() api.PodSpec {
|
func DeepEqualSafePodSpec() api.PodSpec {
|
||||||
grace := int64(30)
|
grace := int64(30)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
return api.PodSpec{
|
return api.PodSpec{
|
||||||
RestartPolicy: api.RestartPolicyAlways,
|
RestartPolicy: api.RestartPolicyAlways,
|
||||||
DNSPolicy: api.DNSClusterFirst,
|
DNSPolicy: api.DNSClusterFirst,
|
||||||
TerminationGracePeriodSeconds: &grace,
|
TerminationGracePeriodSeconds: &grace,
|
||||||
SecurityContext: &api.PodSecurityContext{},
|
SecurityContext: &api.PodSecurityContext{},
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// V1DeepEqualSafePodSpec returns a PodSpec which is ready to be used with apiequality.Semantic.DeepEqual
|
// V1DeepEqualSafePodSpec returns a PodSpec which is ready to be used with apiequality.Semantic.DeepEqual
|
||||||
func V1DeepEqualSafePodSpec() v1.PodSpec {
|
func V1DeepEqualSafePodSpec() v1.PodSpec {
|
||||||
grace := int64(30)
|
grace := int64(30)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
return v1.PodSpec{
|
return v1.PodSpec{
|
||||||
RestartPolicy: v1.RestartPolicyAlways,
|
RestartPolicy: v1.RestartPolicyAlways,
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
TerminationGracePeriodSeconds: &grace,
|
TerminationGracePeriodSeconds: &grace,
|
||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
|||||||
defaultLabels := map[string]string{"foo": "bar"}
|
defaultLabels := map[string]string{"foo": "bar"}
|
||||||
maxUnavailable := intstr.FromInt(1)
|
maxUnavailable := intstr.FromInt(1)
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -47,7 +46,6 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: defaultLabels,
|
Labels: defaultLabels,
|
||||||
@ -60,7 +58,6 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -178,7 +175,6 @@ func TestSetDefaultStatefulSet(t *testing.T) {
|
|||||||
var defaultReplicas int32 = 1
|
var defaultReplicas int32 = 1
|
||||||
|
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -186,7 +182,6 @@ func TestSetDefaultStatefulSet(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: defaultLabels,
|
Labels: defaultLabels,
|
||||||
@ -291,7 +286,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
|||||||
defaultIntOrString := intstr.FromString("25%")
|
defaultIntOrString := intstr.FromString("25%")
|
||||||
differentIntOrString := intstr.FromInt(5)
|
differentIntOrString := intstr.FromInt(5)
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -299,7 +293,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
@ -38,7 +38,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
|||||||
defaultIntOrString := intstr.FromString("25%")
|
defaultIntOrString := intstr.FromString("25%")
|
||||||
differentIntOrString := intstr.FromInt(5)
|
differentIntOrString := intstr.FromInt(5)
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -46,7 +45,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
@ -39,7 +39,6 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
|||||||
defaultLabels := map[string]string{"foo": "bar"}
|
defaultLabels := map[string]string{"foo": "bar"}
|
||||||
maxUnavailable := intstr.FromInt(1)
|
maxUnavailable := intstr.FromInt(1)
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -47,7 +46,6 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: defaultLabels,
|
Labels: defaultLabels,
|
||||||
@ -60,7 +58,6 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -178,7 +175,6 @@ func TestSetDefaultStatefulSet(t *testing.T) {
|
|||||||
var defaultReplicas int32 = 1
|
var defaultReplicas int32 = 1
|
||||||
|
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -186,7 +182,6 @@ func TestSetDefaultStatefulSet(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: defaultLabels,
|
Labels: defaultLabels,
|
||||||
@ -291,7 +286,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
|||||||
defaultIntOrString := intstr.FromString("25%")
|
defaultIntOrString := intstr.FromString("25%")
|
||||||
differentIntOrString := intstr.FromInt(5)
|
differentIntOrString := intstr.FromInt(5)
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -299,7 +293,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
@ -160,8 +160,16 @@ func SetDefaults_Pod(obj *v1.Pod) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if obj.Spec.EnableServiceLinks == nil {
|
||||||
|
enableServiceLinks := v1.DefaultEnableServiceLinks
|
||||||
|
obj.Spec.EnableServiceLinks = &enableServiceLinks
|
||||||
|
}
|
||||||
}
|
}
|
||||||
func SetDefaults_PodSpec(obj *v1.PodSpec) {
|
func SetDefaults_PodSpec(obj *v1.PodSpec) {
|
||||||
|
// New fields added here will break upgrade tests:
|
||||||
|
// https://github.com/kubernetes/kubernetes/issues/69445
|
||||||
|
// In most cases the new defaulted field can added to SetDefaults_Pod instead of here, so
|
||||||
|
// that it only materializes in the Pod object and not all objects with a PodSpec field.
|
||||||
if obj.DNSPolicy == "" {
|
if obj.DNSPolicy == "" {
|
||||||
obj.DNSPolicy = v1.DNSClusterFirst
|
obj.DNSPolicy = v1.DNSClusterFirst
|
||||||
}
|
}
|
||||||
@ -182,10 +190,6 @@ func SetDefaults_PodSpec(obj *v1.PodSpec) {
|
|||||||
if obj.SchedulerName == "" {
|
if obj.SchedulerName == "" {
|
||||||
obj.SchedulerName = v1.DefaultSchedulerName
|
obj.SchedulerName = v1.DefaultSchedulerName
|
||||||
}
|
}
|
||||||
if obj.EnableServiceLinks == nil {
|
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
obj.EnableServiceLinks = &enableServiceLinks
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
func SetDefaults_Probe(obj *v1.Probe) {
|
func SetDefaults_Probe(obj *v1.Probe) {
|
||||||
if obj.TimeoutSeconds == 0 {
|
if obj.TimeoutSeconds == 0 {
|
||||||
|
@ -40,7 +40,6 @@ import (
|
|||||||
func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
||||||
defaultLabels := map[string]string{"foo": "bar"}
|
defaultLabels := map[string]string{"foo": "bar"}
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -48,7 +47,6 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: defaultLabels,
|
Labels: defaultLabels,
|
||||||
@ -61,7 +59,6 @@ func TestSetDefaultDaemonSetSpec(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -167,7 +164,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
|||||||
defaultIntOrString := intstr.FromInt(1)
|
defaultIntOrString := intstr.FromInt(1)
|
||||||
differentIntOrString := intstr.FromInt(5)
|
differentIntOrString := intstr.FromInt(5)
|
||||||
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
||||||
enableServiceLinks := v1.DefaultEnableServiceLinks
|
|
||||||
defaultTemplate := v1.PodTemplateSpec{
|
defaultTemplate := v1.PodTemplateSpec{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
@ -175,7 +171,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
|||||||
SecurityContext: &v1.PodSecurityContext{},
|
SecurityContext: &v1.PodSecurityContext{},
|
||||||
TerminationGracePeriodSeconds: &period,
|
TerminationGracePeriodSeconds: &period,
|
||||||
SchedulerName: api.DefaultSchedulerName,
|
SchedulerName: api.DefaultSchedulerName,
|
||||||
EnableServiceLinks: &enableServiceLinks,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user