From 6cfaa1056965e7d5c005ed76249dc194c7ac1bc9 Mon Sep 17 00:00:00 2001 From: Dave Protasowski Date: Mon, 24 Feb 2020 11:35:31 -0500 Subject: [PATCH] Fixed #1057 - Rename ConvertUp/Down to ConvertTo/From --- apis/convert.go | 16 +++--- apis/convert_test.go | 24 ++++----- apis/duck/v1/addressable_types.go | 8 +-- apis/duck/v1/addressable_types_test.go | 12 ++--- apis/duck/v1alpha1/addressable_types.go | 8 +-- apis/duck/v1alpha1/addressable_types_test.go | 20 +++---- apis/duck/v1beta1/addressable_types.go | 8 +-- apis/duck/v1beta1/addressable_types_test.go | 12 ++--- apis/interfaces.go | 8 +-- apis/testing/roundtrip/roundtrip.go | 4 +- .../conversion/controller.go | 4 +- .../conversion/conversion.go | 4 +- .../conversion/conversion_test.go | 8 +-- .../conversion/internal/types.go | 52 +++++++++---------- 14 files changed, 94 insertions(+), 94 deletions(-) diff --git a/apis/convert.go b/apis/convert.go index e67a379303..d6a28a0727 100644 --- a/apis/convert.go +++ b/apis/convert.go @@ -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) } diff --git a/apis/convert_test.go b/apis/convert_test.go index 9484a37f71..ac0475f827 100644 --- a/apis/convert_test.go +++ b/apis/convert_test.go @@ -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 { @@ -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 @@ -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 */ @@ -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 { @@ -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 @@ -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, @@ -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 } diff --git a/apis/duck/v1/addressable_types.go b/apis/duck/v1/addressable_types.go index e5955aeb69..579e6976ee 100644 --- a/apis/duck/v1/addressable_types.go +++ b/apis/duck/v1/addressable_types.go @@ -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) } diff --git a/apis/duck/v1/addressable_types_test.go b/apis/duck/v1/addressable_types_test.go index dc26f4788f..d65165d777 100644 --- a/apis/duck/v1/addressable_types_test.go +++ b/apis/duck/v1/addressable_types_test.go @@ -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 } diff --git a/apis/duck/v1alpha1/addressable_types.go b/apis/duck/v1alpha1/addressable_types.go index d0a81db8fc..70c9b0135c 100644 --- a/apis/duck/v1alpha1/addressable_types.go +++ b/apis/duck/v1alpha1/addressable_types.go @@ -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 @@ -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() diff --git a/apis/duck/v1alpha1/addressable_types_test.go b/apis/duck/v1alpha1/addressable_types_test.go index cc1c1327c8..0daabf9931 100644 --- a/apis/duck/v1alpha1/addressable_types_test.go +++ b/apis/duck/v1alpha1/addressable_types_test.go @@ -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 } @@ -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 @@ -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 != "" { diff --git a/apis/duck/v1beta1/addressable_types.go b/apis/duck/v1beta1/addressable_types.go index 6093bd0338..3e3f828676 100644 --- a/apis/duck/v1beta1/addressable_types.go +++ b/apis/duck/v1beta1/addressable_types.go @@ -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() @@ -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() diff --git a/apis/duck/v1beta1/addressable_types_test.go b/apis/duck/v1beta1/addressable_types_test.go index dbb6bb0f00..7cadabd39b 100644 --- a/apis/duck/v1beta1/addressable_types_test.go +++ b/apis/duck/v1beta1/addressable_types_test.go @@ -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 } diff --git a/apis/interfaces.go b/apis/interfaces.go index fef69d8b31..b4d350f88f 100644 --- a/apis/interfaces.go +++ b/apis/interfaces.go @@ -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 diff --git a/apis/testing/roundtrip/roundtrip.go b/apis/testing/roundtrip/roundtrip.go index 9410d99422..ccc030f7eb 100644 --- a/apis/testing/roundtrip/roundtrip.go +++ b/apis/testing/roundtrip/roundtrip.go @@ -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) } @@ -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 diff --git a/webhook/resourcesemantics/conversion/controller.go b/webhook/resourcesemantics/conversion/controller.go index bb06f2e216..b21003e0a8 100644 --- a/webhook/resourcesemantics/conversion/controller.go +++ b/webhook/resourcesemantics/conversion/controller.go @@ -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() diff --git a/webhook/resourcesemantics/conversion/conversion.go b/webhook/resourcesemantics/conversion/conversion.go index afc3915f12..e829ed75cf 100644 --- a/webhook/resourcesemantics/conversion/conversion.go +++ b/webhook/resourcesemantics/conversion/conversion.go @@ -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 } diff --git a/webhook/resourcesemantics/conversion/conversion_test.go b/webhook/resourcesemantics/conversion/conversion_test.go index 0841ffa403..51a87e20d1 100644 --- a/webhook/resourcesemantics/conversion/conversion_test.go +++ b/webhook/resourcesemantics/conversion/conversion_test.go @@ -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 { diff --git a/webhook/resourcesemantics/conversion/internal/types.go b/webhook/resourcesemantics/conversion/internal/types.go index 764ddc9257..52f67006ac 100644 --- a/webhook/resourcesemantics/conversion/internal/types.go +++ b/webhook/resourcesemantics/conversion/internal/types.go @@ -42,13 +42,13 @@ const ( // will cause json unmarshalling of the resource to fail ErrorUnmarshal = "unmarshal" - // ErrorConvertUp when assigned to the Spec.Property of the ErrorResource - // will cause ConvertUp to fail - ErrorConvertUp = "convertUp" + // ErrorConvertTo when assigned to the Spec.Property of the ErrorResource + // will cause ConvertTo to fail + ErrorConvertTo = "convertTo" - // ErrorConvertDown when assigned to the Spec.Property of the ErrorResource - // will cause ConvertDown to fail - ErrorConvertDown = "convertDown" + // ErrorConvertFrom when assigned to the Spec.Property of the ErrorResource + // will cause ConvertFrom to fail + ErrorConvertFrom = "convertFrom" ) type ( @@ -180,8 +180,8 @@ func NewErrorResource(failure string) *ErrorResource { } } -// ConvertUp implements apis.Convertible -func (r *V1Resource) ConvertUp(ctx context.Context, to apis.Convertible) error { +// ConvertTo implements apis.Convertible +func (r *V1Resource) ConvertTo(ctx context.Context, to apis.Convertible) error { switch sink := to.(type) { case *V2Resource: sink.Spec.Property = "prefix/" + r.Spec.Property @@ -197,8 +197,8 @@ func (r *V1Resource) ConvertUp(ctx context.Context, to apis.Convertible) error { return nil } -// ConvertDown implements apis.Convertible -func (r *V1Resource) ConvertDown(ctx context.Context, from apis.Convertible) error { +// ConvertFrom implements apis.Convertible +func (r *V1Resource) ConvertFrom(ctx context.Context, from apis.Convertible) error { switch source := from.(type) { case *V2Resource: r.Spec.Property = strings.TrimPrefix(source.Spec.Property, "prefix/") @@ -221,40 +221,40 @@ func (r *V3Resource) SetDefaults(ctx context.Context) { } } -// ConvertUp implements apis.Convertible -func (*V2Resource) ConvertUp(ctx context.Context, to apis.Convertible) error { +// ConvertTo implements apis.Convertible +func (*V2Resource) ConvertTo(ctx context.Context, to apis.Convertible) error { panic("unimplemented") } -// ConvertDown implements apis.Convertible -func (*V2Resource) ConvertDown(ctx context.Context, from apis.Convertible) error { +// ConvertFrom implements apis.Convertible +func (*V2Resource) ConvertFrom(ctx context.Context, from apis.Convertible) error { panic("unimplemented") } -// ConvertUp implements apis.Convertible -func (*V3Resource) ConvertUp(ctx context.Context, to apis.Convertible) error { +// ConvertTo implements apis.Convertible +func (*V3Resource) ConvertTo(ctx context.Context, to apis.Convertible) error { panic("unimplemented") } -// ConvertDown implements apis.Convertible -func (*V3Resource) ConvertDown(ctx context.Context, from apis.Convertible) error { +// ConvertFrom implements apis.Convertible +func (*V3Resource) ConvertFrom(ctx context.Context, from apis.Convertible) error { panic("unimplemented") } -// ConvertUp implements apis.Convertible -func (e *ErrorResource) ConvertUp(ctx context.Context, to apis.Convertible) error { - if e.Spec.Property == ErrorConvertUp { +// ConvertTo implements apis.Convertible +func (e *ErrorResource) ConvertTo(ctx context.Context, to apis.Convertible) error { + if e.Spec.Property == ErrorConvertTo { return errors.New("boooom - convert up") } - return e.V1Resource.ConvertUp(ctx, to) + return e.V1Resource.ConvertTo(ctx, to) } -// ConvertDown implements apis.Convertible -func (e *ErrorResource) ConvertDown(ctx context.Context, from apis.Convertible) error { - err := e.V1Resource.ConvertDown(ctx, from) +// ConvertFrom implements apis.Convertible +func (e *ErrorResource) ConvertFrom(ctx context.Context, from apis.Convertible) error { + err := e.V1Resource.ConvertFrom(ctx, from) - if err == nil && e.Spec.Property == ErrorConvertDown { + if err == nil && e.Spec.Property == ErrorConvertFrom { err = errors.New("boooom - convert down") } return err