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
16 changes: 8 additions & 8 deletions apis/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ package apis

import "context"

// ConvertUpViaProxy attempts to convert a specific source to a sink
// ConvertToViaProxy attempts to convert a specific source to a sink
// through a proxy
func ConvertUpViaProxy(
func ConvertToViaProxy(
ctx context.Context,
source, proxy, sink Convertible,
) error {

if err := source.ConvertUp(ctx, proxy); err != nil {
if err := source.ConvertTo(ctx, proxy); err != nil {
return err
}

return proxy.ConvertUp(ctx, sink)
return proxy.ConvertTo(ctx, sink)
}

// ConvertDownViaProxy attempts to convert a specific sink from a source
// ConvertFromViaProxy attempts to convert a specific sink from a source
// through a proxy
func ConvertDownViaProxy(
func ConvertFromViaProxy(
ctx context.Context,
source, proxy, sink Convertible,
) error {

if err := proxy.ConvertDown(ctx, source); err != nil {
if err := proxy.ConvertFrom(ctx, source); err != nil {
return err
}

return sink.ConvertDown(ctx, proxy)
return sink.ConvertFrom(ctx, proxy)
}
24 changes: 12 additions & 12 deletions apis/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
"testing"
)

func TestConvertUpViaProxy(t *testing.T) {
func TestConvertToViaProxy(t *testing.T) {
sink := &testResource{}
proxy := &testResource{}
source := &testResource{proxy: proxy}

err := ConvertUpViaProxy(context.Background(), source, proxy, sink)
err := ConvertToViaProxy(context.Background(), source, proxy, sink)

if err != nil {
t.Errorf("ConvertUpViaProxy returned unexpected err: %s", err)
t.Errorf("ConvertToViaProxy returned unexpected err: %s", err)
}

if source.to != proxy {
Expand All @@ -42,7 +42,7 @@ func TestConvertUpViaProxy(t *testing.T) {
}
}

func TestConvertUpViaProxyError(t *testing.T) {
func TestConvertToViaProxyError(t *testing.T) {
tests := []struct {
name string
source, proxy testResource
Expand All @@ -62,7 +62,7 @@ func TestConvertUpViaProxyError(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := ConvertUpViaProxy(context.Background(),
err := ConvertToViaProxy(context.Background(),
&test.source,
&test.proxy,
nil, /* sink */
Expand All @@ -75,15 +75,15 @@ func TestConvertUpViaProxyError(t *testing.T) {
}
}

func TestConvertDownViaProxy(t *testing.T) {
func TestConvertFromViaProxy(t *testing.T) {
proxy := &testResource{}
sink := &testResource{}
source := &testResource{}

err := ConvertDownViaProxy(context.Background(), source, proxy, sink)
err := ConvertFromViaProxy(context.Background(), source, proxy, sink)

if err != nil {
t.Errorf("ConvertDownViaProxy returned unexpected err: %s", err)
t.Errorf("ConvertFromViaProxy returned unexpected err: %s", err)
}

if proxy.from != source {
Expand All @@ -95,7 +95,7 @@ func TestConvertDownViaProxy(t *testing.T) {
}
}

func TestConvertDownViaProxyError(t *testing.T) {
func TestConvertFromViaProxyError(t *testing.T) {
tests := []struct {
name string
sink, proxy testResource
Expand All @@ -116,7 +116,7 @@ func TestConvertDownViaProxyError(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {

err := ConvertDownViaProxy(context.Background(),
err := ConvertFromViaProxy(context.Background(),
nil, /* source */
&test.proxy,
&test.sink,
Expand All @@ -135,12 +135,12 @@ type testResource struct {

var _ Convertible = (*testResource)(nil)

func (r *testResource) ConvertUp(ctx context.Context, to Convertible) error {
func (r *testResource) ConvertTo(ctx context.Context, to Convertible) error {
r.to = to
return r.err
}

func (r *testResource) ConvertDown(ctx context.Context, from Convertible) error {
func (r *testResource) ConvertFrom(ctx context.Context, from Convertible) error {
r.from = from
return r.err
}
8 changes: 4 additions & 4 deletions apis/duck/v1/addressable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ func (*Addressable) GetFullType() duck.Populatable {
return &AddressableType{}
}

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

// ConvertDown implements apis.Convertible
func (a *Addressable) ConvertDown(ctx context.Context, from apis.Convertible) error {
// ConvertFrom implements apis.Convertible
func (a *Addressable) ConvertFrom(ctx context.Context, from apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", from)
}

Expand Down
12 changes: 6 additions & 6 deletions apis/duck/v1/addressable_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ func TestConversion(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
conv := test.conv
if err := test.addr.ConvertUp(context.Background(), conv); err != nil {
if err := test.addr.ConvertTo(context.Background(), conv); err != nil {
if !test.wantErrUp {
t.Errorf("ConvertUp() = %v", err)
t.Errorf("ConvertTo() = %v", err)
}
} else if test.wantErrUp {
t.Errorf("ConvertUp() = %#v, wanted error", conv)
t.Errorf("ConvertTo() = %#v, wanted error", conv)
}
got := &Addressable{}
if err := got.ConvertDown(context.Background(), conv); err != nil {
if err := got.ConvertFrom(context.Background(), conv); err != nil {
if !test.wantErrDown {
t.Errorf("ConvertDown() = %v", err)
t.Errorf("ConvertFrom() = %v", err)
}
return
} else if test.wantErrDown {
t.Errorf("ConvertDown() = %#v, wanted error", conv)
t.Errorf("ConvertFrom() = %#v, wanted error", conv)
return
}

Expand Down
8 changes: 4 additions & 4 deletions apis/duck/v1alpha1/addressable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (*Addressable) GetFullType() duck.Populatable {
return &AddressableType{}
}

// ConvertUp implements apis.Convertible
func (a *Addressable) ConvertUp(ctx context.Context, to apis.Convertible) error {
// ConvertTo implements apis.Convertible
func (a *Addressable) ConvertTo(ctx context.Context, to apis.Convertible) error {
var url *apis.URL
if a.URL != nil {
url = a.URL
Expand All @@ -101,8 +101,8 @@ func (a *Addressable) ConvertUp(ctx context.Context, to apis.Convertible) error
}
}

// ConvertDown implements apis.Convertible
func (a *Addressable) ConvertDown(ctx context.Context, from apis.Convertible) error {
// ConvertFrom implements apis.Convertible
func (a *Addressable) ConvertFrom(ctx context.Context, from apis.Convertible) error {
switch source := from.(type) {
case *v1.Addressable:
a.URL = source.URL.DeepCopy()
Expand Down
20 changes: 10 additions & 10 deletions apis/duck/v1alpha1/addressable_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ func TestConversion(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
conv := test.conv
if err := test.addr.ConvertUp(context.Background(), conv); err != nil {
if err := test.addr.ConvertTo(context.Background(), conv); err != nil {
if !test.wantErrUp {
t.Errorf("ConvertUp() = %v", err)
t.Errorf("ConvertTo() = %v", err)
}
} else if test.wantErrUp {
t.Errorf("ConvertUp() = %#v, wanted error", conv)
t.Errorf("ConvertTo() = %#v, wanted error", conv)
}
got := &Addressable{}
if err := got.ConvertDown(context.Background(), conv); err != nil {
if err := got.ConvertFrom(context.Background(), conv); err != nil {
if !test.wantErrDown {
t.Errorf("ConvertDown() = %v", err)
t.Errorf("ConvertFrom() = %v", err)
}
return
} else if test.wantErrDown {
t.Errorf("ConvertDown() = %#v, wanted error", conv)
t.Errorf("ConvertFrom() = %#v, wanted error", conv)
return
}

Expand All @@ -164,7 +164,7 @@ func TestConversion(t *testing.T) {
}
}

func TestConvertUp(t *testing.T) {
func TestConvertTo(t *testing.T) {
tests := []struct {
name string
addr *Addressable
Expand Down Expand Up @@ -219,12 +219,12 @@ func TestConvertUp(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := test.conv
if err := test.addr.ConvertUp(context.Background(), got); err != nil {
if err := test.addr.ConvertTo(context.Background(), got); err != nil {
if !test.wantErrUp {
t.Errorf("ConvertUp() = %v", err)
t.Errorf("ConvertTo() = %v", err)
}
} else if test.wantErrUp {
t.Errorf("ConvertUp() = %#v, wanted error", got)
t.Errorf("ConvertTo() = %#v, wanted error", got)
}

if diff := cmp.Diff(test.want, got); diff != "" {
Expand Down
8 changes: 4 additions & 4 deletions apis/duck/v1beta1/addressable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (*Addressable) GetFullType() duck.Populatable {
return &AddressableType{}
}

// ConvertUp implements apis.Convertible
func (a *Addressable) ConvertUp(ctx context.Context, to apis.Convertible) error {
// ConvertTo implements apis.Convertible
func (a *Addressable) ConvertTo(ctx context.Context, to apis.Convertible) error {
switch sink := to.(type) {
case *v1.Addressable:
sink.URL = a.URL.DeepCopy()
Expand All @@ -88,8 +88,8 @@ func (a *Addressable) ConvertUp(ctx context.Context, to apis.Convertible) error
}
}

// ConvertDown implements apis.Convertible
func (a *Addressable) ConvertDown(ctx context.Context, from apis.Convertible) error {
// ConvertFrom implements apis.Convertible
func (a *Addressable) ConvertFrom(ctx context.Context, from apis.Convertible) error {
switch source := from.(type) {
case *v1.Addressable:
a.URL = source.URL.DeepCopy()
Expand Down
12 changes: 6 additions & 6 deletions apis/duck/v1beta1/addressable_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ func TestConversion(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
conv := test.conv
if err := test.addr.ConvertUp(context.Background(), conv); err != nil {
if err := test.addr.ConvertTo(context.Background(), conv); err != nil {
if !test.wantErrUp {
t.Errorf("ConvertUp() = %v", err)
t.Errorf("ConvertTo() = %v", err)
}
} else if test.wantErrUp {
t.Errorf("ConvertUp() = %#v, wanted error", conv)
t.Errorf("ConvertTo() = %#v, wanted error", conv)
}
got := &Addressable{}
if err := got.ConvertDown(context.Background(), conv); err != nil {
if err := got.ConvertFrom(context.Background(), conv); err != nil {
if !test.wantErrDown {
t.Errorf("ConvertDown() = %v", err)
t.Errorf("ConvertFrom() = %v", err)
}
return
} else if test.wantErrDown {
t.Errorf("ConvertDown() = %#v, wanted error", conv)
t.Errorf("ConvertFrom() = %#v, wanted error", conv)
return
}

Expand Down
8 changes: 4 additions & 4 deletions apis/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ type Validatable interface {
// Convertible indicates that a particular type supports conversions to/from
// "higher" versions of the same type.
type Convertible interface {
// ConvertUp up-converts the receiver into `to`.
ConvertUp(ctx context.Context, to Convertible) error
// ConvertTo converts the receiver into `to`.
ConvertTo(ctx context.Context, to Convertible) error

// ConvertDown down-converts from `from` into the receiver.
ConvertDown(ctx context.Context, from Convertible) error
// ConvertFrom converts `from` into the receiver.
ConvertFrom(ctx context.Context, from Convertible) error
}

// Listable indicates that a particular type can be returned via the returned
Expand Down
4 changes: 2 additions & 2 deletions apis/testing/roundtrip/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func roundTripViaHub(t *testing.T, gvk schema.GroupVersionKind, scheme, hubs *ru
return
}

if err := hub.ConvertDown(ctx, obj); err != nil {
if err := hub.ConvertFrom(ctx, obj); err != nil {
t.Errorf("Conversion to hub (%s) failed: %s", hubGVK, err)
}

Expand All @@ -183,7 +183,7 @@ func roundTripViaHub(t *testing.T, gvk schema.GroupVersionKind, scheme, hubs *ru
}

newObj := objForGVK(t, gvk, scheme)
if err := hub.ConvertUp(ctx, newObj); err != nil {
if err := hub.ConvertTo(ctx, newObj); err != nil {
t.Errorf("Conversion from hub (%s) failed: %s", hubGVK, err)
t.Errorf("object: %#v", obj)
return
Expand Down
4 changes: 2 additions & 2 deletions webhook/resourcesemantics/conversion/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
// ConversionController will apply defaults before returning
// the response
type ConvertibleObject interface {
// ConvertUp(ctx)
// ConvertDown(ctx)
// ConvertTo(ctx, to)
// ConvertFrom(ctx, from)
apis.Convertible

// DeepCopyObject()
Expand Down
4 changes: 2 additions & 2 deletions webhook/resourcesemantics/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ func (r *reconciler) convert(

if inGVK.Version == conv.HubVersion {
hub = in
} else if err = hub.ConvertDown(ctx, in); err != nil {
} else if err = hub.ConvertFrom(ctx, in); err != nil {
err = fmt.Errorf("conversion failed to version %s for type %s - %s", outGVK.Version, formatGVK(inGVK), err)
return
}

if outGVK.Version == conv.HubVersion {
out = hub
} else if err = hub.ConvertUp(ctx, out); err != nil {
} else if err = hub.ConvertTo(ctx, out); err != nil {
err = fmt.Errorf("conversion failed to version %s for type %s - %s", outGVK.Version, formatGVK(inGVK), err)
return
}
Expand Down
8 changes: 4 additions & 4 deletions webhook/resourcesemantics/conversion/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,11 @@ func TestConversionFailureToConvert(t *testing.T) {
name string
errorOn string
}{{
name: "error converting down",
errorOn: internal.ErrorConvertDown,
name: "error converting from",
errorOn: internal.ErrorConvertFrom,
}, {
name: "error converting up",
errorOn: internal.ErrorConvertUp,
name: "error converting to",
errorOn: internal.ErrorConvertTo,
}}

for _, test := range tests {
Expand Down
Loading