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

feat(source): Add 'kn source list' #666

Merged
merged 12 commits into from
Mar 10, 2020

Conversation

navidshaikh
Copy link
Collaborator

@navidshaikh navidshaikh commented Feb 14, 2020

/lint
Fixes #480

Proposed Changes

  • Add 'kn source list' listing the available sources COs
  • Use dynamic client to find available source objects
  • Add --type flag to filter source list based on source type
  • Printed a source with machine readable format:
    • If source objects are of one type: apiVersion and kind is set to respective source type's object
    • If source objects are of different types in list: apiVersion is set to "" and kind is to List.
    • If source objects are of different types but only one --type filter is given to subset source objects, the machine readable format sets apiVersion and List to respective source's type.

Default output:

kn source list
NAME   TYPE              RESOURCE                                        SINK         READY
a1     ApiServerSource   apiserversources.sources.eventing.knative.dev   svc:eshow2   True
c1     CronJobSource     cronjobsources.sources.eventing.knative.dev     svc:eshow3   True
p1     PingSource        pingsources.sources.knative.dev                 svc:eshow1   True

Using (case insensitive) type filters:

  1. Single source type
➜  client git:(pr/source-list) kn source list --type ApiServerSource
NAME   TYPE              RESOURCE                                        SINK         READY
a1     ApiServerSource   apiserversources.sources.eventing.knative.dev   svc:eshow2   True
  1. Multiple source types
➜  client git:(pr/source-list) kn source list --type ApiServerSource --type pingsource
NAME   TYPE              RESOURCE                                        SINK         READY
a1     ApiServerSource   apiserversources.sources.eventing.knative.dev   svc:eshow2   True
p1     PingSource        pingsources.sources.knative.dev                 svc:eshow1   True

See kind and apiVersion of List for machine readable format:

  1. For multiple types of source objects
➜  client git:(pr/source-list) kn source list -oyaml| grep kind | tail -1
kind: List
➜  client git:(pr/source-list) kn source list -oyaml| grep apiVersion | head -1
apiVersion: ""
  1. For single source type objects (or sub-set a single type using --type filter):
➜  client git:(pr/source-list) kn source list --type apiserversource -oyaml | grep kind | tail -1 
kind: ApiServerSourceList
➜  client git:(pr/source-list) kn source list --type apiserversource -oyaml | grep apiVersion | head -1
apiVersion: sources.eventing.knative.dev/v1alpha1

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 14, 2020
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Feb 14, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@navidshaikh: 2 warnings.

In response to this:

/lint
Fixes #480

Proposed Changes

  • Add 'kn source list' listing the available sources COs
  • Use dynamic client to
  • find out available source types
  • find the COs in given namespace for each source type
➜  client git:(pr/source-list) kn source list
NAME        TYPE              RESOURCE                                        SINK
k8sevents   ApiServerSource   apiserversources.sources.eventing.knative.dev   svc:mysvc

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

pkg/kn/commands/source/human_readable_flags.go Outdated Show resolved Hide resolved
pkg/kn/commands/source/human_readable_flags.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 14, 2020
@navidshaikh
Copy link
Collaborator Author

Adding another example of kn source list with another column READY.

@navidshaikh
Copy link
Collaborator Author

With 3 additional columns: CONDITIONS, READY, REASON

kn source list
NAME              TYPE              RESOURCE                                        SINK        CONDITIONS   READY   REASON
k8sevents         ApiServerSource   apiserversources.sources.eventing.knative.dev   svc:mysvc   6 OK / 6     True    
k8sevents2        ApiServerSource   apiserversources.sources.eventing.knative.dev   svc:mysvc   2 OK / 5     False    : User system:serviceaccount:default:doesnt-exist cannot get, list, watch resource "events" in API group ""
my-cron-trigger   CronJobSource     cronjobsources.sources.eventing.knative.dev     svc:mysvc   7 OK / 7     True    

@navidshaikh
Copy link
Collaborator Author

With only READY column

kn source list
NAME              TYPE              RESOURCE                                        SINK        READY
k8sevents         ApiServerSource   apiserversources.sources.eventing.knative.dev   svc:mysvc   True
k8sevents2        ApiServerSource   apiserversources.sources.eventing.knative.dev   svc:mysvc   False
my-cron-trigger   CronJobSource     cronjobsources.sources.eventing.knative.dev     svc:mysvc   True

