Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/apis/serving/v1alpha1/revision_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ func (source *RevisionSpec) ConvertTo(ctx context.Context, sink *v1.RevisionSpec
Volumes: source.Volumes,
ImagePullSecrets: source.ImagePullSecrets,
}
case len(source.Containers) == 1:
case len(source.Containers) != 0:
sink.PodSpec = source.PodSpec
case len(source.Containers) > 1:
return apis.ErrMultipleOneOf("containers")
default:
return apis.ErrMissingOneOf("container", "containers")
}
Expand Down
55 changes: 51 additions & 4 deletions pkg/apis/serving/v1alpha1/revision_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestRevisionConversion(t *testing.T) {
t.Errorf("ConvertFrom() = %v", err)
}
if diff := cmp.Diff(test.in, got); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
t.Errorf("Roundtrip (-want, +got): \n%s", diff)
}
})

Expand All @@ -199,12 +199,56 @@ func TestRevisionConversion(t *testing.T) {
t.Errorf("ConvertFrom() = %v", err)
}
if diff := cmp.Diff(test.in, got); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
t.Errorf("Roundtrip (-want, +got): \n%s", diff)
}
})
}
}

func TestRevisionConversionForMultiContainer(t *testing.T) {
input := &Revision{
ObjectMeta: metav1.ObjectMeta{
Name: "multi-container",
},
Spec: RevisionSpec{
RevisionSpec: v1.RevisionSpec{
PodSpec: corev1.PodSpec{
ServiceAccountName: "robocop",
Containers: []corev1.Container{{
Image: "busybox",
}, {
Image: "helloworld",
}},
},
TimeoutSeconds: ptr.Int64(18),
ContainerConcurrency: ptr.Int64(53),
},
},
Status: RevisionStatus{
Status: duckv1.Status{
ObservedGeneration: 1,
Conditions: duckv1.Conditions{{
Type: "Ready",
Status: "True",
}},
},
ServiceName: "foo-bar",
LogURL: "http://logger.io",
},
}
beta := &v1beta1.Revision{}
if err := input.ConvertTo(context.Background(), beta); err != nil {
t.Errorf("ConvertTo() = %v", err)
}
got := &Revision{}
if err := got.ConvertFrom(context.Background(), beta); err != nil {
t.Errorf("ConvertFrom() = %v", err)
}
if diff := cmp.Diff(input, got); diff != "" {
t.Errorf("Roundtrip (-want, +got): \n%s", diff)
}
}

func TestRevisionConversionError(t *testing.T) {
tests := []struct {
name string
Expand All @@ -231,6 +275,9 @@ func TestRevisionConversionError(t *testing.T) {
TimeoutSeconds: ptr.Int64(18),
ContainerConcurrency: ptr.Int64(53),
},
DeprecatedContainer: &corev1.Container{
Image: "busybox",
},
},
Status: RevisionStatus{
Status: duckv1.Status{
Expand All @@ -244,7 +291,7 @@ func TestRevisionConversionError(t *testing.T) {
LogURL: "http://logger.io",
},
},
want: apis.ErrMultipleOneOf("containers"),
want: apis.ErrMultipleOneOf("container", "containers"),
}, {
name: "no containers in podspec",
in: &Revision{
Expand Down Expand Up @@ -286,7 +333,7 @@ func TestRevisionConversionError(t *testing.T) {
t.Errorf("ConvertTo() = %#v, wanted %v", beta, test.want)
}
if diff := cmp.Diff(test.want.Error(), got.Error()); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
t.Errorf("Roundtrip (-want, +got): \n%s", diff)
}
})
}
Expand Down