Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform multiple writeSink(s) to DescribeSink #1075

Merged
merged 1 commit into from
Oct 29, 2020

Conversation

daisy-ycguo
Copy link
Member

@daisy-ycguo daisy-ycguo commented Oct 27, 2020

Description

There are multiple writeSink in source commands to print Sink object. And there is a utility DescribeSink in lib/printing. It's better to uniform them.

Changes

  • Uniform multiple writeSink(s) to a single WriteSink

@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Oct 27, 2020
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 27, 2020
Comment on lines 151 to 165

// WriteSink writes a sink to a PrefixWriter which is used in describe command
func WriteSink(dw printers.PrefixWriter, sink *duckv1.Destination) {
subWriter := dw.WriteAttribute("Sink", "")
ref := sink.Ref
if ref != nil {
subWriter.WriteAttribute("Name", sink.Ref.Name)
subWriter.WriteAttribute("Namespace", sink.Ref.Namespace)
subWriter.WriteAttribute("Resource", fmt.Sprintf("%s (%s)", sink.Ref.Kind, sink.Ref.APIVersion))
}
uri := sink.URI
if uri != nil {
subWriter.WriteAttribute("URI", uri.String())
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

while doing the subscription CRUD, separated this util here

func DescribeSink(dw printers.PrefixWriter, attribute, namespace string, sink *duckv1.Destination) {

lets refer this util at following places

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the information. I updated. Please review again.

@daisy-ycguo daisy-ycguo changed the title Uniform multiple writeSink(s) to a single WriteSink Uniform multiple writeSink(s) to DescribeSink Oct 27, 2020
@daisy-ycguo daisy-ycguo force-pushed the small-fix branch 2 times, most recently from 52e7d1c to a0b401b Compare October 27, 2020 08:03
Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Looks good, with a minor change request.

@@ -29,6 +29,9 @@ func DescribeSink(dw printers.PrefixWriter, attribute, namespace string, sink *d
if sink == nil {
return
}
if len(attribute) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like that this method is never called with an attribute that is different to "". So I just would remove that argument and maybe re-introduce it if there is ever a need for a different label than Sink.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@rhuss : subscription CRUD uses it for DeadLetterSink etc

printing.DescribeSink(dw, "Subscriber", subscription.Namespace, subscription.Spec.Subscriber)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@daisy-ycguo : can you please update the function docstring to mention this behavior ? (like 'Sink' is used for attribute value if empty string is provided)

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. I will update the docstring.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. But maybe it's just better to require an explicit argument ? This could then also serve as documentation when calling the function (so just changing "" everywhere to "Sink") ? Not sure about this, so feel free to keep it .

Yet an alternative would be to move attribute to the end of the argument list and make it an optional parameter like attribute ...string. But I'm not dogmatic here, feel to chose what you think fits best.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But maybe it's just better to require an explicit argument ? This could then also serve as documentation when calling the function (so just changing "" everywhere to "Sink") ? Not sure about this, so feel free to keep it .

I was thinking same about it when I first saw this. As we are exporting this util, IMO we shouldn't carry any assumption and require explicit attribute value.

Copy link
Member Author

@daisy-ycguo daisy-ycguo Oct 28, 2020

Choose a reason for hiding this comment

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

I changed the code to make it mandatory.

Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

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

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 27, 2020
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2020
@knative-metrics-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/kn/commands/source/apiserver/describe.go 86.9% 84.6% -2.3
pkg/kn/commands/source/binding/describe.go 92.3% 90.9% -1.4
pkg/kn/commands/source/ping/describe.go 87.3% 84.8% -2.5
pkg/kn/commands/trigger/describe.go 85.7% 82.5% -3.2

Copy link
Collaborator

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: daisy-ycguo, maximilien, navidshaikh

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [maximilien,navidshaikh]

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 merged commit 6ed76ae into knative:master Oct 29, 2020
dsimansk added a commit to dsimansk/client that referenced this pull request Jun 15, 2022
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants