use MakePodSpec consistently (#125805)
cleaning up some tests after MakePod/MakePodSpec were introduced
This commit is contained in:
		| @@ -55,8 +55,8 @@ func MakePod(name string, tweaks ...Tweak) *api.Pod { | |||||||
| 	return pod | 	return pod | ||||||
| } | } | ||||||
|  |  | ||||||
| func MakePodSpec(policy api.RestartPolicy, tweaks ...Tweak) api.PodSpec { | func MakePodSpec(tweaks ...Tweak) api.PodSpec { | ||||||
| 	return MakePod("", append([]Tweak{SetRestartPolicy(policy)}, tweaks...)...).Spec | 	return MakePod("", tweaks...).Spec | ||||||
| } | } | ||||||
|  |  | ||||||
| func SetNamespace(ns string) Tweak { | func SetNamespace(ns string) Tweak { | ||||||
|   | |||||||
| @@ -1504,14 +1504,14 @@ func TestValidateDaemonSetUpdate(t *testing.T) { | |||||||
| 	validSelector2 := map[string]string{"c": "d"} | 	validSelector2 := map[string]string{"c": "d"} | ||||||
| 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||||
|  |  | ||||||
| 	validPodSpecAbc := podtest.MakePodSpec(api.RestartPolicyAlways, | 	validPodSpecAbc := podtest.MakePodSpec( | ||||||
| 		podtest.SetContainers(podtest.MakeContainer("abc"))) | 		podtest.SetContainers(podtest.MakeContainer("abc"))) | ||||||
| 	validPodSpecDef := podtest.MakePodSpec(api.RestartPolicyAlways, | 	validPodSpecDef := podtest.MakePodSpec( | ||||||
| 		podtest.SetContainers(podtest.MakeContainer("def"))) | 		podtest.SetContainers(podtest.MakeContainer("def"))) | ||||||
| 	validPodSpecNodeSelector := podtest.MakePodSpec(api.RestartPolicyAlways, | 	validPodSpecNodeSelector := podtest.MakePodSpec( | ||||||
| 		podtest.SetNodeSelector(validSelector), | 		podtest.SetNodeSelector(validSelector), | ||||||
| 		podtest.SetNodeName("xyz")) | 		podtest.SetNodeName("xyz")) | ||||||
| 	validPodSpecVolume := podtest.MakePodSpec(api.RestartPolicyAlways, | 	validPodSpecVolume := podtest.MakePodSpec( | ||||||
| 		podtest.SetVolumes(api.Volume{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}})) | 		podtest.SetVolumes(api.Volume{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}})) | ||||||
|  |  | ||||||
| 	validPodTemplateAbc := api.PodTemplate{ | 	validPodTemplateAbc := api.PodTemplate{ | ||||||
| @@ -1558,7 +1558,7 @@ func TestValidateDaemonSetUpdate(t *testing.T) { | |||||||
| 	invalidPodTemplate := api.PodTemplate{ | 	invalidPodTemplate := api.PodTemplate{ | ||||||
| 		Template: api.PodTemplateSpec{ | 		Template: api.PodTemplateSpec{ | ||||||
| 			// no containers specified | 			// no containers specified | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, podtest.SetContainers()), | 			Spec: podtest.MakePodSpec(podtest.SetContainers()), | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| @@ -1976,7 +1976,7 @@ func TestValidateDaemonSet(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	validHostNetPodTemplate := api.PodTemplate{ | 	validHostNetPodTemplate := api.PodTemplate{ | ||||||
| @@ -1984,7 +1984,7 @@ func TestValidateDaemonSet(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetSecurityContext(&api.PodSecurityContext{ | 				podtest.SetSecurityContext(&api.PodSecurityContext{ | ||||||
| 					HostNetwork: true, | 					HostNetwork: true, | ||||||
| 				}), | 				}), | ||||||
| @@ -1999,7 +1999,7 @@ func TestValidateDaemonSet(t *testing.T) { | |||||||
| 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||||
| 	invalidPodTemplate := api.PodTemplate{ | 	invalidPodTemplate := api.PodTemplate{ | ||||||
| 		Template: api.PodTemplateSpec{ | 		Template: api.PodTemplateSpec{ | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, podtest.SetLabels(invalidSelector)), | 			Spec: podtest.MakePodSpec(podtest.SetLabels(invalidSelector)), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	successCases := []apps.DaemonSet{{ | 	successCases := []apps.DaemonSet{{ | ||||||
| @@ -2124,7 +2124,7 @@ func TestValidateDaemonSet(t *testing.T) { | |||||||
| 			Spec: apps.DaemonSetSpec{ | 			Spec: apps.DaemonSetSpec{ | ||||||
| 				Selector: &metav1.LabelSelector{MatchLabels: validSelector}, | 				Selector: &metav1.LabelSelector{MatchLabels: validSelector}, | ||||||
| 				Template: api.PodTemplateSpec{ | 				Template: api.PodTemplateSpec{ | ||||||
| 					Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure, podtest.SetLabels(validSelector)), | 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure), podtest.SetLabels(validSelector)), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| @@ -2136,7 +2136,7 @@ func TestValidateDaemonSet(t *testing.T) { | |||||||
| 			Spec: apps.DaemonSetSpec{ | 			Spec: apps.DaemonSetSpec{ | ||||||
| 				Selector: &metav1.LabelSelector{MatchLabels: validSelector}, | 				Selector: &metav1.LabelSelector{MatchLabels: validSelector}, | ||||||
| 				Template: api.PodTemplateSpec{ | 				Template: api.PodTemplateSpec{ | ||||||
| 					Spec: podtest.MakePodSpec(api.RestartPolicyNever, podtest.SetLabels(validSelector)), | 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyNever), podtest.SetLabels(validSelector)), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| @@ -2148,7 +2148,7 @@ func TestValidateDaemonSet(t *testing.T) { | |||||||
| 					ObjectMeta: metav1.ObjectMeta{ | 					ObjectMeta: metav1.ObjectMeta{ | ||||||
| 						Labels: validSelector, | 						Labels: validSelector, | ||||||
| 					}, | 					}, | ||||||
| 					Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | 					Spec: podtest.MakePodSpec( | ||||||
| 						podtest.SetEphemeralContainers(api.EphemeralContainer{EphemeralContainerCommon: api.EphemeralContainerCommon{Name: "debug", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}})), | 						podtest.SetEphemeralContainers(api.EphemeralContainer{EphemeralContainerCommon: api.EphemeralContainerCommon{Name: "debug", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}})), | ||||||
| 				}, | 				}, | ||||||
| 				UpdateStrategy: apps.DaemonSetUpdateStrategy{ | 				UpdateStrategy: apps.DaemonSetUpdateStrategy{ | ||||||
| @@ -2207,7 +2207,7 @@ func validDeployment(tweaks ...func(d *apps.Deployment)) *apps.Deployment { | |||||||
| 						"name": "abc", | 						"name": "abc", | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 				Spec: podtest.MakePodSpec(), | ||||||
| 			}, | 			}, | ||||||
| 			RollbackTo: &apps.RollbackConfig{ | 			RollbackTo: &apps.RollbackConfig{ | ||||||
| 				Revision: 1, | 				Revision: 1, | ||||||
| @@ -2538,7 +2538,7 @@ func TestValidateDeploymentUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validLabels, | 				Labels: validLabels, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	readWriteVolumePodTemplate := api.PodTemplate{ | 	readWriteVolumePodTemplate := api.PodTemplate{ | ||||||
| @@ -2546,7 +2546,7 @@ func TestValidateDeploymentUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validLabels, | 				Labels: validLabels, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetVolumes(api.Volume{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | 				podtest.SetVolumes(api.Volume{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | ||||||
| 			), | 			), | ||||||
| 		}, | 		}, | ||||||
| @@ -2555,7 +2555,7 @@ func TestValidateDeploymentUpdate(t *testing.T) { | |||||||
| 	invalidPodTemplate := api.PodTemplate{ | 	invalidPodTemplate := api.PodTemplate{ | ||||||
| 		Template: api.PodTemplateSpec{ | 		Template: api.PodTemplateSpec{ | ||||||
| 			// no containers specified | 			// no containers specified | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, podtest.SetContainers()), | 			Spec: podtest.MakePodSpec(podtest.SetContainers()), | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: invalidLabels, | 				Labels: invalidLabels, | ||||||
| 			}, | 			}, | ||||||
| @@ -2852,7 +2852,7 @@ func TestValidateReplicaSetStatusUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validLabels, | 				Labels: validLabels, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	type rcUpdateTest struct { | 	type rcUpdateTest struct { | ||||||
| @@ -2930,7 +2930,7 @@ func TestValidateReplicaSetUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validLabels, | 				Labels: validLabels, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	readWriteVolumePodTemplate := api.PodTemplate{ | 	readWriteVolumePodTemplate := api.PodTemplate{ | ||||||
| @@ -2938,7 +2938,7 @@ func TestValidateReplicaSetUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validLabels, | 				Labels: validLabels, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetVolumes(api.Volume{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | 				podtest.SetVolumes(api.Volume{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | ||||||
| 			), | 			), | ||||||
| 		}, | 		}, | ||||||
| @@ -2946,7 +2946,7 @@ func TestValidateReplicaSetUpdate(t *testing.T) { | |||||||
| 	invalidLabels := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | 	invalidLabels := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||||
| 	invalidPodTemplate := api.PodTemplate{ | 	invalidPodTemplate := api.PodTemplate{ | ||||||
| 		Template: api.PodTemplateSpec{ | 		Template: api.PodTemplateSpec{ | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, podtest.SetContainers()), | 			Spec: podtest.MakePodSpec(podtest.SetContainers()), | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: invalidLabels, | 				Labels: invalidLabels, | ||||||
| 			}, | 			}, | ||||||
| @@ -3096,7 +3096,7 @@ func TestValidateReplicaSet(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validLabels, | 				Labels: validLabels, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	validHostNetPodTemplate := api.PodTemplate{ | 	validHostNetPodTemplate := api.PodTemplate{ | ||||||
| @@ -3104,7 +3104,7 @@ func TestValidateReplicaSet(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validLabels, | 				Labels: validLabels, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetSecurityContext(&api.PodSecurityContext{ | 				podtest.SetSecurityContext(&api.PodSecurityContext{ | ||||||
| 					HostNetwork: true, | 					HostNetwork: true, | ||||||
| 				}), | 				}), | ||||||
| @@ -3120,7 +3120,7 @@ func TestValidateReplicaSet(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validLabels, | 				Labels: validLabels, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetVolumes(api.Volume{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | 				podtest.SetVolumes(api.Volume{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | ||||||
| 			), | 			), | ||||||
| 		}, | 		}, | ||||||
| @@ -3128,7 +3128,7 @@ func TestValidateReplicaSet(t *testing.T) { | |||||||
| 	invalidLabels := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | 	invalidLabels := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||||
| 	invalidPodTemplate := api.PodTemplate{ | 	invalidPodTemplate := api.PodTemplate{ | ||||||
| 		Template: api.PodTemplateSpec{ | 		Template: api.PodTemplateSpec{ | ||||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 			Spec: podtest.MakePodSpec(), | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: invalidLabels, | 				Labels: invalidLabels, | ||||||
| 			}, | 			}, | ||||||
| @@ -3262,7 +3262,7 @@ func TestValidateReplicaSet(t *testing.T) { | |||||||
| 			Spec: apps.ReplicaSetSpec{ | 			Spec: apps.ReplicaSetSpec{ | ||||||
| 				Selector: &metav1.LabelSelector{MatchLabels: validLabels}, | 				Selector: &metav1.LabelSelector{MatchLabels: validLabels}, | ||||||
| 				Template: api.PodTemplateSpec{ | 				Template: api.PodTemplateSpec{ | ||||||
| 					Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					ObjectMeta: metav1.ObjectMeta{ | 					ObjectMeta: metav1.ObjectMeta{ | ||||||
| 						Labels: validLabels, | 						Labels: validLabels, | ||||||
| 					}, | 					}, | ||||||
| @@ -3277,7 +3277,7 @@ func TestValidateReplicaSet(t *testing.T) { | |||||||
| 			Spec: apps.ReplicaSetSpec{ | 			Spec: apps.ReplicaSetSpec{ | ||||||
| 				Selector: &metav1.LabelSelector{MatchLabels: validLabels}, | 				Selector: &metav1.LabelSelector{MatchLabels: validLabels}, | ||||||
| 				Template: api.PodTemplateSpec{ | 				Template: api.PodTemplateSpec{ | ||||||
| 					Spec: podtest.MakePodSpec(api.RestartPolicyNever), | 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyNever)), | ||||||
| 					ObjectMeta: metav1.ObjectMeta{ | 					ObjectMeta: metav1.ObjectMeta{ | ||||||
| 						Labels: validLabels, | 						Labels: validLabels, | ||||||
| 					}, | 					}, | ||||||
|   | |||||||
| @@ -62,7 +62,7 @@ func getValidPodTemplateSpecForManual(selector *metav1.LabelSelector) api.PodTem | |||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			Labels: selector.MatchLabels, | 			Labels: selector.MatchLabels, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -77,7 +77,7 @@ func getValidPodTemplateSpecForGenerated(selector *metav1.LabelSelector) api.Pod | |||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			Labels: selector.MatchLabels, | 			Labels: selector.MatchLabels, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure, | 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure), | ||||||
| 			podtest.SetInitContainers(podtest.MakeContainer("def"))), | 			podtest.SetInitContainers(podtest.MakeContainer("def"))), | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @@ -388,7 +388,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: map[string]string{batch.LegacyControllerUidLabel: "1a2b3c", batch.LegacyJobNameLabel: "myjob"}, | 							Labels: map[string]string{batch.LegacyControllerUidLabel: "1a2b3c", batch.LegacyJobNameLabel: "myjob"}, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1021,7 +1021,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: validGeneratedSelector.MatchLabels, | 							Labels: validGeneratedSelector.MatchLabels, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 					PodFailurePolicy: &batch.PodFailurePolicy{ | 					PodFailurePolicy: &batch.PodFailurePolicy{ | ||||||
| 						Rules: []batch.PodFailurePolicyRule{}, | 						Rules: []batch.PodFailurePolicyRule{}, | ||||||
| @@ -1235,7 +1235,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: map[string]string{"y": "z"}, | 							Labels: map[string]string{"y": "z"}, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1255,7 +1255,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: map[string]string{"controller-uid": "4d5e6f"}, | 							Labels: map[string]string{"controller-uid": "4d5e6f"}, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1275,7 +1275,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: validManualSelector.MatchLabels, | 							Labels: validManualSelector.MatchLabels, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 						Spec: podtest.MakePodSpec(), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1295,7 +1295,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: validManualSelector.MatchLabels, | 							Labels: validManualSelector.MatchLabels, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec("Invalid"), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy("Invalid")), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1363,7 +1363,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: map[string]string{batch.LegacyJobNameLabel: "myjob"}, | 							Labels: map[string]string{batch.LegacyJobNameLabel: "myjob"}, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1383,7 +1383,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: map[string]string{batch.LegacyJobNameLabel: "myjob"}, | 							Labels: map[string]string{batch.LegacyJobNameLabel: "myjob"}, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1420,7 +1420,7 @@ func TestValidateJob(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: map[string]string{batch.JobNameLabel: "myjob", batch.LegacyControllerUidLabel: "1a2b3c", batch.LegacyJobNameLabel: "myjob"}, | 							Labels: map[string]string{batch.JobNameLabel: "myjob", batch.LegacyControllerUidLabel: "1a2b3c", batch.LegacyJobNameLabel: "myjob"}, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -2835,7 +2835,7 @@ func TestValidateCronJob(t *testing.T) { | |||||||
| 				JobTemplate: batch.JobTemplateSpec{ | 				JobTemplate: batch.JobTemplateSpec{ | ||||||
| 					Spec: batch.JobSpec{ | 					Spec: batch.JobSpec{ | ||||||
| 						Template: api.PodTemplateSpec{ | 						Template: api.PodTemplateSpec{ | ||||||
| 							Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | 							Spec: podtest.MakePodSpec(), | ||||||
| 						}, | 						}, | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| @@ -2853,7 +2853,7 @@ func TestValidateCronJob(t *testing.T) { | |||||||
| 				JobTemplate: batch.JobTemplateSpec{ | 				JobTemplate: batch.JobTemplateSpec{ | ||||||
| 					Spec: batch.JobSpec{ | 					Spec: batch.JobSpec{ | ||||||
| 						Template: api.PodTemplateSpec{ | 						Template: api.PodTemplateSpec{ | ||||||
| 							Spec: podtest.MakePodSpec("Invalid"), | 							Spec: podtest.MakePodSpec(podtest.SetRestartPolicy("Invalid")), | ||||||
| 						}, | 						}, | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
|   | |||||||
| @@ -3142,6 +3142,9 @@ func handlerFromLifecycle(lh *core.LifecycleHandler) commonHandler { | |||||||
|  |  | ||||||
| func validateSleepAction(sleep *core.SleepAction, gracePeriod *int64, fldPath *field.Path) field.ErrorList { | func validateSleepAction(sleep *core.SleepAction, gracePeriod *int64, fldPath *field.Path) field.ErrorList { | ||||||
| 	allErrors := field.ErrorList{} | 	allErrors := field.ErrorList{} | ||||||
|  | 	// We allow gracePeriod to be nil here because the pod in which this SleepAction | ||||||
|  | 	// is defined might have an invalid grace period defined, and we don't want to | ||||||
|  | 	// flag another error here when the real problem will already be flagged. | ||||||
| 	if gracePeriod != nil && sleep.Seconds <= 0 || sleep.Seconds > *gracePeriod { | 	if gracePeriod != nil && sleep.Seconds <= 0 || sleep.Seconds > *gracePeriod { | ||||||
| 		invalidStr := fmt.Sprintf("must be greater than 0 and less than terminationGracePeriodSeconds (%d)", *gracePeriod) | 		invalidStr := fmt.Sprintf("must be greater than 0 and less than terminationGracePeriodSeconds (%d)", *gracePeriod) | ||||||
| 		allErrors = append(allErrors, field.Invalid(fldPath, sleep.Seconds, invalidStr)) | 		allErrors = append(allErrors, field.Invalid(fldPath, sleep.Seconds, invalidStr)) | ||||||
|   | |||||||
| @@ -9907,9 +9907,9 @@ func TestValidatePodSpec(t *testing.T) { | |||||||
| 	badfsGroupChangePolicy1 := core.PodFSGroupChangePolicy("invalid") | 	badfsGroupChangePolicy1 := core.PodFSGroupChangePolicy("invalid") | ||||||
| 	badfsGroupChangePolicy2 := core.PodFSGroupChangePolicy("") | 	badfsGroupChangePolicy2 := core.PodFSGroupChangePolicy("") | ||||||
|  |  | ||||||
| 	successCases := map[string]core.Pod{ | 	successCases := map[string]*core.Pod{ | ||||||
| 		"populate basic fields, leave defaults for most": *podtest.MakePod(""), | 		"populate basic fields, leave defaults for most": podtest.MakePod(""), | ||||||
| 		"populate all fields": *podtest.MakePod("", | 		"populate all fields": podtest.MakePod("", | ||||||
| 			podtest.SetInitContainers(podtest.MakeContainer("ictr")), | 			podtest.SetInitContainers(podtest.MakeContainer("ictr")), | ||||||
| 			podtest.SetVolumes(podtest.MakeEmptyVolume(("vol"))), | 			podtest.SetVolumes(podtest.MakeEmptyVolume(("vol"))), | ||||||
| 			podtest.SetNodeSelector(map[string]string{ | 			podtest.SetNodeSelector(map[string]string{ | ||||||
| @@ -9919,36 +9919,36 @@ func TestValidatePodSpec(t *testing.T) { | |||||||
| 			podtest.SetActiveDeadlineSeconds(activeDeadlineSecondsMax), | 			podtest.SetActiveDeadlineSeconds(activeDeadlineSecondsMax), | ||||||
| 			podtest.SetServiceAccountName("acct"), | 			podtest.SetServiceAccountName("acct"), | ||||||
| 		), | 		), | ||||||
| 		"populate HostNetwork": *podtest.MakePod("", | 		"populate HostNetwork": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", | 			podtest.SetContainers(podtest.MakeContainer("ctr", | ||||||
| 				podtest.SetContainerPorts(core.ContainerPort{HostPort: 8080, ContainerPort: 8080, Protocol: "TCP"}))), | 				podtest.SetContainerPorts(core.ContainerPort{HostPort: 8080, ContainerPort: 8080, Protocol: "TCP"}))), | ||||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{HostNetwork: true}), | 			podtest.SetSecurityContext(&core.PodSecurityContext{HostNetwork: true}), | ||||||
| 		), | 		), | ||||||
| 		"populate RunAsUser SupplementalGroups FSGroup with minID 0": *podtest.MakePod("", | 		"populate RunAsUser SupplementalGroups FSGroup with minID 0": podtest.MakePod("", | ||||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 				SupplementalGroups: []int64{minGroupID}, | 				SupplementalGroups: []int64{minGroupID}, | ||||||
| 				RunAsUser:          &minUserID, | 				RunAsUser:          &minUserID, | ||||||
| 				FSGroup:            &minGroupID, | 				FSGroup:            &minGroupID, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"populate RunAsUser SupplementalGroups FSGroup with maxID 2147483647": *podtest.MakePod("", | 		"populate RunAsUser SupplementalGroups FSGroup with maxID 2147483647": podtest.MakePod("", | ||||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 				SupplementalGroups: []int64{maxGroupID}, | 				SupplementalGroups: []int64{maxGroupID}, | ||||||
| 				RunAsUser:          &maxUserID, | 				RunAsUser:          &maxUserID, | ||||||
| 				FSGroup:            &maxGroupID, | 				FSGroup:            &maxGroupID, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"populate HostIPC": *podtest.MakePod("", | 		"populate HostIPC": podtest.MakePod("", | ||||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 				HostIPC: true, | 				HostIPC: true, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"populate HostPID": *podtest.MakePod("", | 		"populate HostPID": podtest.MakePod("", | ||||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 				HostPID: true, | 				HostPID: true, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"populate Affinity": *podtest.MakePod("", | 		"populate Affinity": podtest.MakePod("", | ||||||
| 			podtest.SetAffinity(&core.Affinity{ | 			podtest.SetAffinity(&core.Affinity{ | ||||||
| 				NodeAffinity: &core.NodeAffinity{ | 				NodeAffinity: &core.NodeAffinity{ | ||||||
| 					RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{ | 					RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{ | ||||||
| @@ -9978,38 +9978,38 @@ func TestValidatePodSpec(t *testing.T) { | |||||||
| 				}, | 				}, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"populate HostAliases": *podtest.MakePod("", | 		"populate HostAliases": podtest.MakePod("", | ||||||
| 			podtest.SetHostAliases(core.HostAlias{IP: "12.34.56.78", Hostnames: []string{"host1", "host2"}}), | 			podtest.SetHostAliases(core.HostAlias{IP: "12.34.56.78", Hostnames: []string{"host1", "host2"}}), | ||||||
| 		), | 		), | ||||||
| 		"populate HostAliases with `foo.bar` hostnames": *podtest.MakePod("", | 		"populate HostAliases with `foo.bar` hostnames": podtest.MakePod("", | ||||||
| 			podtest.SetHostAliases(core.HostAlias{IP: "12.34.56.78", Hostnames: []string{"host1.foo", "host2.bar"}}), | 			podtest.SetHostAliases(core.HostAlias{IP: "12.34.56.78", Hostnames: []string{"host1.foo", "host2.bar"}}), | ||||||
| 		), | 		), | ||||||
| 		"populate HostAliases with HostNetwork": *podtest.MakePod("", | 		"populate HostAliases with HostNetwork": podtest.MakePod("", | ||||||
| 			podtest.SetHostAliases(core.HostAlias{IP: "12.34.56.78", Hostnames: []string{"host1.foo", "host2.bar"}}), | 			podtest.SetHostAliases(core.HostAlias{IP: "12.34.56.78", Hostnames: []string{"host1.foo", "host2.bar"}}), | ||||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 				HostNetwork: true, | 				HostNetwork: true, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"populate PriorityClassName": *podtest.MakePod("", | 		"populate PriorityClassName": podtest.MakePod("", | ||||||
| 			podtest.SetPriorityClassName("valid-name"), | 			podtest.SetPriorityClassName("valid-name"), | ||||||
| 		), | 		), | ||||||
| 		"populate ShareProcessNamespace": *podtest.MakePod("", | 		"populate ShareProcessNamespace": podtest.MakePod("", | ||||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 				ShareProcessNamespace: &[]bool{true}[0], | 				ShareProcessNamespace: &[]bool{true}[0], | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"populate RuntimeClassName": *podtest.MakePod("", | 		"populate RuntimeClassName": podtest.MakePod("", | ||||||
| 			podtest.SetRuntimeClassName("valid-sandbox"), | 			podtest.SetRuntimeClassName("valid-sandbox"), | ||||||
| 		), | 		), | ||||||
| 		"populate Overhead": *podtest.MakePod("", | 		"populate Overhead": podtest.MakePod("", | ||||||
| 			podtest.SetOverhead(core.ResourceList{}), | 			podtest.SetOverhead(core.ResourceList{}), | ||||||
| 		), | 		), | ||||||
| 		"populate FSGroupChangePolicy": *podtest.MakePod("", | 		"populate FSGroupChangePolicy": podtest.MakePod("", | ||||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 				FSGroupChangePolicy: &goodfsGroupChangePolicy, | 				FSGroupChangePolicy: &goodfsGroupChangePolicy, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"resources resize policy for containers": *podtest.MakePod("", | 		"resources resize policy for containers": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResizePolicy( | 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResizePolicy( | ||||||
| 				core.ContainerResizePolicy{ResourceName: "cpu", RestartPolicy: "NotRequired"}), | 				core.ContainerResizePolicy{ResourceName: "cpu", RestartPolicy: "NotRequired"}), | ||||||
| 			)), | 			)), | ||||||
| @@ -16257,7 +16257,7 @@ func TestValidateReplicationControllerUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("").Spec, | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	readWriteVolumePodTemplate := core.PodTemplate{ | 	readWriteVolumePodTemplate := core.PodTemplate{ | ||||||
| @@ -16265,9 +16265,9 @@ func TestValidateReplicationControllerUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("", | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetVolumes(core.Volume{Name: "gcepd", VolumeSource: core.VolumeSource{GCEPersistentDisk: &core.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | 				podtest.SetVolumes(core.Volume{Name: "gcepd", VolumeSource: core.VolumeSource{GCEPersistentDisk: &core.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | ||||||
| 			).Spec, | 			), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||||
| @@ -16276,7 +16276,7 @@ func TestValidateReplicationControllerUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: invalidSelector, | 				Labels: invalidSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("").Spec, | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	type rcUpdateTest struct { | 	type rcUpdateTest struct { | ||||||
| @@ -16408,7 +16408,7 @@ func TestValidateReplicationController(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("").Spec, | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	readWriteVolumePodTemplate := core.PodTemplate{ | 	readWriteVolumePodTemplate := core.PodTemplate{ | ||||||
| @@ -16416,9 +16416,9 @@ func TestValidateReplicationController(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("", | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetVolumes(core.Volume{Name: "gcepd", VolumeSource: core.VolumeSource{GCEPersistentDisk: &core.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | 				podtest.SetVolumes(core.Volume{Name: "gcepd", VolumeSource: core.VolumeSource{GCEPersistentDisk: &core.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}), | ||||||
| 			).Spec, | 			), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	hostnetPodTemplate := core.PodTemplate{ | 	hostnetPodTemplate := core.PodTemplate{ | ||||||
| @@ -16426,7 +16426,7 @@ func TestValidateReplicationController(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("", | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetSecurityContext(&core.PodSecurityContext{ | 				podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 					HostNetwork: true, | 					HostNetwork: true, | ||||||
| 				}), | 				}), | ||||||
| @@ -16435,13 +16435,13 @@ func TestValidateReplicationController(t *testing.T) { | |||||||
| 						ContainerPort: 12345, | 						ContainerPort: 12345, | ||||||
| 						Protocol:      core.ProtocolTCP, | 						Protocol:      core.ProtocolTCP, | ||||||
| 					}))), | 					}))), | ||||||
| 			).Spec, | 			), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||||
| 	invalidPodTemplate := core.PodTemplate{ | 	invalidPodTemplate := core.PodTemplate{ | ||||||
| 		Template: core.PodTemplateSpec{ | 		Template: core.PodTemplateSpec{ | ||||||
| 			Spec: podtest.MakePod("").Spec, | 			Spec: podtest.MakePodSpec(), | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: invalidSelector, | 				Labels: invalidSelector, | ||||||
| 			}, | 			}, | ||||||
| @@ -16575,9 +16575,7 @@ func TestValidateReplicationController(t *testing.T) { | |||||||
| 			Spec: core.ReplicationControllerSpec{ | 			Spec: core.ReplicationControllerSpec{ | ||||||
| 				Selector: validSelector, | 				Selector: validSelector, | ||||||
| 				Template: &core.PodTemplateSpec{ | 				Template: &core.PodTemplateSpec{ | ||||||
| 					Spec: podtest.MakePod("", | 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(core.RestartPolicyOnFailure)), | ||||||
| 						podtest.SetRestartPolicy(core.RestartPolicyOnFailure), |  | ||||||
| 					).Spec, |  | ||||||
| 					ObjectMeta: metav1.ObjectMeta{ | 					ObjectMeta: metav1.ObjectMeta{ | ||||||
| 						Labels: validSelector, | 						Labels: validSelector, | ||||||
| 					}, | 					}, | ||||||
| @@ -16592,9 +16590,7 @@ func TestValidateReplicationController(t *testing.T) { | |||||||
| 			Spec: core.ReplicationControllerSpec{ | 			Spec: core.ReplicationControllerSpec{ | ||||||
| 				Selector: validSelector, | 				Selector: validSelector, | ||||||
| 				Template: &core.PodTemplateSpec{ | 				Template: &core.PodTemplateSpec{ | ||||||
| 					Spec: podtest.MakePod("", | 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(core.RestartPolicyNever)), | ||||||
| 						podtest.SetRestartPolicy(core.RestartPolicyNever), |  | ||||||
| 					).Spec, |  | ||||||
| 					ObjectMeta: metav1.ObjectMeta{ | 					ObjectMeta: metav1.ObjectMeta{ | ||||||
| 						Labels: validSelector, | 						Labels: validSelector, | ||||||
| 					}, | 					}, | ||||||
| @@ -16610,9 +16606,9 @@ func TestValidateReplicationController(t *testing.T) { | |||||||
| 					ObjectMeta: metav1.ObjectMeta{ | 					ObjectMeta: metav1.ObjectMeta{ | ||||||
| 						Labels: validSelector, | 						Labels: validSelector, | ||||||
| 					}, | 					}, | ||||||
| 					Spec: podtest.MakePod("", | 					Spec: podtest.MakePodSpec( | ||||||
| 						podtest.SetEphemeralContainers(core.EphemeralContainer{EphemeralContainerCommon: core.EphemeralContainerCommon{Name: "debug", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}}), | 						podtest.SetEphemeralContainers(core.EphemeralContainer{EphemeralContainerCommon: core.EphemeralContainerCommon{Name: "debug", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}}), | ||||||
| 					).Spec, | 					), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| @@ -22855,7 +22851,7 @@ func TestValidatePodTemplateSpecSeccomp(t *testing.T) { | |||||||
| 					"container.seccomp.security.alpha.kubernetes.io/test2": "unconfined", | 					"container.seccomp.security.alpha.kubernetes.io/test2": "unconfined", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("", | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetContainers( | 				podtest.SetContainers( | ||||||
| 					podtest.MakeContainer("test1"), | 					podtest.MakeContainer("test1"), | ||||||
| 					podtest.MakeContainer("test2", | 					podtest.MakeContainer("test2", | ||||||
| @@ -22864,7 +22860,7 @@ func TestValidatePodTemplateSpecSeccomp(t *testing.T) { | |||||||
| 								Type: core.SeccompProfileTypeRuntimeDefault, | 								Type: core.SeccompProfileTypeRuntimeDefault, | ||||||
| 							}, | 							}, | ||||||
| 						}))), | 						}))), | ||||||
| 			).Spec, | 			), | ||||||
| 		}, | 		}, | ||||||
| 	}, { | 	}, { | ||||||
| 		description: "seccomp field and pod annotation must match", | 		description: "seccomp field and pod annotation must match", | ||||||
| @@ -22880,13 +22876,13 @@ func TestValidatePodTemplateSpecSeccomp(t *testing.T) { | |||||||
| 					"seccomp.security.alpha.kubernetes.io/pod": "runtime/default", | 					"seccomp.security.alpha.kubernetes.io/pod": "runtime/default", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("", | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetSecurityContext(&core.PodSecurityContext{ | 				podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||||
| 					SeccompProfile: &core.SeccompProfile{ | 					SeccompProfile: &core.SeccompProfile{ | ||||||
| 						Type: core.SeccompProfileTypeUnconfined, | 						Type: core.SeccompProfileTypeUnconfined, | ||||||
| 					}, | 					}, | ||||||
| 				}), | 				}), | ||||||
| 			).Spec, | 			), | ||||||
| 		}, | 		}, | ||||||
| 	}, { | 	}, { | ||||||
| 		description: "init seccomp field and container annotation must match", | 		description: "init seccomp field and container annotation must match", | ||||||
| @@ -22902,14 +22898,14 @@ func TestValidatePodTemplateSpecSeccomp(t *testing.T) { | |||||||
| 					"container.seccomp.security.alpha.kubernetes.io/init-test": "unconfined", | 					"container.seccomp.security.alpha.kubernetes.io/init-test": "unconfined", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("", | 			Spec: podtest.MakePodSpec( | ||||||
| 				podtest.SetInitContainers(podtest.MakeContainer("init-test", | 				podtest.SetInitContainers(podtest.MakeContainer("init-test", | ||||||
| 					podtest.SetContainerSecurityContext(core.SecurityContext{ | 					podtest.SetContainerSecurityContext(core.SecurityContext{ | ||||||
| 						SeccompProfile: &core.SeccompProfile{ | 						SeccompProfile: &core.SeccompProfile{ | ||||||
| 							Type: core.SeccompProfileTypeRuntimeDefault, | 							Type: core.SeccompProfileTypeRuntimeDefault, | ||||||
| 						}, | 						}, | ||||||
| 					}))), | 					}))), | ||||||
| 			).Spec, | 			), | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	} | 	} | ||||||
| @@ -23724,7 +23720,7 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | |||||||
| 	shortPodName := &metav1.ObjectMeta{ | 	shortPodName := &metav1.ObjectMeta{ | ||||||
| 		Name: "some-pod", | 		Name: "some-pod", | ||||||
| 	} | 	} | ||||||
| 	goodClaimTemplate := *podtest.MakePod("", | 	goodClaimTemplate := podtest.MakePod("", | ||||||
| 		podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim-template"}}}))), | 		podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim-template"}}}))), | ||||||
| 		podtest.SetRestartPolicy(core.RestartPolicyAlways), | 		podtest.SetRestartPolicy(core.RestartPolicyAlways), | ||||||
| 		podtest.SetResourceClaims(core.PodResourceClaim{ | 		podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| @@ -23732,7 +23728,7 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | |||||||
| 			ResourceClaimTemplateName: &externalClaimTemplateName, | 			ResourceClaimTemplateName: &externalClaimTemplateName, | ||||||
| 		}), | 		}), | ||||||
| 	) | 	) | ||||||
| 	goodClaimReference := *podtest.MakePod("", | 	goodClaimReference := podtest.MakePod("", | ||||||
| 		podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim-reference"}}}))), | 		podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim-reference"}}}))), | ||||||
| 		podtest.SetRestartPolicy(core.RestartPolicyAlways), | 		podtest.SetRestartPolicy(core.RestartPolicyAlways), | ||||||
| 		podtest.SetResourceClaims(core.PodResourceClaim{ | 		podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| @@ -23741,10 +23737,10 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | |||||||
| 		}), | 		}), | ||||||
| 	) | 	) | ||||||
|  |  | ||||||
| 	successCases := map[string]core.Pod{ | 	successCases := map[string]*core.Pod{ | ||||||
| 		"resource claim reference": goodClaimReference, | 		"resource claim reference": goodClaimReference, | ||||||
| 		"resource claim template":  goodClaimTemplate, | 		"resource claim template":  goodClaimTemplate, | ||||||
| 		"multiple claims": *podtest.MakePod("", | 		"multiple claims": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}, {Name: "another-claim"}}}))), | 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}, {Name: "another-claim"}}}))), | ||||||
| 			podtest.SetResourceClaims( | 			podtest.SetResourceClaims( | ||||||
| 				core.PodResourceClaim{ | 				core.PodResourceClaim{ | ||||||
| @@ -23756,7 +23752,7 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | |||||||
| 					ResourceClaimName: &externalClaimName, | 					ResourceClaimName: &externalClaimName, | ||||||
| 				}), | 				}), | ||||||
| 		), | 		), | ||||||
| 		"init container": *podtest.MakePod("", | 		"init container": podtest.MakePod("", | ||||||
| 			podtest.SetInitContainers(podtest.MakeContainer("ctr-init", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}))), | 			podtest.SetInitContainers(podtest.MakeContainer("ctr-init", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}))), | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:              "my-claim", | 				Name:              "my-claim", | ||||||
| @@ -23772,26 +23768,26 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | |||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	failureCases := map[string]core.Pod{ | 	failureCases := map[string]*core.Pod{ | ||||||
| 		"pod claim name with prefix": *podtest.MakePod("", | 		"pod claim name with prefix": podtest.MakePod("", | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:              "../my-claim", | 				Name:              "../my-claim", | ||||||
| 				ResourceClaimName: &externalClaimName, | 				ResourceClaimName: &externalClaimName, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"pod claim name with path": *podtest.MakePod("", | 		"pod claim name with path": podtest.MakePod("", | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:              "my/claim", | 				Name:              "my/claim", | ||||||
| 				ResourceClaimName: &externalClaimName, | 				ResourceClaimName: &externalClaimName, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"pod claim name empty": *podtest.MakePod("", | 		"pod claim name empty": podtest.MakePod("", | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:              "", | 				Name:              "", | ||||||
| 				ResourceClaimName: &externalClaimName, | 				ResourceClaimName: &externalClaimName, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"duplicate pod claim entries": *podtest.MakePod("", | 		"duplicate pod claim entries": podtest.MakePod("", | ||||||
| 			podtest.SetResourceClaims( | 			podtest.SetResourceClaims( | ||||||
| 				core.PodResourceClaim{ | 				core.PodResourceClaim{ | ||||||
| 					Name:              "my-claim", | 					Name:              "my-claim", | ||||||
| @@ -23802,12 +23798,12 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | |||||||
| 					ResourceClaimName: &externalClaimName, | 					ResourceClaimName: &externalClaimName, | ||||||
| 				}), | 				}), | ||||||
| 		), | 		), | ||||||
| 		"resource claim source empty": *podtest.MakePod("", | 		"resource claim source empty": podtest.MakePod("", | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name: "my-claim", | 				Name: "my-claim", | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"resource claim reference and template": *podtest.MakePod("", | 		"resource claim reference and template": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}))), | 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}))), | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:                      "my-claim", | 				Name:                      "my-claim", | ||||||
| @@ -23815,32 +23811,32 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | |||||||
| 				ResourceClaimTemplateName: &externalClaimTemplateName, | 				ResourceClaimTemplateName: &externalClaimTemplateName, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"claim not found": *podtest.MakePod("", | 		"claim not found": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "no-such-claim"}}}))), | 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "no-such-claim"}}}))), | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:              "my-claim", | 				Name:              "my-claim", | ||||||
| 				ResourceClaimName: &externalClaimName, | 				ResourceClaimName: &externalClaimName, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"claim name empty": *podtest.MakePod("", | 		"claim name empty": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: ""}}}))), | 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: ""}}}))), | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:              "my-claim", | 				Name:              "my-claim", | ||||||
| 				ResourceClaimName: &externalClaimName, | 				ResourceClaimName: &externalClaimName, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"pod claim name duplicates": *podtest.MakePod("", | 		"pod claim name duplicates": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}, {Name: "my-claim"}}}))), | 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}, {Name: "my-claim"}}}))), | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:              "my-claim", | 				Name:              "my-claim", | ||||||
| 				ResourceClaimName: &externalClaimName, | 				ResourceClaimName: &externalClaimName, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"no claims defined": *podtest.MakePod("", | 		"no claims defined": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}))), | 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}))), | ||||||
| 			podtest.SetRestartPolicy(core.RestartPolicyAlways), | 			podtest.SetRestartPolicy(core.RestartPolicyAlways), | ||||||
| 		), | 		), | ||||||
| 		"duplicate pod claim name": *podtest.MakePod("", | 		"duplicate pod claim name": podtest.MakePod("", | ||||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}))), | 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources(core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}))), | ||||||
| 			podtest.SetRestartPolicy(core.RestartPolicyAlways), | 			podtest.SetRestartPolicy(core.RestartPolicyAlways), | ||||||
| 			podtest.SetResourceClaims( | 			podtest.SetResourceClaims( | ||||||
| @@ -23853,24 +23849,24 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | |||||||
| 					ResourceClaimName: &externalClaimName, | 					ResourceClaimName: &externalClaimName, | ||||||
| 				}), | 				}), | ||||||
| 		), | 		), | ||||||
| 		"ephemeral container don't support resource requirements": *podtest.MakePod("", | 		"ephemeral container don't support resource requirements": podtest.MakePod("", | ||||||
| 			podtest.SetEphemeralContainers(core.EphemeralContainer{EphemeralContainerCommon: core.EphemeralContainerCommon{Name: "ctr-ephemeral", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File", Resources: core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}}, TargetContainerName: "ctr"}), | 			podtest.SetEphemeralContainers(core.EphemeralContainer{EphemeralContainerCommon: core.EphemeralContainerCommon{Name: "ctr-ephemeral", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File", Resources: core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "my-claim"}}}}, TargetContainerName: "ctr"}), | ||||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||||
| 				Name:              "my-claim", | 				Name:              "my-claim", | ||||||
| 				ResourceClaimName: &externalClaimName, | 				ResourceClaimName: &externalClaimName, | ||||||
| 			}), | 			}), | ||||||
| 		), | 		), | ||||||
| 		"invalid claim template name": func() core.Pod { | 		"invalid claim template name": func() *core.Pod { | ||||||
| 			pod := goodClaimTemplate.DeepCopy() | 			pod := goodClaimTemplate.DeepCopy() | ||||||
| 			notLabel := ".foo_bar" | 			notLabel := ".foo_bar" | ||||||
| 			pod.Spec.ResourceClaims[0].ResourceClaimTemplateName = ¬Label | 			pod.Spec.ResourceClaims[0].ResourceClaimTemplateName = ¬Label | ||||||
| 			return *pod | 			return pod | ||||||
| 		}(), | 		}(), | ||||||
| 		"invalid claim reference name": func() core.Pod { | 		"invalid claim reference name": func() *core.Pod { | ||||||
| 			pod := goodClaimReference.DeepCopy() | 			pod := goodClaimReference.DeepCopy() | ||||||
| 			notLabel := ".foo_bar" | 			notLabel := ".foo_bar" | ||||||
| 			pod.Spec.ResourceClaims[0].ResourceClaimName = ¬Label | 			pod.Spec.ResourceClaims[0].ResourceClaimName = ¬Label | ||||||
| 			return *pod | 			return pod | ||||||
| 		}(), | 		}(), | ||||||
| 	} | 	} | ||||||
| 	for k, v := range failureCases { | 	for k, v := range failureCases { | ||||||
| @@ -24097,7 +24093,7 @@ func TestValidatePodSpecWithSupplementalGroupsPolicy(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| 	for name, tt := range validatePodSpecTestCases { | 	for name, tt := range validatePodSpecTestCases { | ||||||
| 		t.Run(name, func(t *testing.T) { | 		t.Run(name, func(t *testing.T) { | ||||||
| 			podSpec := podtest.MakePodSpec(core.RestartPolicyAlways, podtest.SetSecurityContext(tt.securityContext), podtest.SetContainers(podtest.MakeContainer("con"))) | 			podSpec := podtest.MakePodSpec(podtest.SetSecurityContext(tt.securityContext), podtest.SetContainers(podtest.MakeContainer("con"))) | ||||||
|  |  | ||||||
| 			if tt.wantFieldErrors == nil { | 			if tt.wantFieldErrors == nil { | ||||||
| 				tt.wantFieldErrors = field.ErrorList{} | 				tt.wantFieldErrors = field.ErrorList{} | ||||||
| @@ -24138,7 +24134,7 @@ func TestValidateWindowsPodSecurityContextSupplementalGroupsPolicy(t *testing.T) | |||||||
|  |  | ||||||
| 	for name, tt := range testCases { | 	for name, tt := range testCases { | ||||||
| 		t.Run(name, func(t *testing.T) { | 		t.Run(name, func(t *testing.T) { | ||||||
| 			podSpec := podtest.MakePodSpec(core.RestartPolicyAlways, podtest.SetSecurityContext(tt.securityContext), podtest.SetOS(core.Windows), podtest.SetContainers(podtest.MakeContainer("con"))) | 			podSpec := podtest.MakePodSpec(podtest.SetSecurityContext(tt.securityContext), podtest.SetOS(core.Windows), podtest.SetContainers(podtest.MakeContainer("con"))) | ||||||
| 			if tt.wantFieldErrors == nil { | 			if tt.wantFieldErrors == nil { | ||||||
| 				tt.wantFieldErrors = field.ErrorList{} | 				tt.wantFieldErrors = field.ErrorList{} | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -63,7 +63,7 @@ func newValidDaemonSet() *apps.DaemonSet { | |||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
| 					Labels: map[string]string{"a": "b"}, | 					Labels: map[string]string{"a": "b"}, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePod("").Spec, | 				Spec: podtest.MakePodSpec(), | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -139,7 +139,7 @@ func newDaemonSetWithSelectorLabels(selectorLabels map[string]string, templateGe | |||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
| 					Labels: selectorLabels, | 					Labels: selectorLabels, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePod("").Spec, | 				Spec: podtest.MakePodSpec(), | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -80,7 +80,7 @@ func validNewDeployment() *apps.Deployment { | |||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
| 					Labels: map[string]string{"a": "b"}, | 					Labels: map[string]string{"a": "b"}, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePod("").Spec, | 				Spec: podtest.MakePodSpec(), | ||||||
| 			}, | 			}, | ||||||
| 			Replicas: 7, | 			Replicas: 7, | ||||||
| 		}, | 		}, | ||||||
|   | |||||||
| @@ -174,7 +174,7 @@ func newDeploymentWithSelectorLabels(selectorLabels map[string]string) *apps.Dep | |||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
| 					Labels: selectorLabels, | 					Labels: selectorLabels, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePod("").Spec, | 				Spec: podtest.MakePodSpec(), | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| @@ -205,7 +205,7 @@ func newDeploymentWithHugePageValue(resourceName api.ResourceName, value resourc | |||||||
| 					Name:      "foo", | 					Name:      "foo", | ||||||
| 					Labels:    map[string]string{"foo": "bar"}, | 					Labels:    map[string]string{"foo": "bar"}, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | 				Spec: podtest.MakePodSpec( | ||||||
| 					podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources( | 					podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources( | ||||||
| 						api.ResourceRequirements{ | 						api.ResourceRequirements{ | ||||||
| 							Requests: api.ResourceList{ | 							Requests: api.ResourceList{ | ||||||
|   | |||||||
| @@ -76,7 +76,7 @@ func validNewReplicaSet() *apps.ReplicaSet { | |||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
| 					Labels: map[string]string{"a": "b"}, | 					Labels: map[string]string{"a": "b"}, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePod("").Spec, | 				Spec: podtest.MakePodSpec(), | ||||||
| 			}, | 			}, | ||||||
| 			Replicas: 7, | 			Replicas: 7, | ||||||
| 		}, | 		}, | ||||||
|   | |||||||
| @@ -50,7 +50,7 @@ func TestReplicaSetStrategy(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("").Spec, | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	rs := &apps.ReplicaSet{ | 	rs := &apps.ReplicaSet{ | ||||||
| @@ -215,7 +215,7 @@ func newReplicaSetWithSelectorLabels(selectorLabels map[string]string) *apps.Rep | |||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
| 					Labels: selectorLabels, | 					Labels: selectorLabels, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePod("").Spec, | 				Spec: podtest.MakePodSpec(), | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -60,7 +60,7 @@ func validNewCronJob() *batch.CronJob { | |||||||
| 			JobTemplate: batch.JobTemplateSpec{ | 			JobTemplate: batch.JobTemplateSpec{ | ||||||
| 				Spec: batch.JobSpec{ | 				Spec: batch.JobSpec{ | ||||||
| 					Template: api.PodTemplateSpec{ | 					Template: api.PodTemplateSpec{ | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
|   | |||||||
| @@ -30,7 +30,7 @@ import ( | |||||||
|  |  | ||||||
| var ( | var ( | ||||||
| 	validPodTemplateSpec = api.PodTemplateSpec{ | 	validPodTemplateSpec = api.PodTemplateSpec{ | ||||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 	} | 	} | ||||||
| 	validCronjobSpec = batch.CronJobSpec{ | 	validCronjobSpec = batch.CronJobSpec{ | ||||||
| 		Schedule:          "5 5 * * ?", | 		Schedule:          "5 5 * * ?", | ||||||
|   | |||||||
| @@ -74,7 +74,7 @@ func validNewJob() *batch.Job { | |||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
| 					Labels: map[string]string{"a": "b"}, | 					Labels: map[string]string{"a": "b"}, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 				Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -1021,7 +1021,7 @@ func TestJobStrategy_ValidateUpdate(t *testing.T) { | |||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			Labels: validSelector.MatchLabels, | 			Labels: validSelector.MatchLabels, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 	} | 	} | ||||||
| 	validPodTemplateSpecNever := *validPodTemplateSpec.DeepCopy() | 	validPodTemplateSpecNever := *validPodTemplateSpec.DeepCopy() | ||||||
| 	validPodTemplateSpecNever.Spec.RestartPolicy = api.RestartPolicyNever | 	validPodTemplateSpecNever.Spec.RestartPolicy = api.RestartPolicyNever | ||||||
| @@ -1223,7 +1223,7 @@ func TestJobStrategy_ValidateUpdate(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: map[string]string{batch.LegacyJobNameLabel: "myjob", batch.LegacyControllerUidLabel: "test"}, | 							Labels: map[string]string{batch.LegacyJobNameLabel: "myjob", batch.LegacyControllerUidLabel: "test"}, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1249,7 +1249,7 @@ func TestJobStrategy_ValidateUpdate(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: map[string]string{batch.LegacyJobNameLabel: "myjob", batch.JobNameLabel: "myjob", batch.LegacyControllerUidLabel: "test", batch.ControllerUidLabel: "test"}, | 							Labels: map[string]string{batch.LegacyJobNameLabel: "myjob", batch.JobNameLabel: "myjob", batch.LegacyControllerUidLabel: "test", batch.ControllerUidLabel: "test"}, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -1315,7 +1315,7 @@ func TestJobStrategy_WarningsOnUpdate(t *testing.T) { | |||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			Labels: validSelector.MatchLabels, | 			Labels: validSelector.MatchLabels, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 	} | 	} | ||||||
| 	cases := map[string]struct { | 	cases := map[string]struct { | ||||||
| 		oldJob            *batch.Job | 		oldJob            *batch.Job | ||||||
| @@ -1470,7 +1470,7 @@ func TestJobStrategy_WarningsOnCreate(t *testing.T) { | |||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			Labels: validSelector.MatchLabels, | 			Labels: validSelector.MatchLabels, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||||
| 	} | 	} | ||||||
| 	validSpec := batch.JobSpec{ | 	validSpec := batch.JobSpec{ | ||||||
| 		CompletionMode: completionModePtr(batch.NonIndexedCompletion), | 		CompletionMode: completionModePtr(batch.NonIndexedCompletion), | ||||||
| @@ -1537,8 +1537,8 @@ func TestJobStrategy_Validate(t *testing.T) { | |||||||
| 	batchLabels := getValidBatchLabels() | 	batchLabels := getValidBatchLabels() | ||||||
| 	labelsWithNonBatch := getValidBatchLabelsWithNonBatch() | 	labelsWithNonBatch := getValidBatchLabelsWithNonBatch() | ||||||
| 	defaultSelector := &metav1.LabelSelector{MatchLabels: map[string]string{batch.ControllerUidLabel: string(theUID)}} | 	defaultSelector := &metav1.LabelSelector{MatchLabels: map[string]string{batch.ControllerUidLabel: string(theUID)}} | ||||||
| 	validPodSpec := podtest.MakePodSpec(api.RestartPolicyOnFailure) | 	validPodSpec := podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)) | ||||||
| 	validPodSpecNever := podtest.MakePodSpec(api.RestartPolicyNever) | 	validPodSpecNever := podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyNever)) | ||||||
| 	validObjectMeta := getValidObjectMeta(0) | 	validObjectMeta := getValidObjectMeta(0) | ||||||
| 	testcases := map[string]struct { | 	testcases := map[string]struct { | ||||||
| 		enableJobPodFailurePolicy     bool | 		enableJobPodFailurePolicy     bool | ||||||
| @@ -1721,7 +1721,7 @@ func TestJobStrategy_Validate(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: labelsWithNonBatch, | 							Labels: labelsWithNonBatch, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure, | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure), | ||||||
| 							podtest.SetVolumes(api.Volume{Name: "volume-name"})), | 							podtest.SetVolumes(api.Volume{Name: "volume-name"})), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| @@ -1735,7 +1735,7 @@ func TestJobStrategy_Validate(t *testing.T) { | |||||||
| 						ObjectMeta: metav1.ObjectMeta{ | 						ObjectMeta: metav1.ObjectMeta{ | ||||||
| 							Labels: labelsWithNonBatch, | 							Labels: labelsWithNonBatch, | ||||||
| 						}, | 						}, | ||||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure, | 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure), | ||||||
| 							podtest.SetVolumes(api.Volume{Name: "volume-name"})), | 							podtest.SetVolumes(api.Volume{Name: "volume-name"})), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
|   | |||||||
| @@ -56,7 +56,7 @@ func validNewPodTemplate(name string) *api.PodTemplate { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: map[string]string{"test": "foo"}, | 				Labels: map[string]string{"test": "foo"}, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("").Spec, | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -83,7 +83,7 @@ func validNewController() *api.ReplicationController { | |||||||
| 				ObjectMeta: metav1.ObjectMeta{ | 				ObjectMeta: metav1.ObjectMeta{ | ||||||
| 					Labels: map[string]string{"a": "b"}, | 					Labels: map[string]string{"a": "b"}, | ||||||
| 				}, | 				}, | ||||||
| 				Spec: podtest.MakePod("").Spec, | 				Spec: podtest.MakePodSpec(), | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -45,7 +45,7 @@ func TestControllerStrategy(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("").Spec, | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	rc := &api.ReplicationController{ | 	rc := &api.ReplicationController{ | ||||||
| @@ -160,7 +160,7 @@ func TestValidateUpdate(t *testing.T) { | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Labels: validSelector, | 				Labels: validSelector, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: podtest.MakePod("").Spec, | 			Spec: podtest.MakePodSpec(), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	oldController := &api.ReplicationController{ | 	oldController := &api.ReplicationController{ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Fraenkel
					Michael Fraenkel