Repository: kubernetes/kubernetes (language: go)

Issue:
Cleanup: Validate pod terminationGracePeriodSeconds and fix tests
xref: https://github.com/kubernetes/kubernetes/pull/119026/files#r1265687485

Apparently we do not validate that the `terminationGracePeriodSeconds` field is non-nil.  It has a default value, so it should never actually be nil, but because we never validated it in the past, we have tests that do not set it.

We should remove code which check for nil, like the above comment:

```
	var gracePeriod int64
	if spec.TerminationGracePeriodSeconds != nil {
		// this could happen in tests
		gracePeriod = *spec.TerminationGracePeriodSeconds
	}
```

This will cause a bunch of tests to fail.  Those tests SHOULD be setting this field properly.  See "k8s.io/kubernetes/pkg/api/service/testing" which has helper functions for the same problem in Service.



Discussion / hints:
This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the `triage/accepted` label and provide further guidance.

The `triage/accepted` label can be added by org members by writing `/triage accepted` in a comment.


<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>
/assign
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity, `lifecycle/stale` is applied
- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied
- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed

You can:
- Mark this issue as fresh with `/remove-lifecycle stale`
- Close this issue with `/close`
- Offer to help out with [Issue Triage][1]

Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community).

/lifecycle stale

[1]: https://www.kubernetes.dev/docs/guide/issue-triage/
 i would like to have a look at this issue 

let me know @thockin @charles-chenzz 
You don't need permission :)


Message ID: ***@***.***>
>

I got pretty far on the cleanup but then hit this test:
https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/apps/validation/validation_test.go#L2091

Not sure how exactly to fix this.  I can set the TerminationGracePeriodSeconds value into the PodSpec which seems dubious given the alternative which is to apply the defaults which we don't really do anywhere either.  
@fraenkel please go ahead with a PR either commenting or removing that test with your notes above, reviewers can chime in there.
What error are you getting?  That test looks like it runs an invalid (zero-value) template, which should fail?
Well since we removed the fill in for the TerminationGraccePeriod, that panics since its nil. Each of the app resources have this issue.

ValidatePodSpec still needs to grab the gracePeriod so ti can do further validation.

Fix patch:
diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go
index 7eadbe664d6f1..e0841d0c21bb2 100644
--- a/pkg/apis/core/validation/validation.go
+++ b/pkg/apis/core/validation/validation.go
@@ -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))


Test patch:
diff --git a/pkg/api/pod/testing/make.go b/pkg/api/pod/testing/make.go
index 51d45bc3bc313..6faee51ea3535 100644
--- a/pkg/api/pod/testing/make.go
+++ b/pkg/api/pod/testing/make.go
@@ -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 {
diff --git a/pkg/apis/apps/validation/validation_test.go b/pkg/apis/apps/validation/validation_test.go
index 5483b58066abe..1155fda24133f 100644
--- a/pkg/apis/apps/validation/validation_test.go
+++ b/pkg/apis/apps/validation/validation_test.go
@@ -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,
 					},
diff --git a/pkg/apis/batch/validation/validation_test.go b/pkg/apis/batch/validation/validation_test.go
index c2fa713c92806..25e7c8f5f6403 100644
--- a/pkg/apis/batch/validation/validation_test.go
+++ b/pkg/apis/batch/validation/validation_test.go
@@ -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")),
 						},
 					},
 				},
diff --git a/pkg/apis/core/validation/validation_test.go b/pkg/apis/core/validation/validation_test.go
index 855582aee1bc2..65d5a2236e395 100644
--- a/pkg/apis/core/validation/validation_test.go
+++ b/pkg/apis/core/validation/validation_test.go
@@ -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 = &notLabel
-			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 = &notLabel
-			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{}
 			}
diff --git a/pkg/registry/apps/daemonset/storage/storage_test.go b/pkg/registry/apps/daemonset/storage/storage_test.go
index 376670113924c..0b84720584187 100644
--- a/pkg/registry/apps/daemonset/storage/storage_test.go
+++ b/pkg/registry/apps/daemonset/storage/storage_test.go
@@ -63,7 +63,7 @@ func newValidDaemonSet() *apps.DaemonSet {
 				ObjectMeta: metav1.ObjectMeta{
 					Labels: map[string]string{"a": "b"},
 				},
-				Spec: podtest.MakePod("").Spec,
+				Spec: podtest.MakePodSpec(),
 			},
 		},
 	}
