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 | ||||
| } | ||||
|  | ||||
| func MakePodSpec(policy api.RestartPolicy, tweaks ...Tweak) api.PodSpec { | ||||
| 	return MakePod("", append([]Tweak{SetRestartPolicy(policy)}, tweaks...)...).Spec | ||||
| func MakePodSpec(tweaks ...Tweak) api.PodSpec { | ||||
| 	return MakePod("", tweaks...).Spec | ||||
| } | ||||
|  | ||||
| func SetNamespace(ns string) Tweak { | ||||
|   | ||||
| @@ -1504,14 +1504,14 @@ func TestValidateDaemonSetUpdate(t *testing.T) { | ||||
| 	validSelector2 := map[string]string{"c": "d"} | ||||
| 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||
|  | ||||
| 	validPodSpecAbc := podtest.MakePodSpec(api.RestartPolicyAlways, | ||||
| 	validPodSpecAbc := podtest.MakePodSpec( | ||||
| 		podtest.SetContainers(podtest.MakeContainer("abc"))) | ||||
| 	validPodSpecDef := podtest.MakePodSpec(api.RestartPolicyAlways, | ||||
| 	validPodSpecDef := podtest.MakePodSpec( | ||||
| 		podtest.SetContainers(podtest.MakeContainer("def"))) | ||||
| 	validPodSpecNodeSelector := podtest.MakePodSpec(api.RestartPolicyAlways, | ||||
| 	validPodSpecNodeSelector := podtest.MakePodSpec( | ||||
| 		podtest.SetNodeSelector(validSelector), | ||||
| 		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}}})) | ||||
|  | ||||
| 	validPodTemplateAbc := api.PodTemplate{ | ||||
| @@ -1558,7 +1558,7 @@ func TestValidateDaemonSetUpdate(t *testing.T) { | ||||
| 	invalidPodTemplate := api.PodTemplate{ | ||||
| 		Template: api.PodTemplateSpec{ | ||||
| 			// no containers specified | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, podtest.SetContainers()), | ||||
| 			Spec: podtest.MakePodSpec(podtest.SetContainers()), | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| @@ -1976,7 +1976,7 @@ func TestValidateDaemonSet(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	validHostNetPodTemplate := api.PodTemplate{ | ||||
| @@ -1984,7 +1984,7 @@ func TestValidateDaemonSet(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | ||||
| 			Spec: podtest.MakePodSpec( | ||||
| 				podtest.SetSecurityContext(&api.PodSecurityContext{ | ||||
| 					HostNetwork: true, | ||||
| 				}), | ||||
| @@ -1999,7 +1999,7 @@ func TestValidateDaemonSet(t *testing.T) { | ||||
| 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||
| 	invalidPodTemplate := api.PodTemplate{ | ||||
| 		Template: api.PodTemplateSpec{ | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, podtest.SetLabels(invalidSelector)), | ||||
| 			Spec: podtest.MakePodSpec(podtest.SetLabels(invalidSelector)), | ||||
| 		}, | ||||
| 	} | ||||
| 	successCases := []apps.DaemonSet{{ | ||||
| @@ -2124,7 +2124,7 @@ func TestValidateDaemonSet(t *testing.T) { | ||||
| 			Spec: apps.DaemonSetSpec{ | ||||
| 				Selector: &metav1.LabelSelector{MatchLabels: validSelector}, | ||||
| 				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{ | ||||
| 				Selector: &metav1.LabelSelector{MatchLabels: validSelector}, | ||||
| 				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{ | ||||
| 						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"}})), | ||||
| 				}, | ||||
| 				UpdateStrategy: apps.DaemonSetUpdateStrategy{ | ||||
| @@ -2207,7 +2207,7 @@ func validDeployment(tweaks ...func(d *apps.Deployment)) *apps.Deployment { | ||||
| 						"name": "abc", | ||||
| 					}, | ||||
| 				}, | ||||
| 				Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 				Spec: podtest.MakePodSpec(), | ||||
| 			}, | ||||
| 			RollbackTo: &apps.RollbackConfig{ | ||||
| 				Revision: 1, | ||||
| @@ -2538,7 +2538,7 @@ func TestValidateDeploymentUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validLabels, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	readWriteVolumePodTemplate := api.PodTemplate{ | ||||
| @@ -2546,7 +2546,7 @@ func TestValidateDeploymentUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				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}}}), | ||||
| 			), | ||||
| 		}, | ||||
| @@ -2555,7 +2555,7 @@ func TestValidateDeploymentUpdate(t *testing.T) { | ||||
| 	invalidPodTemplate := api.PodTemplate{ | ||||
| 		Template: api.PodTemplateSpec{ | ||||
| 			// no containers specified | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, podtest.SetContainers()), | ||||
| 			Spec: podtest.MakePodSpec(podtest.SetContainers()), | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: invalidLabels, | ||||
| 			}, | ||||
| @@ -2852,7 +2852,7 @@ func TestValidateReplicaSetStatusUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validLabels, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	type rcUpdateTest struct { | ||||
| @@ -2930,7 +2930,7 @@ func TestValidateReplicaSetUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validLabels, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	readWriteVolumePodTemplate := api.PodTemplate{ | ||||
| @@ -2938,7 +2938,7 @@ func TestValidateReplicaSetUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				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}}}), | ||||
| 			), | ||||
| 		}, | ||||
| @@ -2946,7 +2946,7 @@ func TestValidateReplicaSetUpdate(t *testing.T) { | ||||
| 	invalidLabels := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||
| 	invalidPodTemplate := api.PodTemplate{ | ||||
| 		Template: api.PodTemplateSpec{ | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, podtest.SetContainers()), | ||||
| 			Spec: podtest.MakePodSpec(podtest.SetContainers()), | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: invalidLabels, | ||||
| 			}, | ||||
| @@ -3096,7 +3096,7 @@ func TestValidateReplicaSet(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validLabels, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	validHostNetPodTemplate := api.PodTemplate{ | ||||
| @@ -3104,7 +3104,7 @@ func TestValidateReplicaSet(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validLabels, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | ||||
| 			Spec: podtest.MakePodSpec( | ||||
| 				podtest.SetSecurityContext(&api.PodSecurityContext{ | ||||
| 					HostNetwork: true, | ||||
| 				}), | ||||
| @@ -3120,7 +3120,7 @@ func TestValidateReplicaSet(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				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}}}), | ||||
| 			), | ||||
| 		}, | ||||
| @@ -3128,7 +3128,7 @@ func TestValidateReplicaSet(t *testing.T) { | ||||
| 	invalidLabels := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||
| 	invalidPodTemplate := api.PodTemplate{ | ||||
| 		Template: api.PodTemplateSpec{ | ||||
| 			Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: invalidLabels, | ||||
| 			}, | ||||
| @@ -3262,7 +3262,7 @@ func TestValidateReplicaSet(t *testing.T) { | ||||
| 			Spec: apps.ReplicaSetSpec{ | ||||
| 				Selector: &metav1.LabelSelector{MatchLabels: validLabels}, | ||||
| 				Template: api.PodTemplateSpec{ | ||||
| 					Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | ||||
| 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||
| 					ObjectMeta: metav1.ObjectMeta{ | ||||
| 						Labels: validLabels, | ||||
| 					}, | ||||
| @@ -3277,7 +3277,7 @@ func TestValidateReplicaSet(t *testing.T) { | ||||
| 			Spec: apps.ReplicaSetSpec{ | ||||
| 				Selector: &metav1.LabelSelector{MatchLabels: validLabels}, | ||||
| 				Template: api.PodTemplateSpec{ | ||||
| 					Spec: podtest.MakePodSpec(api.RestartPolicyNever), | ||||
| 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyNever)), | ||||
| 					ObjectMeta: metav1.ObjectMeta{ | ||||
| 						Labels: validLabels, | ||||
| 					}, | ||||
|   | ||||
| @@ -62,7 +62,7 @@ func getValidPodTemplateSpecForManual(selector *metav1.LabelSelector) api.PodTem | ||||
| 		ObjectMeta: metav1.ObjectMeta{ | ||||
| 			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{ | ||||
| 			Labels: selector.MatchLabels, | ||||
| 		}, | ||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure, | ||||
| 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure), | ||||
| 			podtest.SetInitContainers(podtest.MakeContainer("def"))), | ||||
| 	} | ||||
| } | ||||
| @@ -388,7 +388,7 @@ func TestValidateJob(t *testing.T) { | ||||
| 						ObjectMeta: metav1.ObjectMeta{ | ||||
| 							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{ | ||||
| 							Labels: validGeneratedSelector.MatchLabels, | ||||
| 						}, | ||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | ||||
| 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||
| 					}, | ||||
| 					PodFailurePolicy: &batch.PodFailurePolicy{ | ||||
| 						Rules: []batch.PodFailurePolicyRule{}, | ||||
| @@ -1235,7 +1235,7 @@ func TestValidateJob(t *testing.T) { | ||||
| 						ObjectMeta: metav1.ObjectMeta{ | ||||
| 							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{ | ||||
| 							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{ | ||||
| 							Labels: validManualSelector.MatchLabels, | ||||
| 						}, | ||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 						Spec: podtest.MakePodSpec(), | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| @@ -1295,7 +1295,7 @@ func TestValidateJob(t *testing.T) { | ||||
| 						ObjectMeta: metav1.ObjectMeta{ | ||||
| 							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{ | ||||
| 							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{ | ||||
| 							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{ | ||||
| 							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{ | ||||
| 					Spec: batch.JobSpec{ | ||||
| 						Template: api.PodTemplateSpec{ | ||||
| 							Spec: podtest.MakePodSpec(api.RestartPolicyAlways), | ||||
| 							Spec: podtest.MakePodSpec(), | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| @@ -2853,7 +2853,7 @@ func TestValidateCronJob(t *testing.T) { | ||||
| 				JobTemplate: batch.JobTemplateSpec{ | ||||
| 					Spec: batch.JobSpec{ | ||||
| 						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 { | ||||
| 	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 { | ||||
| 		invalidStr := fmt.Sprintf("must be greater than 0 and less than terminationGracePeriodSeconds (%d)", *gracePeriod) | ||||
| 		allErrors = append(allErrors, field.Invalid(fldPath, sleep.Seconds, invalidStr)) | ||||
|   | ||||
| @@ -9907,9 +9907,9 @@ func TestValidatePodSpec(t *testing.T) { | ||||
| 	badfsGroupChangePolicy1 := core.PodFSGroupChangePolicy("invalid") | ||||
| 	badfsGroupChangePolicy2 := core.PodFSGroupChangePolicy("") | ||||
|  | ||||
| 	successCases := map[string]core.Pod{ | ||||
| 		"populate basic fields, leave defaults for most": *podtest.MakePod(""), | ||||
| 		"populate all fields": *podtest.MakePod("", | ||||
| 	successCases := map[string]*core.Pod{ | ||||
| 		"populate basic fields, leave defaults for most": podtest.MakePod(""), | ||||
| 		"populate all fields": podtest.MakePod("", | ||||
| 			podtest.SetInitContainers(podtest.MakeContainer("ictr")), | ||||
| 			podtest.SetVolumes(podtest.MakeEmptyVolume(("vol"))), | ||||
| 			podtest.SetNodeSelector(map[string]string{ | ||||
| @@ -9919,36 +9919,36 @@ func TestValidatePodSpec(t *testing.T) { | ||||
| 			podtest.SetActiveDeadlineSeconds(activeDeadlineSecondsMax), | ||||
| 			podtest.SetServiceAccountName("acct"), | ||||
| 		), | ||||
| 		"populate HostNetwork": *podtest.MakePod("", | ||||
| 		"populate HostNetwork": podtest.MakePod("", | ||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", | ||||
| 				podtest.SetContainerPorts(core.ContainerPort{HostPort: 8080, ContainerPort: 8080, Protocol: "TCP"}))), | ||||
| 			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{ | ||||
| 				SupplementalGroups: []int64{minGroupID}, | ||||
| 				RunAsUser:          &minUserID, | ||||
| 				FSGroup:            &minGroupID, | ||||
| 			}), | ||||
| 		), | ||||
| 		"populate RunAsUser SupplementalGroups FSGroup with maxID 2147483647": *podtest.MakePod("", | ||||
| 		"populate RunAsUser SupplementalGroups FSGroup with maxID 2147483647": podtest.MakePod("", | ||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||
| 				SupplementalGroups: []int64{maxGroupID}, | ||||
| 				RunAsUser:          &maxUserID, | ||||
| 				FSGroup:            &maxGroupID, | ||||
| 			}), | ||||
| 		), | ||||
| 		"populate HostIPC": *podtest.MakePod("", | ||||
| 		"populate HostIPC": podtest.MakePod("", | ||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||
| 				HostIPC: true, | ||||
| 			}), | ||||
| 		), | ||||
| 		"populate HostPID": *podtest.MakePod("", | ||||
| 		"populate HostPID": podtest.MakePod("", | ||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||
| 				HostPID: true, | ||||
| 			}), | ||||
| 		), | ||||
| 		"populate Affinity": *podtest.MakePod("", | ||||
| 		"populate Affinity": podtest.MakePod("", | ||||
| 			podtest.SetAffinity(&core.Affinity{ | ||||
| 				NodeAffinity: &core.NodeAffinity{ | ||||
| 					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"}}), | ||||
| 		), | ||||
| 		"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"}}), | ||||
| 		), | ||||
| 		"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.SetSecurityContext(&core.PodSecurityContext{ | ||||
| 				HostNetwork: true, | ||||
| 			}), | ||||
| 		), | ||||
| 		"populate PriorityClassName": *podtest.MakePod("", | ||||
| 		"populate PriorityClassName": podtest.MakePod("", | ||||
| 			podtest.SetPriorityClassName("valid-name"), | ||||
| 		), | ||||
| 		"populate ShareProcessNamespace": *podtest.MakePod("", | ||||
| 		"populate ShareProcessNamespace": podtest.MakePod("", | ||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||
| 				ShareProcessNamespace: &[]bool{true}[0], | ||||
| 			}), | ||||
| 		), | ||||
| 		"populate RuntimeClassName": *podtest.MakePod("", | ||||
| 		"populate RuntimeClassName": podtest.MakePod("", | ||||
| 			podtest.SetRuntimeClassName("valid-sandbox"), | ||||
| 		), | ||||
| 		"populate Overhead": *podtest.MakePod("", | ||||
| 		"populate Overhead": podtest.MakePod("", | ||||
| 			podtest.SetOverhead(core.ResourceList{}), | ||||
| 		), | ||||
| 		"populate FSGroupChangePolicy": *podtest.MakePod("", | ||||
| 		"populate FSGroupChangePolicy": podtest.MakePod("", | ||||
| 			podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||
| 				FSGroupChangePolicy: &goodfsGroupChangePolicy, | ||||
| 			}), | ||||
| 		), | ||||
| 		"resources resize policy for containers": *podtest.MakePod("", | ||||
| 		"resources resize policy for containers": podtest.MakePod("", | ||||
| 			podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResizePolicy( | ||||
| 				core.ContainerResizePolicy{ResourceName: "cpu", RestartPolicy: "NotRequired"}), | ||||
| 			)), | ||||
| @@ -16257,7 +16257,7 @@ func TestValidateReplicationControllerUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("").Spec, | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	readWriteVolumePodTemplate := core.PodTemplate{ | ||||
| @@ -16265,9 +16265,9 @@ func TestValidateReplicationControllerUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				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}}}), | ||||
| 			).Spec, | ||||
| 			), | ||||
| 		}, | ||||
| 	} | ||||
| 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||
| @@ -16276,7 +16276,7 @@ func TestValidateReplicationControllerUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: invalidSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("").Spec, | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	type rcUpdateTest struct { | ||||
| @@ -16408,7 +16408,7 @@ func TestValidateReplicationController(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("").Spec, | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	readWriteVolumePodTemplate := core.PodTemplate{ | ||||
| @@ -16416,9 +16416,9 @@ func TestValidateReplicationController(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				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}}}), | ||||
| 			).Spec, | ||||
| 			), | ||||
| 		}, | ||||
| 	} | ||||
| 	hostnetPodTemplate := core.PodTemplate{ | ||||
| @@ -16426,7 +16426,7 @@ func TestValidateReplicationController(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("", | ||||
| 			Spec: podtest.MakePodSpec( | ||||
| 				podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||
| 					HostNetwork: true, | ||||
| 				}), | ||||
| @@ -16435,13 +16435,13 @@ func TestValidateReplicationController(t *testing.T) { | ||||
| 						ContainerPort: 12345, | ||||
| 						Protocol:      core.ProtocolTCP, | ||||
| 					}))), | ||||
| 			).Spec, | ||||
| 			), | ||||
| 		}, | ||||
| 	} | ||||
| 	invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"} | ||||
| 	invalidPodTemplate := core.PodTemplate{ | ||||
| 		Template: core.PodTemplateSpec{ | ||||
| 			Spec: podtest.MakePod("").Spec, | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: invalidSelector, | ||||
| 			}, | ||||
| @@ -16575,9 +16575,7 @@ func TestValidateReplicationController(t *testing.T) { | ||||
| 			Spec: core.ReplicationControllerSpec{ | ||||
| 				Selector: validSelector, | ||||
| 				Template: &core.PodTemplateSpec{ | ||||
| 					Spec: podtest.MakePod("", | ||||
| 						podtest.SetRestartPolicy(core.RestartPolicyOnFailure), | ||||
| 					).Spec, | ||||
| 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(core.RestartPolicyOnFailure)), | ||||
| 					ObjectMeta: metav1.ObjectMeta{ | ||||
| 						Labels: validSelector, | ||||
| 					}, | ||||
| @@ -16592,9 +16590,7 @@ func TestValidateReplicationController(t *testing.T) { | ||||
| 			Spec: core.ReplicationControllerSpec{ | ||||
| 				Selector: validSelector, | ||||
| 				Template: &core.PodTemplateSpec{ | ||||
| 					Spec: podtest.MakePod("", | ||||
| 						podtest.SetRestartPolicy(core.RestartPolicyNever), | ||||
| 					).Spec, | ||||
| 					Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(core.RestartPolicyNever)), | ||||
| 					ObjectMeta: metav1.ObjectMeta{ | ||||
| 						Labels: validSelector, | ||||
| 					}, | ||||
| @@ -16610,9 +16606,9 @@ func TestValidateReplicationController(t *testing.T) { | ||||
| 					ObjectMeta: metav1.ObjectMeta{ | ||||
| 						Labels: validSelector, | ||||
| 					}, | ||||
| 					Spec: podtest.MakePod("", | ||||
| 					Spec: podtest.MakePodSpec( | ||||
| 						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", | ||||
| 				}, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("", | ||||
| 			Spec: podtest.MakePodSpec( | ||||
| 				podtest.SetContainers( | ||||
| 					podtest.MakeContainer("test1"), | ||||
| 					podtest.MakeContainer("test2", | ||||
| @@ -22864,7 +22860,7 @@ func TestValidatePodTemplateSpecSeccomp(t *testing.T) { | ||||
| 								Type: core.SeccompProfileTypeRuntimeDefault, | ||||
| 							}, | ||||
| 						}))), | ||||
| 			).Spec, | ||||
| 			), | ||||
| 		}, | ||||
| 	}, { | ||||
| 		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", | ||||
| 				}, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("", | ||||
| 			Spec: podtest.MakePodSpec( | ||||
| 				podtest.SetSecurityContext(&core.PodSecurityContext{ | ||||
| 					SeccompProfile: &core.SeccompProfile{ | ||||
| 						Type: core.SeccompProfileTypeUnconfined, | ||||
| 					}, | ||||
| 				}), | ||||
| 			).Spec, | ||||
| 			), | ||||
| 		}, | ||||
| 	}, { | ||||
| 		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", | ||||
| 				}, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("", | ||||
| 			Spec: podtest.MakePodSpec( | ||||
| 				podtest.SetInitContainers(podtest.MakeContainer("init-test", | ||||
| 					podtest.SetContainerSecurityContext(core.SecurityContext{ | ||||
| 						SeccompProfile: &core.SeccompProfile{ | ||||
| 							Type: core.SeccompProfileTypeRuntimeDefault, | ||||
| 						}, | ||||
| 					}))), | ||||
| 			).Spec, | ||||
| 			), | ||||
| 		}, | ||||
| 	}, | ||||
| 	} | ||||
| @@ -23724,7 +23720,7 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | ||||
| 	shortPodName := &metav1.ObjectMeta{ | ||||
| 		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.SetRestartPolicy(core.RestartPolicyAlways), | ||||
| 		podtest.SetResourceClaims(core.PodResourceClaim{ | ||||
| @@ -23732,7 +23728,7 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | ||||
| 			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.SetRestartPolicy(core.RestartPolicyAlways), | ||||
| 		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 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.SetResourceClaims( | ||||
| 				core.PodResourceClaim{ | ||||
| @@ -23756,7 +23752,7 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | ||||
| 					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.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:              "my-claim", | ||||
| @@ -23772,26 +23768,26 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | ||||
| 		}) | ||||
| 	} | ||||
|  | ||||
| 	failureCases := map[string]core.Pod{ | ||||
| 		"pod claim name with prefix": *podtest.MakePod("", | ||||
| 	failureCases := map[string]*core.Pod{ | ||||
| 		"pod claim name with prefix": podtest.MakePod("", | ||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:              "../my-claim", | ||||
| 				ResourceClaimName: &externalClaimName, | ||||
| 			}), | ||||
| 		), | ||||
| 		"pod claim name with path": *podtest.MakePod("", | ||||
| 		"pod claim name with path": podtest.MakePod("", | ||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:              "my/claim", | ||||
| 				ResourceClaimName: &externalClaimName, | ||||
| 			}), | ||||
| 		), | ||||
| 		"pod claim name empty": *podtest.MakePod("", | ||||
| 		"pod claim name empty": podtest.MakePod("", | ||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:              "", | ||||
| 				ResourceClaimName: &externalClaimName, | ||||
| 			}), | ||||
| 		), | ||||
| 		"duplicate pod claim entries": *podtest.MakePod("", | ||||
| 		"duplicate pod claim entries": podtest.MakePod("", | ||||
| 			podtest.SetResourceClaims( | ||||
| 				core.PodResourceClaim{ | ||||
| 					Name:              "my-claim", | ||||
| @@ -23802,12 +23798,12 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | ||||
| 					ResourceClaimName: &externalClaimName, | ||||
| 				}), | ||||
| 		), | ||||
| 		"resource claim source empty": *podtest.MakePod("", | ||||
| 		"resource claim source empty": podtest.MakePod("", | ||||
| 			podtest.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				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.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:                      "my-claim", | ||||
| @@ -23815,32 +23811,32 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | ||||
| 				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.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:              "my-claim", | ||||
| 				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.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:              "my-claim", | ||||
| 				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.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:              "my-claim", | ||||
| 				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.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.SetRestartPolicy(core.RestartPolicyAlways), | ||||
| 			podtest.SetResourceClaims( | ||||
| @@ -23853,24 +23849,24 @@ func TestValidateDynamicResourceAllocation(t *testing.T) { | ||||
| 					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.SetResourceClaims(core.PodResourceClaim{ | ||||
| 				Name:              "my-claim", | ||||
| 				ResourceClaimName: &externalClaimName, | ||||
| 			}), | ||||
| 		), | ||||
| 		"invalid claim template name": func() core.Pod { | ||||
| 		"invalid claim template name": func() *core.Pod { | ||||
| 			pod := goodClaimTemplate.DeepCopy() | ||||
| 			notLabel := ".foo_bar" | ||||
| 			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() | ||||
| 			notLabel := ".foo_bar" | ||||
| 			pod.Spec.ResourceClaims[0].ResourceClaimName = ¬Label | ||||
| 			return *pod | ||||
| 			return pod | ||||
| 		}(), | ||||
| 	} | ||||
| 	for k, v := range failureCases { | ||||
| @@ -24097,7 +24093,7 @@ func TestValidatePodSpecWithSupplementalGroupsPolicy(t *testing.T) { | ||||
| 	} | ||||
| 	for name, tt := range validatePodSpecTestCases { | ||||
| 		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 { | ||||
| 				tt.wantFieldErrors = field.ErrorList{} | ||||
| @@ -24138,7 +24134,7 @@ func TestValidateWindowsPodSecurityContextSupplementalGroupsPolicy(t *testing.T) | ||||
|  | ||||
| 	for name, tt := range testCases { | ||||
| 		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 { | ||||
| 				tt.wantFieldErrors = field.ErrorList{} | ||||
| 			} | ||||
|   | ||||
| @@ -63,7 +63,7 @@ func newValidDaemonSet() *apps.DaemonSet { | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					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{ | ||||
| 					Labels: selectorLabels, | ||||
| 				}, | ||||
| 				Spec: podtest.MakePod("").Spec, | ||||
| 				Spec: podtest.MakePodSpec(), | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
|   | ||||
| @@ -80,7 +80,7 @@ func validNewDeployment() *apps.Deployment { | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					Labels: map[string]string{"a": "b"}, | ||||
| 				}, | ||||
| 				Spec: podtest.MakePod("").Spec, | ||||
| 				Spec: podtest.MakePodSpec(), | ||||
| 			}, | ||||
| 			Replicas: 7, | ||||
| 		}, | ||||
|   | ||||
| @@ -174,7 +174,7 @@ func newDeploymentWithSelectorLabels(selectorLabels map[string]string) *apps.Dep | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					Labels: selectorLabels, | ||||
| 				}, | ||||
| 				Spec: podtest.MakePod("").Spec, | ||||
| 				Spec: podtest.MakePodSpec(), | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| @@ -205,7 +205,7 @@ func newDeploymentWithHugePageValue(resourceName api.ResourceName, value resourc | ||||
| 					Name:      "foo", | ||||
| 					Labels:    map[string]string{"foo": "bar"}, | ||||
| 				}, | ||||
| 				Spec: podtest.MakePodSpec(api.RestartPolicyAlways, | ||||
| 				Spec: podtest.MakePodSpec( | ||||
| 					podtest.SetContainers(podtest.MakeContainer("ctr", podtest.SetContainerResources( | ||||
| 						api.ResourceRequirements{ | ||||
| 							Requests: api.ResourceList{ | ||||
|   | ||||
| @@ -76,7 +76,7 @@ func validNewReplicaSet() *apps.ReplicaSet { | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					Labels: map[string]string{"a": "b"}, | ||||
| 				}, | ||||
| 				Spec: podtest.MakePod("").Spec, | ||||
| 				Spec: podtest.MakePodSpec(), | ||||
| 			}, | ||||
| 			Replicas: 7, | ||||
| 		}, | ||||
|   | ||||
| @@ -50,7 +50,7 @@ func TestReplicaSetStrategy(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("").Spec, | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	rs := &apps.ReplicaSet{ | ||||
| @@ -215,7 +215,7 @@ func newReplicaSetWithSelectorLabels(selectorLabels map[string]string) *apps.Rep | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					Labels: selectorLabels, | ||||
| 				}, | ||||
| 				Spec: podtest.MakePod("").Spec, | ||||
| 				Spec: podtest.MakePodSpec(), | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
|   | ||||
| @@ -60,7 +60,7 @@ func validNewCronJob() *batch.CronJob { | ||||
| 			JobTemplate: batch.JobTemplateSpec{ | ||||
| 				Spec: batch.JobSpec{ | ||||
| 					Template: api.PodTemplateSpec{ | ||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | ||||
| 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
|   | ||||
| @@ -30,7 +30,7 @@ import ( | ||||
|  | ||||
| var ( | ||||
| 	validPodTemplateSpec = api.PodTemplateSpec{ | ||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | ||||
| 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||
| 	} | ||||
| 	validCronjobSpec = batch.CronJobSpec{ | ||||
| 		Schedule:          "5 5 * * ?", | ||||
|   | ||||
| @@ -74,7 +74,7 @@ func validNewJob() *batch.Job { | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					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{ | ||||
| 			Labels: validSelector.MatchLabels, | ||||
| 		}, | ||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | ||||
| 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||
| 	} | ||||
| 	validPodTemplateSpecNever := *validPodTemplateSpec.DeepCopy() | ||||
| 	validPodTemplateSpecNever.Spec.RestartPolicy = api.RestartPolicyNever | ||||
| @@ -1223,7 +1223,7 @@ func TestJobStrategy_ValidateUpdate(t *testing.T) { | ||||
| 						ObjectMeta: metav1.ObjectMeta{ | ||||
| 							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{ | ||||
| 							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{ | ||||
| 			Labels: validSelector.MatchLabels, | ||||
| 		}, | ||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | ||||
| 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||
| 	} | ||||
| 	cases := map[string]struct { | ||||
| 		oldJob            *batch.Job | ||||
| @@ -1470,7 +1470,7 @@ func TestJobStrategy_WarningsOnCreate(t *testing.T) { | ||||
| 		ObjectMeta: metav1.ObjectMeta{ | ||||
| 			Labels: validSelector.MatchLabels, | ||||
| 		}, | ||||
| 		Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure), | ||||
| 		Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)), | ||||
| 	} | ||||
| 	validSpec := batch.JobSpec{ | ||||
| 		CompletionMode: completionModePtr(batch.NonIndexedCompletion), | ||||
| @@ -1537,8 +1537,8 @@ func TestJobStrategy_Validate(t *testing.T) { | ||||
| 	batchLabels := getValidBatchLabels() | ||||
| 	labelsWithNonBatch := getValidBatchLabelsWithNonBatch() | ||||
| 	defaultSelector := &metav1.LabelSelector{MatchLabels: map[string]string{batch.ControllerUidLabel: string(theUID)}} | ||||
| 	validPodSpec := podtest.MakePodSpec(api.RestartPolicyOnFailure) | ||||
| 	validPodSpecNever := podtest.MakePodSpec(api.RestartPolicyNever) | ||||
| 	validPodSpec := podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure)) | ||||
| 	validPodSpecNever := podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyNever)) | ||||
| 	validObjectMeta := getValidObjectMeta(0) | ||||
| 	testcases := map[string]struct { | ||||
| 		enableJobPodFailurePolicy     bool | ||||
| @@ -1721,7 +1721,7 @@ func TestJobStrategy_Validate(t *testing.T) { | ||||
| 						ObjectMeta: metav1.ObjectMeta{ | ||||
| 							Labels: labelsWithNonBatch, | ||||
| 						}, | ||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure, | ||||
| 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure), | ||||
| 							podtest.SetVolumes(api.Volume{Name: "volume-name"})), | ||||
| 					}, | ||||
| 				}, | ||||
| @@ -1735,7 +1735,7 @@ func TestJobStrategy_Validate(t *testing.T) { | ||||
| 						ObjectMeta: metav1.ObjectMeta{ | ||||
| 							Labels: labelsWithNonBatch, | ||||
| 						}, | ||||
| 						Spec: podtest.MakePodSpec(api.RestartPolicyOnFailure, | ||||
| 						Spec: podtest.MakePodSpec(podtest.SetRestartPolicy(api.RestartPolicyOnFailure), | ||||
| 							podtest.SetVolumes(api.Volume{Name: "volume-name"})), | ||||
| 					}, | ||||
| 				}, | ||||
|   | ||||
| @@ -56,7 +56,7 @@ func validNewPodTemplate(name string) *api.PodTemplate { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: map[string]string{"test": "foo"}, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("").Spec, | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -83,7 +83,7 @@ func validNewController() *api.ReplicationController { | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					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{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("").Spec, | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	rc := &api.ReplicationController{ | ||||
| @@ -160,7 +160,7 @@ func TestValidateUpdate(t *testing.T) { | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Labels: validSelector, | ||||
| 			}, | ||||
| 			Spec: podtest.MakePod("").Spec, | ||||
| 			Spec: podtest.MakePodSpec(), | ||||
| 		}, | ||||
| 	} | ||||
| 	oldController := &api.ReplicationController{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Fraenkel
					Michael Fraenkel