Skip to content

Create an interface for retrieving duck-type fields#1275

Merged
knative-prow-robot merged 6 commits into
knative:masterfrom
whaught:and1
May 4, 2020
Merged

Create an interface for retrieving duck-type fields#1275
knative-prow-robot merged 6 commits into
knative:masterfrom
whaught:and1

Conversation

@whaught
Copy link
Copy Markdown
Contributor

@whaught whaught commented May 1, 2020

Issue #1226

  • This creates a new interface for receiving the core fields of KResource duck resources
  • KResource implements the interface, but I intend to use this to implement for the basic API types
    • Unblocks the ability to cast to the interface and reason generically about the resource. I intend to use this to detect and run common logic for these resources.

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label May 1, 2020
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 1, 2020
Comment thread apis/duck/v1/kresource_type.go Outdated
@whaught
Copy link
Copy Markdown
Contributor Author

whaught commented May 1, 2020

/assign @vaikas @n3wscott

@knative-metrics-robot
Copy link
Copy Markdown

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

File Old Coverage New Coverage Delta
apis/duck/v1/kresource_type.go Do not exist 50.0%

@whaught
Copy link
Copy Markdown
Contributor Author

whaught commented May 1, 2020

/hold I'm not sure if this is going to work without some reflection.

There isn't a way in golang to dynamically test if a resource implements an interface and then run logic on it that way.

The advantage of this would be instead of #1261 we'd reflect an instance of KRShaped from our type and from there we could create common logic (instead of duplicating that logic with the generator)

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 1, 2020
@whaught
Copy link
Copy Markdown
Contributor Author

whaught commented May 1, 2020

/unhold nah let's keep going with this. As long as we still create a new tag to genreconciler we'll only do this for KRShaped things. At least now we can create unit-testable functions on this type more easily instead of doing it all directly in the generated code.

@whaught
Copy link
Copy Markdown
Contributor Author

whaught commented May 2, 2020

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 2, 2020
// KRShaped is an interface for retrieving the duck elements of an arbitraty resource.
type KRShaped interface {
GetTypeMeta() *metav1.TypeMeta

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.

I think these come from RuntimeObject

Comment thread apis/duck/v1/kresource_type.go
Comment thread apis/duck/v1/kresource_type.go
@n3wscott
Copy link
Copy Markdown
Contributor

n3wscott commented May 4, 2020

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: n3wscott, whaught

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-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 4, 2020
@knative-prow-robot knative-prow-robot merged commit 4a2ba05 into knative:master May 4, 2020
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