diff --git a/pkg/registry/apps/daemonset/strategy_test.go b/pkg/registry/apps/daemonset/strategy_test.go
index 77add6fb7377a..f1db558bf413d 100644
--- a/pkg/registry/apps/daemonset/strategy_test.go
+++ b/pkg/registry/apps/daemonset/strategy_test.go
@@ -139,7 +139,7 @@ func newDaemonSetWithSelectorLabels(selectorLabels map[string]string, templateGe
 				ObjectMeta: metav1.ObjectMeta{
 					Labels: selectorLabels,
 				},
-				Spec: podtest.MakePod("").Spec,
+				Spec: podtest.MakePodSpec(),
 			},
 		},
 	}
diff --git a/pkg/registry/apps/deployment/storage/storage_test.go b/pkg/registry/apps/deployment/storage/storage_test.go
index 6a1bd0533ec41..316185b021bae 100644
--- a/pkg/registry/apps/deployment/storage/storage_test.go
+++ b/pkg/registry/apps/deployment/storage/storage_test.go
@@ -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,
 		},
diff --git a/pkg/registry/apps/deployment/strategy_test.go b/pkg/registry/apps/deployment/strategy_test.go
index 37f4c810fbedd..68e11e79464c6 100644
--- a/pkg/registry/apps/deployment/strategy_test.go
+++ b/pkg/registry/apps/deployment/strategy_test.go
@@ -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{
diff --git a/pkg/registry/apps/replicaset/storage/storage_test.go b/pkg/registry/apps/replicaset/storage/storage_test.go
index 63411e21a423d..8da0749b51255 100644
--- a/pkg/registry/apps/replicaset/storage/storage_test.go
+++ b/pkg/registry/apps/replicaset/storage/storage_test.go
@@ -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,
 		},
diff --git a/pkg/registry/apps/replicaset/strategy_test.go b/pkg/registry/apps/replicaset/strategy_test.go
index 06efdd2da55cc..01cd2404903d9 100644
--- a/pkg/registry/apps/replicaset/strategy_test.go
+++ b/pkg/registry/apps/replicaset/strategy_test.go
@@ -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(),
 			},
 		},
 	}
diff --git a/pkg/registry/batch/cronjob/storage/storage_test.go b/pkg/registry/batch/cronjob/storage/storage_test.go
index 46a5019fe22f4..a15b107406002 100644
--- a/pkg/registry/batch/cronjob/storage/storage_test.go
+++ b/pkg/registry/batch/cronjob/storage/storage_test.go
@@ -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)),
 					},
 				},
 			},
diff --git a/pkg/registry/batch/cronjob/strategy_test.go b/pkg/registry/batch/cronjob/strategy_test.go
index be645fcb43d58..28f479e1cade6 100644
--- a/pkg/registry/batch/cronjob/strategy_test.go
+++ b/pkg/registry/batch/cronjob/strategy_test.go
@@ -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 * * ?",
diff --git a/pkg/registry/batch/job/storage/storage_test.go b/pkg/registry/batch/job/storage/storage_test.go
index 8b5112cd3b008..ce4ca97bc02a3 100644
--- a/pkg/registry/batch/job/storage/storage_test.go
+++ b/pkg/registry/batch/job/storage/storage_test.go
@@ -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)),
 			},
 		},
 	}
diff --git a/pkg/registry/batch/job/strategy_test.go b/pkg/registry/batch/job/strategy_test.go
index acd4b0ab9a078..15fd8441ec692 100644
--- a/pkg/registry/batch/job/strategy_test.go
+++ b/pkg/registry/batch/job/strategy_test.go
@@ -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"})),
 					},
 				},
diff --git a/pkg/registry/core/podtemplate/storage/storage_test.go b/pkg/registry/core/podtemplate/storage/storage_test.go
index fd177c4b05d88..b38bf9a5c310e 100644
--- a/pkg/registry/core/podtemplate/storage/storage_test.go
+++ b/pkg/registry/core/podtemplate/storage/storage_test.go
@@ -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(),
 		},
 	}
 }
diff --git a/pkg/registry/core/replicationcontroller/storage/storage_test.go b/pkg/registry/core/replicationcontroller/storage/storage_test.go
index 9fb3f19b1900c..cf840aa972eb0 100644
--- a/pkg/registry/core/replicationcontroller/storage/storage_test.go
+++ b/pkg/registry/core/replicationcontroller/storage/storage_test.go
@@ -83,7 +83,7 @@ func validNewController() *api.ReplicationController {
 				ObjectMeta: metav1.ObjectMeta{
 					Labels: map[string]string{"a": "b"},
 				},
-				Spec: podtest.MakePod("").Spec,
+				Spec: podtest.MakePodSpec(),
 			},
 		},
 	}
diff --git a/pkg/registry/core/replicationcontroller/strategy_test.go b/pkg/registry/core/replicationcontroller/strategy_test.go
index bb9e289383221..d22d82458daf0 100644
--- a/pkg/registry/core/replicationcontroller/strategy_test.go
+++ b/pkg/registry/core/replicationcontroller/strategy_test.go
@@ -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{