IMO READY column is enough else the columns don't fit in screen, CONDITIONS and READY can be seen from describe instead.

@navidshaikh
Copy link
Collaborator Author

Added --type flag to filter source list based on source type(s). Updated PR description with examples.

@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 18, 2020
@navidshaikh navidshaikh changed the title WIP: feature: Add 'kn source list' feat(source): Add 'kn source list' Feb 18, 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 Feb 18, 2020
@navidshaikh
Copy link
Collaborator Author

/lint

Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@navidshaikh: 2 warnings.

In response to this:

/lint

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

pkg/dynamic/client.go Outdated Show resolved Hide resolved
pkg/dynamic/client.go Outdated Show resolved Hide resolved
@navidshaikh navidshaikh force-pushed the pr/source-list branch 3 times, most recently from 247fa41 to 4d74e8d Compare February 18, 2020 14:38
@navidshaikh
Copy link
Collaborator Author

This is ready for review.
/cc @rhuss @daisy-ycguo

@navidshaikh
Copy link
Collaborator Author

/test pull-knative-client-integration-tests

no endpoints available for service "webhook"

@navidshaikh
Copy link
Collaborator Author

navidshaikh commented Feb 18, 2020 via email

@navidshaikh
Copy link
Collaborator Author

/retest

smoketests: timeout: service 'hello' not ready after 600 seconds

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.

This a partial review for the API and how the list is fetched. Please find my comments below, I think we could improve the API.

Also what I'm a bit puzzled: Why does return ListSourceTypes an Unstructured and not a list CustomResourceDefinitions (which would make it much easier and type-safer to work with).

pkg/dynamic/client.go Outdated Show resolved Hide resolved
pkg/dynamic/client.go Outdated Show resolved Hide resolved
pkg/dynamic/client.go Outdated Show resolved Hide resolved
pkg/dynamic/client.go Outdated Show resolved Hide resolved
pkg/dynamic/client.go Outdated Show resolved Hide resolved
pkg/dynamic/client.go Show resolved Hide resolved
pkg/dynamic/client.go Show resolved Hide resolved
pkg/dynamic/client.go Outdated Show resolved Hide resolved
@navidshaikh
Copy link
Collaborator Author

/retest

@navidshaikh
Copy link
Collaborator Author

/test pull-knative-client-integration-tests

async revision delete issue

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 5, 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 Mar 5, 2020
@rhuss
Copy link
Contributor

rhuss commented Mar 5, 2020

/retest

@navidshaikh there are some codegen errors, too

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 9, 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 Mar 9, 2020
@navidshaikh
Copy link
Collaborator Author

/retest

--- FAIL: TestSourceApiServer (210.14s)

@rhuss
Copy link
Contributor

rhuss commented Mar 9, 2020

@navidshaikh lso codegen error. Guess that somehow sneaked in by a latest merge.

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 9, 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 Mar 9, 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/dynamic/client.go 83.3% 89.2% 5.9
pkg/dynamic/lib.go Do not exist 100.0%
pkg/kn/commands/flags/listfilters.go Do not exist 100.0%
pkg/kn/commands/source/human_readable_flags.go 87.0% 87.2% 0.2
pkg/kn/commands/source/list.go Do not exist 70.6%

sourceList.SetGroupVersionKind(sList.GetObjectKind().GroupVersionKind())
}
}
// Clear the Group and Version for list if there are multiple types of source objects found
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

t.Log("list sources in YAML format")
output = test.sourceList(t, r, "-oyaml")
assert.Check(t, util.ContainsAll(output, "testapisource1", "ApiServerSource", "Service", "testsvc0"))

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for already adding E2E tests, but maybe we could later enhance them with some more cases:

  • Invalid filter option
  • Heterogenous list of different types with -o yaml (would involve to combine a pingsource + apiserver source creation)

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.

Thanks !

Looks good, maybe one could extend the E2E tests a bit. I opened #722 for this.

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: navidshaikh, rhuss

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:

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 ba7e14c into knative:master Mar 10, 2020
@navidshaikh navidshaikh deleted the pr/source-list branch March 10, 2020 07:43
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kn source list - list all source instances (built-in, plugin, untyped)
6 participants