Skip to content

Make SubscribableSpec implement apis.Convertible#3472

Merged
knative-prow-robot merged 4 commits into
knative:masterfrom
aliok:duck_conv_02_SubscribableTypeSpec
Jul 6, 2020
Merged

Make SubscribableSpec implement apis.Convertible#3472
knative-prow-robot merged 4 commits into
knative:masterfrom
aliok:duck_conv_02_SubscribableTypeSpec

Conversation

@aliok
Copy link
Copy Markdown
Member

@aliok aliok commented Jul 3, 2020

Part of #3474

Same story with that #3471, but for SubscribableSpec

@knative-prow-robot knative-prow-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 3, 2020
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 3, 2020
@aliok aliok force-pushed the duck_conv_02_SubscribableTypeSpec branch from 2c737f0 to 06d3ca1 Compare July 3, 2020 09:08
@aliok aliok force-pushed the duck_conv_02_SubscribableTypeSpec branch 2 times, most recently from aa4d9b8 to 1452944 Compare July 3, 2020 10:07
@aliok
Copy link
Copy Markdown
Member Author

aliok commented Jul 3, 2020

/retest

1 similar comment
@aliok
Copy link
Copy Markdown
Member Author

aliok commented Jul 3, 2020

/retest

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2020
@aliok aliok force-pushed the duck_conv_02_SubscribableTypeSpec branch from 5cceb7c to 1ef897b Compare July 6, 2020 06:26
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 6, 2020
@aliok aliok changed the title [WIP] Make SubscribableSpec implement apis.Convertible Make SubscribableSpec implement apis.Convertible Jul 6, 2020
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 6, 2020
@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on the affected files.
Say /test pull-knative-eventing-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/duck/v1alpha1/subscribable_types_conversion.go 98.0% 98.2% 0.2
pkg/apis/duck/v1beta1/subscribable_types_conversion.go 96.2% 96.5% 0.3

sink.Subscribable.Subscribers[i].ConvertFrom(ctx, s)
}
}
default:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need the conversion to v1 too here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going step by step. In this and 2 more PRs I just make things impelemtn the interface.
The v1alpha1<>v1 is to be added later in #3477

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ok

Copy link
Copy Markdown
Contributor

@devguyio devguyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of questions.

func TestSubscribableSpecConversionBadType(t *testing.T) {
good, bad := &SubscribableSpec{}, &SubscribableSpec{}

if err := good.ConvertTo(context.Background(), bad); err == nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is bad considered bad cause this is a conversion from v1 to v1 ? and the good case would be from a different version to v1 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. that's the convention used in everywhere in knative/eventing btw.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is calling any Convertible method considered wrong? can't we convert downwards? v1obj.convertTo(v1beta1obj) ? and if so, how come the v1alpha1 have a convertFrom ? isn't that used for downgrade conversion?

Copy link
Copy Markdown
Member Author

@aliok aliok Jul 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 methods on apis.Convertible:

  • ConvertTo: sets value of other from this
  • ConvertFrom: sets value of this from other

The code for conversion is kept on the lower version types. It is how it is in all over Knative and I like this practice.

To convert down, you would need to do v1beta1obj.ConvertFrom(v1obj).

how come the v1alpha1 have a convertFrom

if your storage version is v1alpha1, you need to convert v1 object to v1alpha1. That's why that method is needed.

@slinkydeveloper
Copy link
Copy Markdown
Contributor

slinkydeveloper commented Jul 6, 2020

/approve

Waiting for last lgtm from @devguyio

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 6, 2020
Copy link
Copy Markdown
Contributor

@devguyio devguyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 6, 2020
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aliok, devguyio, slinkydeveloper

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-test-reporter-robot
Copy link
Copy Markdown

The following jobs failed:

Test name Triggers Retries
pull-knative-eventing-integration-tests 0/3

Failed non-flaky tests preventing automatic retry of pull-knative-eventing-integration-tests:

test/e2e.TestEventTransformationForTriggerV1Beta1BrokerV1Beta1
test/e2e.TestEventTransformationForTriggerV1Beta1BrokerV1Beta1/InMemoryChannel-messaging.knative.dev/v1

@aliok
Copy link
Copy Markdown
Member Author

aliok commented Jul 6, 2020

/retest

@knative-prow-robot knative-prow-robot merged commit 837ec98 into knative:master Jul 6, 2020
@aliok aliok deleted the duck_conv_02_SubscribableTypeSpec branch April 28, 2021 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants