-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate v1 types #5483
Integrate v1 types #5483
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"fmt" | ||
|
||
"knative.dev/pkg/apis" | ||
"knative.dev/serving/pkg/apis/serving/v1" | ||
"knative.dev/serving/pkg/apis/serving/v1beta1" | ||
) | ||
|
||
|
@@ -33,13 +34,19 @@ func (source *Configuration) ConvertUp(ctx context.Context, obj apis.Convertible | |
return err | ||
} | ||
return source.Status.ConvertUp(ctx, &sink.Status) | ||
case *v1.Configuration: | ||
sink.ObjectMeta = source.ObjectMeta | ||
if err := source.Spec.ConvertUp(ctx, &sink.Spec); err != nil { | ||
return err | ||
} | ||
return source.Status.ConvertUp(ctx, &sink.Status) | ||
default: | ||
return fmt.Errorf("unknown version, got: %T", sink) | ||
} | ||
} | ||
|
||
// ConvertUp helps implement apis.Convertible | ||
func (source *ConfigurationSpec) ConvertUp(ctx context.Context, sink *v1beta1.ConfigurationSpec) error { | ||
func (source *ConfigurationSpec) ConvertUp(ctx context.Context, sink *v1.ConfigurationSpec) error { | ||
if source.DeprecatedBuild != nil { | ||
return ConvertErrorf("build", "build cannot be migrated forward.") | ||
} | ||
|
@@ -56,14 +63,14 @@ func (source *ConfigurationSpec) ConvertUp(ctx context.Context, sink *v1beta1.Co | |
} | ||
|
||
// ConvertUp helps implement apis.Convertible | ||
func (source *ConfigurationStatus) ConvertUp(ctx context.Context, sink *v1beta1.ConfigurationStatus) error { | ||
func (source *ConfigurationStatus) ConvertUp(ctx context.Context, sink *v1.ConfigurationStatus) error { | ||
source.Status.ConvertTo(ctx, &sink.Status) | ||
|
||
return source.ConfigurationStatusFields.ConvertUp(ctx, &sink.ConfigurationStatusFields) | ||
} | ||
|
||
// ConvertUp helps implement apis.Convertible | ||
func (source *ConfigurationStatusFields) ConvertUp(ctx context.Context, sink *v1beta1.ConfigurationStatusFields) error { | ||
func (source *ConfigurationStatusFields) ConvertUp(ctx context.Context, sink *v1.ConfigurationStatusFields) error { | ||
sink.LatestReadyRevisionName = source.LatestReadyRevisionName | ||
sink.LatestCreatedRevisionName = source.LatestCreatedRevisionName | ||
return nil | ||
|
@@ -78,26 +85,32 @@ func (sink *Configuration) ConvertDown(ctx context.Context, obj apis.Convertible | |
return err | ||
} | ||
return sink.Status.ConvertDown(ctx, source.Status) | ||
case *v1.Configuration: | ||
sink.ObjectMeta = source.ObjectMeta | ||
if err := sink.Spec.ConvertDown(ctx, source.Spec); err != nil { | ||
return err | ||
} | ||
return sink.Status.ConvertDown(ctx, source.Status) | ||
default: | ||
return fmt.Errorf("unknown version, got: %T", source) | ||
} | ||
} | ||
|
||
// ConvertDown helps implement apis.Convertible | ||
func (sink *ConfigurationSpec) ConvertDown(ctx context.Context, source v1beta1.ConfigurationSpec) error { | ||
func (sink *ConfigurationSpec) ConvertDown(ctx context.Context, source v1.ConfigurationSpec) error { | ||
sink.Template = &RevisionTemplateSpec{} | ||
return sink.Template.ConvertDown(ctx, source.Template) | ||
} | ||
|
||
// ConvertDown helps implement apis.Convertible | ||
func (sink *ConfigurationStatus) ConvertDown(ctx context.Context, source v1beta1.ConfigurationStatus) error { | ||
func (sink *ConfigurationStatus) ConvertDown(ctx context.Context, source v1.ConfigurationStatus) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint naming: receiver name sink should be consistent with previous receiver name source for ConfigurationStatus. More info. |
||
source.Status.ConvertTo(ctx, &sink.Status) | ||
|
||
return sink.ConfigurationStatusFields.ConvertDown(ctx, source.ConfigurationStatusFields) | ||
} | ||
|
||
// ConvertDown helps implement apis.Convertible | ||
func (sink *ConfigurationStatusFields) ConvertDown(ctx context.Context, source v1beta1.ConfigurationStatusFields) error { | ||
func (sink *ConfigurationStatusFields) ConvertDown(ctx context.Context, source v1.ConfigurationStatusFields) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint naming: receiver name sink should be consistent with previous receiver name source for ConfigurationStatusFields. More info. |
||
sink.LatestReadyRevisionName = source.LatestReadyRevisionName | ||
sink.LatestCreatedRevisionName = source.LatestCreatedRevisionName | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,8 +25,10 @@ import ( | |||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
"k8s.io/apimachinery/pkg/runtime" | ||||||
|
||||||
"knative.dev/pkg/apis" | ||||||
duckv1 "knative.dev/pkg/apis/duck/v1" | ||||||
"knative.dev/pkg/ptr" | ||||||
"knative.dev/serving/pkg/apis/serving/v1" | ||||||
"knative.dev/serving/pkg/apis/serving/v1beta1" | ||||||
) | ||||||
|
||||||
|
@@ -42,7 +44,34 @@ func TestConfigurationConversionBadType(t *testing.T) { | |||||
} | ||||||
} | ||||||
|
||||||
func TestConfigurationConversionTemplateError(t *testing.T) { | ||||||
tests := []struct { | ||||||
name string | ||||||
cs *ConfigurationSpec | ||||||
}{{ | ||||||
name: "multiple of", | ||||||
cs: &ConfigurationSpec{ | ||||||
Template: &RevisionTemplateSpec{}, | ||||||
DeprecatedRevisionTemplate: &RevisionTemplateSpec{}, | ||||||
}, | ||||||
}, { | ||||||
name: "missing", | ||||||
cs: &ConfigurationSpec{}, | ||||||
}} | ||||||
|
||||||
for _, test := range tests { | ||||||
t.Run(test.name, func(t *testing.T) { | ||||||
result := &v1.ConfigurationSpec{} | ||||||
if err := test.cs.ConvertUp(context.Background(), result); err == nil { | ||||||
t.Errorf("ConvertUp() = %#v, wanted error", result) | ||||||
} | ||||||
}) | ||||||
} | ||||||
} | ||||||
|
||||||
func TestConfigurationConversion(t *testing.T) { | ||||||
versions := []apis.Convertible{&v1.Configuration{}, &v1beta1.Configuration{}} | ||||||
|
||||||
tests := []struct { | ||||||
name string | ||||||
in *Configuration | ||||||
|
@@ -58,7 +87,7 @@ func TestConfigurationConversion(t *testing.T) { | |||||
Spec: ConfigurationSpec{ | ||||||
Template: &RevisionTemplateSpec{ | ||||||
Spec: RevisionSpec{ | ||||||
RevisionSpec: v1beta1.RevisionSpec{ | ||||||
RevisionSpec: v1.RevisionSpec{ | ||||||
PodSpec: corev1.PodSpec{ | ||||||
ServiceAccountName: "robocop", | ||||||
Containers: []corev1.Container{{ | ||||||
|
@@ -113,7 +142,7 @@ func TestConfigurationConversion(t *testing.T) { | |||||
}, | ||||||
Template: &RevisionTemplateSpec{ | ||||||
Spec: RevisionSpec{ | ||||||
RevisionSpec: v1beta1.RevisionSpec{ | ||||||
RevisionSpec: v1.RevisionSpec{ | ||||||
PodSpec: corev1.PodSpec{ | ||||||
Containers: []corev1.Container{{ | ||||||
Image: "busybox", | ||||||
|
@@ -149,55 +178,57 @@ func TestConfigurationConversion(t *testing.T) { | |||||
} | ||||||
|
||||||
for _, test := range tests { | ||||||
t.Run(test.name, func(t *testing.T) { | ||||||
beta := &v1beta1.Configuration{} | ||||||
if err := test.in.ConvertUp(context.Background(), beta); err != nil { | ||||||
if test.badField != "" { | ||||||
cce, ok := err.(*CannotConvertError) | ||||||
if ok && cce.Field == test.badField { | ||||||
return | ||||||
for _, version := range versions { | ||||||
t.Run(test.name, func(t *testing.T) { | ||||||
ver := version | ||||||
if err := test.in.ConvertUp(context.Background(), ver); err != nil { | ||||||
if test.badField != "" { | ||||||
cce, ok := err.(*CannotConvertError) | ||||||
if ok && cce.Field == test.badField { | ||||||
return | ||||||
} | ||||||
} | ||||||
t.Errorf("ConvertUp() = %v", err) | ||||||
} else if test.badField != "" { | ||||||
t.Errorf("ConvertUp() = %#v, wanted bad field %q", ver, | ||||||
test.badField) | ||||||
return | ||||||
} | ||||||
t.Errorf("ConvertUp() = %v", err) | ||||||
} else if test.badField != "" { | ||||||
t.Errorf("CovnertUp() = %#v, wanted bad field %q", beta, | ||||||
test.badField) | ||||||
return | ||||||
} | ||||||
got := &Configuration{} | ||||||
if err := got.ConvertDown(context.Background(), beta); err != nil { | ||||||
t.Errorf("ConvertDown() = %v", err) | ||||||
} | ||||||
if diff := cmp.Diff(test.in, got); diff != "" { | ||||||
t.Errorf("roundtrip (-want, +got) = %v", diff) | ||||||
} | ||||||
}) | ||||||
got := &Configuration{} | ||||||
if err := got.ConvertDown(context.Background(), ver); err != nil { | ||||||
t.Errorf("ConvertDown() = %v", err) | ||||||
} | ||||||
if diff := cmp.Diff(test.in, got); diff != "" { | ||||||
t.Errorf("roundtrip (-want, +got) = %v", diff) | ||||||
} | ||||||
}) | ||||||
|
||||||
// A variant of the test that uses `revisionTemplate:` and `container:`, | ||||||
// but end up with what we have above anyways. | ||||||
t.Run(test.name+" (deprecated)", func(t *testing.T) { | ||||||
start := toDeprecated(test.in) | ||||||
beta := &v1beta1.Configuration{} | ||||||
if err := start.ConvertUp(context.Background(), beta); err != nil { | ||||||
if test.badField != "" { | ||||||
cce, ok := err.(*CannotConvertError) | ||||||
if ok && cce.Field == test.badField { | ||||||
return | ||||||
// A variant of the test that uses `revisionTemplate:` and `container:`, | ||||||
// but end up with what we have above anyways. | ||||||
t.Run(test.name+" (deprecated)", func(t *testing.T) { | ||||||
ver := version | ||||||
start := toDeprecated(test.in) | ||||||
if err := start.ConvertUp(context.Background(), ver); err != nil { | ||||||
if test.badField != "" { | ||||||
cce, ok := err.(*CannotConvertError) | ||||||
if ok && cce.Field == test.badField { | ||||||
return | ||||||
} | ||||||
} | ||||||
t.Errorf("ConvertUp() = %v", err) | ||||||
} else if test.badField != "" { | ||||||
t.Errorf("CovnertUp() = %#v, wanted bad field %q", ver, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
test.badField) | ||||||
return | ||||||
} | ||||||
t.Errorf("ConvertUp() = %v", err) | ||||||
} else if test.badField != "" { | ||||||
t.Errorf("CovnertUp() = %#v, wanted bad field %q", beta, | ||||||
test.badField) | ||||||
return | ||||||
} | ||||||
got := &Configuration{} | ||||||
if err := got.ConvertDown(context.Background(), beta); err != nil { | ||||||
t.Errorf("ConvertDown() = %v", err) | ||||||
} | ||||||
if diff := cmp.Diff(test.in, got); diff != "" { | ||||||
t.Errorf("roundtrip (-want, +got) = %v", diff) | ||||||
} | ||||||
}) | ||||||
got := &Configuration{} | ||||||
if err := got.ConvertDown(context.Background(), ver); err != nil { | ||||||
t.Errorf("ConvertDown() = %v", err) | ||||||
} | ||||||
if diff := cmp.Diff(test.in, got); diff != "" { | ||||||
t.Errorf("roundtrip (-want, +got) = %v", diff) | ||||||
} | ||||||
}) | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint naming: receiver name sink should be consistent with previous receiver name source for ConfigurationSpec. More info.