Repository: knative/client (go)

Issue:
Add support for providing sink spec in GVR format
<!-- If you need to report a security issue with Knative, send an email to knative-security@googlegroups.com. -->

### Feature request
The user can specify a sink in subscription create and update (`--sink`, `--sink-reply`, `--sink-dead-letter` flags), source create and update(`--sink` flag), and broker create and update (`--dl-sink` flag). Currently, only a few known types are supported as an argument to these flags ("broker", "ksvc", and "channel"). If the user provides any other prefix outside the supported ones, `kn` returns an `unsupported sink prefix` error.
<!-- Please describe the feature request and why you would like to have it -->

### Use case
To use sinks of custom types.
<!-- Please add a concrete use case to demonstrate how such a feature would add value for the user. If you don't have a use case for your feature, please remove this section (however providing a good use case increases the likelihood to be picked up) -->

### UI Example

<!-- If this is about a new command or command line options, please let us know how you would add it to the "kn" UI (in the code block below). If this is not applicable for your feature, delete this section. -->

```
kn source ping create my-ping --schedule "*/2 * * * *" --data '{ value: "hello" }' --sink <apiVersion>:<kind>:<name>:<namespace>
```

<!--
Optional Classifications, remove the '> ' to select:
> /kind good-first-issue
> /kind proposal
> /kind doc
> /kind cleanup
-->


Pull request:
Added gvr sink test cases and support to specify resource as singular/plural
## Description
Added gvr sink test cases and support to specify resource as singular/plural
<!-- Please add a short summary about what the pull request is going to bring on the table -->

## Changes

<!-- Please add list of more detailed changes. These changes should be reflected also in the commit messages -->

* Added 2 tests for singular/plural forms of pingsource resource type
* Added a negative test for an absent resource

## Reference

<!-- Please add the corresponding issue number which this pull request is about to fix -->
Fixes #1704 

Follow up for: https://github.com/knative/client/pull/1717
**Release Note**

<!-- Enter your extended release note in the below block. If the PR requires
additional action from users switching to the new release, include the string
"action required". If no release note is required, write "NONE". -->

```release-note
Add singular/plural support to `--sink` flag
```

<!--
Please add an entry to CHANGELOG.adoc file, too, as part of your Pull Request.

In the following cases, add a short description of PR to the unreleased section in CHANGELOG.adoc:

- 🎁 New feature
- 🐛 Bug fix
- ✨ Feature Update
- 🐣 Refactoring
- 🗑️ Remove feature or internal logic

See other entries in CHANGELOG.adoc as an example for how to add the entry, including a reference to the corresponding issue/PR

PLEASE DON'T ADD THAT LINE HERE IN THE PULL-REQUEST DESCRIPTION BUT DIRECTLY IN CHANGELOG.ADOC AND ADD CHANGELOG.ADOC AS PART OF YOUR PULL-REQUEST.
-->

<!--
To automatically lint go code in this pull request uncomment the line below. You get feedback as comments on your pull request then -->

<!--
/lint
-->


Patch:
diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES
index 196409e3..ea395ff5 100644
--- a/OWNERS_ALIASES
+++ b/OWNERS_ALIASES
@@ -29,7 +29,6 @@ aliases:
   - snneji
   docs-wg-leads:
   - abrennan89
-  - csantanapr
   - snneji
   docs-writers:
   - abrennan89
@@ -205,9 +204,7 @@ aliases:
   - spencerdillard
   ux-wg-leads:
   - abrennan89
-  - csantanapr
   - snneji
   ux-writers:
   - abrennan89
-  - csantanapr
   - snneji
diff --git a/pkg/kn/commands/flags/sink.go b/pkg/kn/commands/flags/sink.go
index 9cc8fea7..36a524a6 100644
--- a/pkg/kn/commands/flags/sink.go
+++ b/pkg/kn/commands/flags/sink.go
@@ -118,6 +118,9 @@ func (i *SinkFlags) ResolveSink(ctx context.Context, knclient clientdynamic.KnDy
 		}
 		parsedVersion, _ := schema.ParseGroupVersion(groupVersion)
 
+		if !strings.HasSuffix(kind, "s") {
+			kind = kind + "s"
+		}
 		typ = schema.GroupVersionResource{
 			Group:    parsedVersion.Group,
 			Version:  parsedVersion.Version,


Test patch:
diff --git a/pkg/kn/commands/flags/sink_test.go b/pkg/kn/commands/flags/sink_test.go
index a194759a..37c9e894 100644
--- a/pkg/kn/commands/flags/sink_test.go
+++ b/pkg/kn/commands/flags/sink_test.go
@@ -23,6 +23,7 @@ import (
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
 	messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
+	"knative.dev/eventing/pkg/apis/sources/v1beta2"
 	"knative.dev/pkg/apis"
 	duckv1 "knative.dev/pkg/apis/duck/v1"
 	servingv1 "knative.dev/serving/pkg/apis/serving/v1"
@@ -86,7 +87,10 @@ func TestResolve(t *testing.T) {
 		TypeMeta:   metav1.TypeMeta{Kind: "Channel", APIVersion: "messaging.knative.dev/v1"},
 		ObjectMeta: metav1.ObjectMeta{Name: "pipe", Namespace: "default"},
 	}
-
+	pingSource := &v1beta2.PingSource{
+		TypeMeta:   metav1.TypeMeta{Kind: "PingSource", APIVersion: "sources.knative.dev/v1"},
+		ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
+	}
 	cases := []resolveCase{
 		{"ksvc:mysvc", &duckv1.Destination{
 			Ref: &duckv1.KReference{Kind: "Service",
@@ -114,14 +118,28 @@ func TestResolve(t *testing.T) {
 			},
 			""},
 
+		{"sources.knative.dev/v1/pingsource:foo", &duckv1.Destination{Ref: &duckv1.KReference{
+			APIVersion: "sources.knative.dev/v1",
+			Kind:       "PingSource",
+			Namespace:  "default",
+			Name:       "foo",
+		}}, ""},
+		{"sources.knative.dev/v1/pingsources:foo", &duckv1.Destination{Ref: &duckv1.KReference{
+			APIVersion: "sources.knative.dev/v1",
+			Kind:       "PingSource",
+			Namespace:  "default",
+			Name:       "foo",
+		}}, ""},
 		{"http://target.example.com", &duckv1.Destination{
 			URI: targetExampleCom,
 		}, ""},
-		{"k8ssvc:foo", nil, "k8ssvc \"foo\" not found"},
+		{"k8ssvc:foo", nil, "k8ssvcs \"foo\" not found"},
 		{"svc:foo", nil, "please use prefix 'ksvc' for knative service"},
 		{"service:foo", nil, "please use prefix 'ksvc' for knative service"},
+		{"absent:foo", nil, "absents \"foo\" not found"},
 	}
-	dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default", mysvc, defaultBroker, pipeChannel)
+	dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default", mysvc, defaultBroker, pipeChannel, pingSource)
+
 	for _, c := range cases {
 		i := &SinkFlags{c.sink}
 		result, err := i.ResolveSink(context.Background(), dynamicClient, "default")