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: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro
},
},

// A function that infuses the context passed to ConvertUp/ConvertDown/SetDefaults with custom metadata.
// A function that infuses the context passed to ConvertTo/ConvertFrom/SetDefaults with custom metadata.
func(ctx context.Context) context.Context {
return ctx
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1/configuration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"knative.dev/pkg/apis"
)

// ConvertUp implements apis.Convertible
func (source *Configuration) ConvertUp(ctx context.Context, sink apis.Convertible) error {
// ConvertTo implements apis.Convertible
func (source *Configuration) ConvertTo(ctx context.Context, sink apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", sink)
}

// ConvertDown implements apis.Convertible
func (sink *Configuration) ConvertDown(ctx context.Context, source apis.Convertible) error {
// ConvertFrom implements apis.Convertible
func (sink *Configuration) ConvertFrom(ctx context.Context, source apis.Convertible) error {
Comment thread
dprotaso marked this conversation as resolved.
return fmt.Errorf("v1 is the highest known version, got: %T", source)
}
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1/configuration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
func TestConfigurationConversionBadType(t *testing.T) {
good, bad := &Configuration{}, &Service{}

if err := good.ConvertUp(context.Background(), bad); err == nil {
t.Errorf("ConvertUp() = %#v, wanted error", bad)
if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
}

if err := good.ConvertDown(context.Background(), bad); err == nil {
t.Errorf("ConvertDown() = %#v, wanted error", good)
if err := good.ConvertFrom(context.Background(), bad); err == nil {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1/revision_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"knative.dev/pkg/apis"
)

// ConvertUp implements apis.Convertible
func (source *Revision) ConvertUp(ctx context.Context, sink apis.Convertible) error {
// ConvertTo implements apis.Convertible
func (source *Revision) ConvertTo(ctx context.Context, sink apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", sink)
}

// ConvertDown implements apis.Convertible
func (sink *Revision) ConvertDown(ctx context.Context, source apis.Convertible) error {
// ConvertFrom implements apis.Convertible
func (sink *Revision) ConvertFrom(ctx context.Context, source apis.Convertible) error {
Comment thread
dprotaso marked this conversation as resolved.
return fmt.Errorf("v1 is the highest known version, got: %T", source)
}
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1/revision_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
func TestRevisionConversionBadType(t *testing.T) {
good, bad := &Revision{}, &Service{}

if err := good.ConvertUp(context.Background(), bad); err == nil {
t.Errorf("ConvertUp() = %#v, wanted error", bad)
if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
}

if err := good.ConvertDown(context.Background(), bad); err == nil {
t.Errorf("ConvertDown() = %#v, wanted error", good)
if err := good.ConvertFrom(context.Background(), bad); err == nil {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1/route_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"knative.dev/pkg/apis"
)

// ConvertUp implements apis.Convertible
func (source *Route) ConvertUp(ctx context.Context, sink apis.Convertible) error {
// ConvertTo implements apis.Convertible
func (source *Route) ConvertTo(ctx context.Context, sink apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", sink)
}

// ConvertDown implements apis.Convertible
func (sink *Route) ConvertDown(ctx context.Context, source apis.Convertible) error {
// ConvertFrom implements apis.Convertible
func (sink *Route) ConvertFrom(ctx context.Context, source apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", source)
}
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1/route_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
func TestRouteConversionBadType(t *testing.T) {
good, bad := &Route{}, &Service{}

if err := good.ConvertUp(context.Background(), bad); err == nil {
t.Errorf("ConvertUp() = %#v, wanted error", bad)
if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
}

if err := good.ConvertDown(context.Background(), bad); err == nil {
t.Errorf("ConvertDown() = %#v, wanted error", good)
if err := good.ConvertFrom(context.Background(), bad); err == nil {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1/service_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"knative.dev/pkg/apis"
)

// ConvertUp implements apis.Convertible
func (source *Service) ConvertUp(ctx context.Context, sink apis.Convertible) error {
// ConvertTo implements apis.Convertible
func (source *Service) ConvertTo(ctx context.Context, sink apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", sink)
}

// ConvertDown implements apis.Convertible
func (sink *Service) ConvertDown(ctx context.Context, source apis.Convertible) error {
// ConvertFrom implements apis.Convertible
func (sink *Service) ConvertFrom(ctx context.Context, source apis.Convertible) error {
Comment thread
dprotaso marked this conversation as resolved.
return fmt.Errorf("v1 is the highest known version, got: %T", source)
}
8 changes: 4 additions & 4 deletions pkg/apis/serving/v1/service_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
func TestServiceConversionBadType(t *testing.T) {
good, bad := &Service{}, &Revision{}

if err := good.ConvertUp(context.Background(), bad); err == nil {
t.Errorf("ConvertUp() = %#v, wanted error", bad)
if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
}

if err := good.ConvertDown(context.Background(), bad); err == nil {
t.Errorf("ConvertDown() = %#v, wanted error", good)
if err := good.ConvertFrom(context.Background(), bad); err == nil {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}
54 changes: 27 additions & 27 deletions pkg/apis/serving/v1alpha1/configuration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,79 +24,79 @@ import (
"knative.dev/serving/pkg/apis/serving/v1beta1"
)

// ConvertUp implements apis.Convertible
func (source *Configuration) ConvertUp(ctx context.Context, obj apis.Convertible) error {
// ConvertTo implements apis.Convertible
func (source *Configuration) ConvertTo(ctx context.Context, obj apis.Convertible) error {
switch sink := obj.(type) {
case *v1beta1.Configuration:
sink.ObjectMeta = source.ObjectMeta
if err := source.Spec.ConvertUp(ctx, &sink.Spec); err != nil {
if err := source.Spec.ConvertTo(ctx, &sink.Spec); err != nil {
return err
}
return source.Status.ConvertUp(ctx, &sink.Status)
return source.Status.ConvertTo(ctx, &sink.Status)
default:
return apis.ConvertUpViaProxy(ctx, source, &v1beta1.Configuration{}, sink)
return apis.ConvertToViaProxy(ctx, source, &v1beta1.Configuration{}, sink)
}
}

// ConvertUp helps implement apis.Convertible
func (source *ConfigurationSpec) ConvertUp(ctx context.Context, sink *v1.ConfigurationSpec) error {
// ConvertTo helps implement apis.Convertible
func (source *ConfigurationSpec) ConvertTo(ctx context.Context, sink *v1.ConfigurationSpec) error {
if source.DeprecatedBuild != nil {
return ConvertErrorf("build", "build cannot be migrated forward.")
}
switch {
case source.DeprecatedRevisionTemplate != nil && source.Template != nil:
return apis.ErrMultipleOneOf("revisionTemplate", "template")
case source.DeprecatedRevisionTemplate != nil:
return source.DeprecatedRevisionTemplate.ConvertUp(ctx, &sink.Template)
return source.DeprecatedRevisionTemplate.ConvertTo(ctx, &sink.Template)
case source.Template != nil:
return source.Template.ConvertUp(ctx, &sink.Template)
return source.Template.ConvertTo(ctx, &sink.Template)
default:
return apis.ErrMissingOneOf("revisionTemplate", "template")
}
}

// ConvertUp helps implement apis.Convertible
func (source *ConfigurationStatus) ConvertUp(ctx context.Context, sink *v1.ConfigurationStatus) error {
// ConvertTo helps implement apis.Convertible
func (source *ConfigurationStatus) ConvertTo(ctx context.Context, sink *v1.ConfigurationStatus) error {
source.Status.ConvertTo(ctx, &sink.Status, v1.IsConfigurationCondition)
return source.ConfigurationStatusFields.ConvertUp(ctx, &sink.ConfigurationStatusFields)
return source.ConfigurationStatusFields.ConvertTo(ctx, &sink.ConfigurationStatusFields)
}

// ConvertUp helps implement apis.Convertible
func (source *ConfigurationStatusFields) ConvertUp(ctx context.Context, sink *v1.ConfigurationStatusFields) error {
// ConvertTo helps implement apis.Convertible
func (source *ConfigurationStatusFields) ConvertTo(ctx context.Context, sink *v1.ConfigurationStatusFields) error {
sink.LatestReadyRevisionName = source.LatestReadyRevisionName
sink.LatestCreatedRevisionName = source.LatestCreatedRevisionName
return nil
}

// ConvertDown implements apis.Convertible
func (sink *Configuration) ConvertDown(ctx context.Context, obj apis.Convertible) error {
// ConvertFrom implements apis.Convertible
func (sink *Configuration) ConvertFrom(ctx context.Context, obj apis.Convertible) error {
Comment thread
dprotaso marked this conversation as resolved.
switch source := obj.(type) {
case *v1beta1.Configuration:
sink.ObjectMeta = source.ObjectMeta
if err := sink.Spec.ConvertDown(ctx, source.Spec); err != nil {
if err := sink.Spec.ConvertFrom(ctx, source.Spec); err != nil {
return err
}
return sink.Status.ConvertDown(ctx, source.Status)
return sink.Status.ConvertFrom(ctx, source.Status)
default:
return apis.ConvertDownViaProxy(ctx, source, &v1beta1.Configuration{}, sink)
return apis.ConvertFromViaProxy(ctx, source, &v1beta1.Configuration{}, sink)
}
}

// ConvertDown helps implement apis.Convertible
func (sink *ConfigurationSpec) ConvertDown(ctx context.Context, source v1.ConfigurationSpec) error {
// ConvertFrom helps implement apis.Convertible
func (sink *ConfigurationSpec) ConvertFrom(ctx context.Context, source v1.ConfigurationSpec) error {
Comment thread
dprotaso marked this conversation as resolved.
sink.Template = &RevisionTemplateSpec{}
return sink.Template.ConvertDown(ctx, source.Template)
return sink.Template.ConvertFrom(ctx, source.Template)
}

// ConvertDown helps implement apis.Convertible
func (sink *ConfigurationStatus) ConvertDown(ctx context.Context, source v1.ConfigurationStatus) error {
// ConvertFrom helps implement apis.Convertible
func (sink *ConfigurationStatus) ConvertFrom(ctx context.Context, source v1.ConfigurationStatus) error {
Comment thread
dprotaso marked this conversation as resolved.
source.Status.ConvertTo(ctx, &sink.Status, v1.IsConfigurationCondition)

return sink.ConfigurationStatusFields.ConvertDown(ctx, source.ConfigurationStatusFields)
return sink.ConfigurationStatusFields.ConvertFrom(ctx, source.ConfigurationStatusFields)
}

// ConvertDown helps implement apis.Convertible
func (sink *ConfigurationStatusFields) ConvertDown(ctx context.Context, source v1.ConfigurationStatusFields) error {
// ConvertFrom helps implement apis.Convertible
func (sink *ConfigurationStatusFields) ConvertFrom(ctx context.Context, source v1.ConfigurationStatusFields) error {
Comment thread
dprotaso marked this conversation as resolved.
sink.LatestReadyRevisionName = source.LatestReadyRevisionName
sink.LatestCreatedRevisionName = source.LatestCreatedRevisionName
return nil
Expand Down
30 changes: 15 additions & 15 deletions pkg/apis/serving/v1alpha1/configuration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import (
func TestConfigurationConversionBadType(t *testing.T) {
good, bad := &Configuration{}, &Service{}

if err := good.ConvertUp(context.Background(), bad); err == nil {
t.Errorf("ConvertUp() = %#v, wanted error", bad)
if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
}

if err := good.ConvertDown(context.Background(), bad); err == nil {
t.Errorf("ConvertDown() = %#v, wanted error", good)
if err := good.ConvertFrom(context.Background(), bad); err == nil {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}

Expand All @@ -62,8 +62,8 @@ func TestConfigurationConversionTemplateError(t *testing.T) {
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)
if err := test.cs.ConvertTo(context.Background(), result); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", result)
}
})
}
Expand Down Expand Up @@ -184,22 +184,22 @@ func TestConfigurationConversion(t *testing.T) {
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 err := test.in.ConvertTo(context.Background(), ver); err != nil {
if test.badField != "" {
cce, ok := err.(*CannotConvertError)
if ok && cce.Field == test.badField {
return
}
}
t.Errorf("ConvertUp() = %v", err)
t.Errorf("ConvertTo() = %v", err)
} else if test.badField != "" {
t.Errorf("ConvertUp() = %#v, wanted bad field %q", ver,
t.Errorf("ConvertTo() = %#v, wanted bad field %q", ver,
test.badField)
return
}
got := &Configuration{}
if err := got.ConvertDown(context.Background(), ver); err != nil {
t.Errorf("ConvertDown() = %v", err)
if err := got.ConvertFrom(context.Background(), ver); err != nil {
t.Errorf("ConvertFrom() = %v", err)
}
if diff := cmp.Diff(test.in, got); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
Expand All @@ -211,22 +211,22 @@ func TestConfigurationConversion(t *testing.T) {
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 err := start.ConvertTo(context.Background(), ver); err != nil {
if test.badField != "" {
cce, ok := err.(*CannotConvertError)
if ok && cce.Field == test.badField {
return
}
}
t.Errorf("ConvertUp() = %v", err)
t.Errorf("ConvertTo() = %v", err)
} else if test.badField != "" {
t.Errorf("CovnertUp() = %#v, wanted bad field %q", ver,
test.badField)
return
}
got := &Configuration{}
if err := got.ConvertDown(context.Background(), ver); err != nil {
t.Errorf("ConvertDown() = %v", err)
if err := got.ConvertFrom(context.Background(), ver); err != nil {
t.Errorf("ConvertFrom() = %v", err)
}
if diff := cmp.Diff(test.in, got); diff != "" {
t.Errorf("roundtrip (-want, +got) = %v", diff)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/serving/v1alpha1/configuration_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func (c *Configuration) SetDefaults(ctx context.Context) {
func (cs *ConfigurationSpec) SetDefaults(ctx context.Context) {
if v1.IsUpgradeViaDefaulting(ctx) {
v := v1.ConfigurationSpec{}
if cs.ConvertUp(ctx, &v) == nil {
if cs.ConvertTo(ctx, &v) == nil {
alpha := ConfigurationSpec{}
if alpha.ConvertDown(ctx, v) == nil {
if alpha.ConvertFrom(ctx, v) == nil {
*cs = alpha
}
}
Expand Down
Loading