Skip to content

Commit

Permalink
Move to corev1.PodSpec now that vN-1 supports the containers field. (k…
Browse files Browse the repository at this point in the history
…native#4221)

Previously we defined our own partial PodSpec because the corev1 version
lacks `omitempty` and appears as `containers: null` in requests from generated
clients, even if unspecified, which would have broken webhook validation.

Now that the field has been out for a release, we can switch to the common
PodSpec.
  • Loading branch information
mattmoor authored and joshrider committed Jun 5, 2019
1 parent 284820d commit d53b2b8
Show file tree
Hide file tree
Showing 31 changed files with 129 additions and 215 deletions.
8 changes: 5 additions & 3 deletions pkg/apis/serving/k8s_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ func validateEnvFrom(envFromList []corev1.EnvFromSource) *apis.FieldError {
}

func ValidatePodSpec(ps corev1.PodSpec) *apis.FieldError {
if equality.Semantic.DeepEqual(ps, corev1.PodSpec{}) {
return apis.ErrMissingField(apis.CurrentField)
}
// This is inlined, and so it makes for a less meaningful
// error message.
// if equality.Semantic.DeepEqual(ps, corev1.PodSpec{}) {
// return apis.ErrMissingField(apis.CurrentField)
// }

errs := apis.CheckDisallowedFields(ps, *PodSpecMask(&ps))

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/serving/k8s_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestPodSpecValidation(t *testing.T) {
ps: corev1.PodSpec{
Containers: []corev1.Container{},
},
want: apis.ErrMissingField(apis.CurrentField),
want: apis.ErrMissingField("containers"),
}, {
name: "missing container",
ps: corev1.PodSpec{
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/serving/v1alpha1/configuration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestConfigurationConversion(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestConfigurationConversion(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "busybox",
}},
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/serving/v1alpha1/configuration_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestConfigurationDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "busybox",
Resources: defaultResources,
Expand All @@ -111,7 +111,7 @@ func TestConfigurationDefaulting(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{}},
},
},
Expand All @@ -125,7 +125,7 @@ func TestConfigurationDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Resources: defaultResources,
}},
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/serving/v1alpha1/configuration_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestConfigurationSpecValidation(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "hellworld",
}},
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestConfigurationSpecValidation(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "hellworld",
}},
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/serving/v1alpha1/revision_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (source *RevisionSpec) ConvertUp(ctx context.Context, sink *v1beta1.Revisio
case source.DeprecatedContainer != nil && len(source.Containers) > 0:
return apis.ErrMultipleOneOf("container", "containers")
case source.DeprecatedContainer != nil:
sink.PodSpec = v1beta1.PodSpec{
sink.PodSpec = corev1.PodSpec{
ServiceAccountName: source.ServiceAccountName,
Containers: []corev1.Container{*source.DeprecatedContainer},
Volumes: source.Volumes,
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1alpha1/revision_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestRevisionConversion(t *testing.T) {
},
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestRevisionConversion(t *testing.T) {
Name: "foo",
},
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestRevisionConversionError(t *testing.T) {
},
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestRevisionConversionError(t *testing.T) {
},
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/serving/v1alpha1/revision_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestRevisionDefaulting(t *testing.T) {
want: &Revision{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "foo",
VolumeMounts: []corev1.VolumeMount{{
Expand All @@ -176,7 +176,7 @@ func TestRevisionDefaulting(t *testing.T) {
RevisionSpec: v1beta1.RevisionSpec{
ContainerConcurrency: 1,
TimeoutSeconds: ptr.Int64(99),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "foo",
Resources: defaultResources,
Expand All @@ -193,7 +193,7 @@ func TestRevisionDefaulting(t *testing.T) {
RevisionSpec: v1beta1.RevisionSpec{
ContainerConcurrency: 1,
TimeoutSeconds: ptr.Int64(99),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "foo",
Resources: defaultResources,
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/serving/v1alpha1/revision_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestRevisionSpecValidation(t *testing.T) {
name: "missing container",
rs: &RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Volumes: []corev1.Volume{{
Name: "the-name",
VolumeSource: corev1.VolumeSource{
Expand All @@ -128,7 +128,7 @@ func TestRevisionSpecValidation(t *testing.T) {
}},
},
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Volumes: []corev1.Volume{{
Name: "the-name",
VolumeSource: corev1.VolumeSource{
Expand All @@ -153,7 +153,7 @@ func TestRevisionSpecValidation(t *testing.T) {
}},
},
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Volumes: []corev1.Volume{{
Name: "the-name",
VolumeSource: corev1.VolumeSource{
Expand Down
22 changes: 11 additions & 11 deletions pkg/apis/serving/v1alpha1/service_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestServiceConversion(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Volumes: []corev1.Volume{{
Name: "the-name",
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Volumes: []corev1.Volume{{
Name: "the-name",
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -370,7 +370,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Volumes: []corev1.Volume{{
Name: "the-name",
Expand Down Expand Up @@ -410,7 +410,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Volumes: []corev1.Volume{{
Name: "the-name",
Expand Down Expand Up @@ -515,7 +515,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down Expand Up @@ -579,7 +579,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Volumes: []corev1.Volume{{
Name: "the-name",
Expand Down Expand Up @@ -619,7 +619,7 @@ func TestServiceConversionFromDeprecated(t *testing.T) {
Template: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
Expand Down
22 changes: 11 additions & 11 deletions pkg/apis/serving/v1alpha1/service_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestServiceDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "busybox",
Resources: defaultResources,
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestServiceDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "busybox",
Resources: defaultResources,
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestServiceDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Resources: defaultResources,
}},
Expand Down Expand Up @@ -418,7 +418,7 @@ func TestServiceDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Resources: defaultResources,
}},
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestServiceDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Resources: defaultResources,
}},
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestServiceDefaulting(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "blah",
}},
Expand All @@ -567,7 +567,7 @@ func TestServiceDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "blah",
Resources: defaultResources,
Expand Down Expand Up @@ -629,7 +629,7 @@ func TestServiceDefaulting(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "blah",
}},
Expand All @@ -651,7 +651,7 @@ func TestServiceDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "blah",
Resources: defaultResources,
Expand Down Expand Up @@ -679,7 +679,7 @@ func TestServiceDefaulting(t *testing.T) {
DeprecatedRevisionTemplate: &RevisionTemplateSpec{
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "blah",
}},
Expand All @@ -704,7 +704,7 @@ func TestServiceDefaulting(t *testing.T) {
Spec: RevisionSpec{
RevisionSpec: v1beta1.RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
PodSpec: v1beta1.PodSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "blah",
Resources: defaultResources,
Expand Down
Loading

0 comments on commit d53b2b8

Please sign in to comment.