From 47f59f07961d7d500c69493686d0b78ca20ec25a Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Tue, 10 Nov 2020 14:20:58 +0530 Subject: [PATCH] [release-0.18] Backport #1092 (#1104) * feat: Add channel sink prefix (#1092) * Add channel sink prefix * Add unit and e2e tests * Add CHANGELOG * Fix e2e tests * Add CHANGELOG for v0.18.2 --- CHANGELOG.adoc | 12 ++++++++++++ docs/cmd/kn_source_apiserver_create.md | 2 +- docs/cmd/kn_source_apiserver_update.md | 2 +- docs/cmd/kn_source_binding_create.md | 2 +- docs/cmd/kn_source_binding_update.md | 2 +- docs/cmd/kn_source_ping_create.md | 2 +- docs/cmd/kn_source_ping_update.md | 2 +- docs/cmd/kn_subscription_create.md | 6 +++--- docs/cmd/kn_subscription_update.md | 6 +++--- docs/cmd/kn_trigger_create.md | 2 +- docs/cmd/kn_trigger_update.md | 2 +- pkg/kn/commands/flags/sink.go | 8 +++++++- pkg/kn/commands/flags/sink_test.go | 20 ++++++++++++++++++-- test/e2e/sink_test.go | 9 +++++++++ 14 files changed, 60 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 9918959812..04bc9bce59 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -12,6 +12,18 @@ | https://github.com/knative/client/pull/[#] //// +## v0.18.2 (2020-11-10) + +[cols="1,10,3", options="header", width="100%"] +|=== +| | Description | PR + +| 🎁 +| Add channel sink prefix +| https://github.com/knative/client/pull/1092[#1092] + +|=== + ## v0.18.1 (2020-10-12) [cols="1,10,3", options="header", width="100%"] diff --git a/docs/cmd/kn_source_apiserver_create.md b/docs/cmd/kn_source_apiserver_create.md index a26f962714..c9d24f39ab 100644 --- a/docs/cmd/kn_source_apiserver_create.md +++ b/docs/cmd/kn_source_apiserver_create.md @@ -30,7 +30,7 @@ kn source apiserver create NAME --resource RESOURCE --sink SINK --resource stringArray Specification for which events to listen, in the format Kind:APIVersion:LabelSelector, e.g. "Event:v1:key=value". "LabelSelector" is a list of comma separated key value pairs. "LabelSelector" can be omitted, e.g. "Event:v1". --service-account string Name of the service account to use to run this source - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. ``` ### Options inherited from parent commands diff --git a/docs/cmd/kn_source_apiserver_update.md b/docs/cmd/kn_source_apiserver_update.md index 2982dd40be..80da4fbbaa 100644 --- a/docs/cmd/kn_source_apiserver_update.md +++ b/docs/cmd/kn_source_apiserver_update.md @@ -30,7 +30,7 @@ kn source apiserver update NAME --resource stringArray Specification for which events to listen, in the format Kind:APIVersion:LabelSelector, e.g. "Event:v1:key=value". "LabelSelector" is a list of comma separated key value pairs. "LabelSelector" can be omitted, e.g. "Event:v1". --service-account string Name of the service account to use to run this source - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. ``` ### Options inherited from parent commands diff --git a/docs/cmd/kn_source_binding_create.md b/docs/cmd/kn_source_binding_create.md index 0a36b9ba88..16b8218231 100644 --- a/docs/cmd/kn_source_binding_create.md +++ b/docs/cmd/kn_source_binding_create.md @@ -24,7 +24,7 @@ kn source binding create NAME --subject SUBJECT --sink SINK --ce-override stringArray Cloud Event overrides to apply before sending event to sink. Example: '--ce-override key=value' You may be provide this flag multiple times. To unset, append "-" to the key (e.g. --ce-override key-). -h, --help help for create -n, --namespace string Specify the namespace to operate in. - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. --subject string Subject which emits cloud events. This argument takes format kind:apiVersion:name for named resources or kind:apiVersion:labelKey1=value1,labelKey2=value2 for matching via a label selector ``` diff --git a/docs/cmd/kn_source_binding_update.md b/docs/cmd/kn_source_binding_update.md index b3a76743ec..eb8e76b0eb 100644 --- a/docs/cmd/kn_source_binding_update.md +++ b/docs/cmd/kn_source_binding_update.md @@ -24,7 +24,7 @@ kn source binding update NAME --ce-override stringArray Cloud Event overrides to apply before sending event to sink. Example: '--ce-override key=value' You may be provide this flag multiple times. To unset, append "-" to the key (e.g. --ce-override key-). -h, --help help for update -n, --namespace string Specify the namespace to operate in. - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. --subject string Subject which emits cloud events. This argument takes format kind:apiVersion:name for named resources or kind:apiVersion:labelKey1=value1,labelKey2=value2 for matching via a label selector ``` diff --git a/docs/cmd/kn_source_ping_create.md b/docs/cmd/kn_source_ping_create.md index d291b52115..14ebdc4997 100644 --- a/docs/cmd/kn_source_ping_create.md +++ b/docs/cmd/kn_source_ping_create.md @@ -26,7 +26,7 @@ kn source ping create NAME --sink SINK -h, --help help for create -n, --namespace string Specify the namespace to operate in. --schedule string Optional schedule specification in crontab format (e.g. '*/2 * * * *' for every two minutes. By default fire every minute. - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. ``` ### Options inherited from parent commands diff --git a/docs/cmd/kn_source_ping_update.md b/docs/cmd/kn_source_ping_update.md index 99c1c6937d..e17bc13913 100644 --- a/docs/cmd/kn_source_ping_update.md +++ b/docs/cmd/kn_source_ping_update.md @@ -26,7 +26,7 @@ kn source ping update NAME -h, --help help for update -n, --namespace string Specify the namespace to operate in. --schedule string Optional schedule specification in crontab format (e.g. '*/2 * * * *' for every two minutes. By default fire every minute. - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. ``` ### Options inherited from parent commands diff --git a/docs/cmd/kn_subscription_create.md b/docs/cmd/kn_subscription_create.md index b18ba33287..80ee2c3e9b 100644 --- a/docs/cmd/kn_subscription_create.md +++ b/docs/cmd/kn_subscription_create.md @@ -27,9 +27,9 @@ kn subscription create NAME --channel string Specify the channel to subscribe to. For the default channel, just use the name (e.g. 'mychannel'). A mapped channel type like 'imc' can be used as a prefix (e.g. 'imc:mychannel'). Finally you can specify the full coordinates to the referenced channel with Group:Version:Kind:Name (e.g. 'messaging.knative.dev:v1alpha1:KafkaChannel:mychannel'). -h, --help help for create -n, --namespace string Specify the namespace to operate in. - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. - --sink-dead-letter string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink-dead-letter broker:nest' for a broker 'nest', '--sink-dead-letter https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink-dead-letter ksvc:receiver' or simply '--sink-dead-letter receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. - --sink-reply string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink-reply broker:nest' for a broker 'nest', '--sink-reply https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink-reply ksvc:receiver' or simply '--sink-reply receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + --sink-dead-letter string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink-dead-letter broker:nest' for a broker 'nest', '--sink-dead-letter channel:pipe' for a channel 'pipe', '--sink-dead-letter https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink-dead-letter ksvc:receiver' or simply '--sink-dead-letter receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + --sink-reply string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink-reply broker:nest' for a broker 'nest', '--sink-reply channel:pipe' for a channel 'pipe', '--sink-reply https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink-reply ksvc:receiver' or simply '--sink-reply receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. ``` ### Options inherited from parent commands diff --git a/docs/cmd/kn_subscription_update.md b/docs/cmd/kn_subscription_update.md index a884c316e0..44109f49f6 100644 --- a/docs/cmd/kn_subscription_update.md +++ b/docs/cmd/kn_subscription_update.md @@ -26,9 +26,9 @@ kn subscription update NAME ``` -h, --help help for update -n, --namespace string Specify the namespace to operate in. - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. - --sink-dead-letter string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink-dead-letter broker:nest' for a broker 'nest', '--sink-dead-letter https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink-dead-letter ksvc:receiver' or simply '--sink-dead-letter receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. - --sink-reply string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink-reply broker:nest' for a broker 'nest', '--sink-reply https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink-reply ksvc:receiver' or simply '--sink-reply receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + --sink-dead-letter string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink-dead-letter broker:nest' for a broker 'nest', '--sink-dead-letter channel:pipe' for a channel 'pipe', '--sink-dead-letter https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink-dead-letter ksvc:receiver' or simply '--sink-dead-letter receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + --sink-reply string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink-reply broker:nest' for a broker 'nest', '--sink-reply channel:pipe' for a channel 'pipe', '--sink-reply https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink-reply ksvc:receiver' or simply '--sink-reply receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. ``` ### Options inherited from parent commands diff --git a/docs/cmd/kn_trigger_create.md b/docs/cmd/kn_trigger_create.md index 2a46592c79..f26edc79ff 100644 --- a/docs/cmd/kn_trigger_create.md +++ b/docs/cmd/kn_trigger_create.md @@ -29,7 +29,7 @@ kn trigger create NAME --sink SINK -h, --help help for create --inject-broker Create new broker with name default through common annotation -n, --namespace string Specify the namespace to operate in. - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. ``` ### Options inherited from parent commands diff --git a/docs/cmd/kn_trigger_update.md b/docs/cmd/kn_trigger_update.md index 9f1b6e4bdd..2e8f6ae1ba 100644 --- a/docs/cmd/kn_trigger_update.md +++ b/docs/cmd/kn_trigger_update.md @@ -33,7 +33,7 @@ kn trigger update NAME -h, --help help for update --inject-broker Create new broker with name default through common annotation -n, --namespace string Specify the namespace to operate in. - -s, --sink string Addressable sink for events. You can specify a broker, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. + -s, --sink string Addressable sink for events. You can specify a broker, channel, Knative service or URI. Examples: '--sink broker:nest' for a broker 'nest', '--sink channel:pipe' for a channel 'pipe', '--sink https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, '--sink ksvc:receiver' or simply '--sink receiver' for a Knative service 'receiver'. If a prefix is not provided, it is considered as a Knative service. ``` ### Options inherited from parent commands diff --git a/pkg/kn/commands/flags/sink.go b/pkg/kn/commands/flags/sink.go index abd3963e47..e1985b9d08 100644 --- a/pkg/kn/commands/flags/sink.go +++ b/pkg/kn/commands/flags/sink.go @@ -43,8 +43,9 @@ func (i *SinkFlags) AddWithFlagName(cmd *cobra.Command, fname, short string) { cmd.Flags().StringVarP(&i.sink, fname, short, "", "") } cmd.Flag(fname).Usage = "Addressable sink for events. " + - "You can specify a broker, Knative service or URI. " + + "You can specify a broker, channel, Knative service or URI. " + "Examples: '" + flag + " broker:nest' for a broker 'nest', " + + "'" + flag + " channel:pipe' for a channel 'pipe', " + "'" + flag + " https://event.receiver.uri' for an URI with an 'http://' or 'https://' schema, " + "'" + flag + " ksvc:receiver' or simply '" + flag + " receiver' for a Knative service 'receiver'. " + "If a prefix is not provided, it is considered as a Knative service." @@ -77,6 +78,11 @@ var sinkMappings = map[string]schema.GroupVersionResource{ Group: "serving.knative.dev", Version: "v1", }, + "channel": { + Resource: "channels", + Group: "messaging.knative.dev", + Version: "v1beta1", + }, } // ResolveSink returns the Destination referred to by the flags in the acceptor. diff --git a/pkg/kn/commands/flags/sink_test.go b/pkg/kn/commands/flags/sink_test.go index 5a0470142f..f477346652 100644 --- a/pkg/kn/commands/flags/sink_test.go +++ b/pkg/kn/commands/flags/sink_test.go @@ -21,6 +21,7 @@ import ( "gotest.tools/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" + messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" servingv1 "knative.dev/serving/pkg/apis/serving/v1" @@ -70,6 +71,8 @@ func TestSinkFlagAdd(t *testing.T) { func TestResolve(t *testing.T) { targetExampleCom, err := apis.ParseURL("http://target.example.com") + assert.NilError(t, err) + mysvc := &servingv1.Service{ TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "serving.knative.dev/v1"}, ObjectMeta: metav1.ObjectMeta{Name: "mysvc", Namespace: "default"}, @@ -78,8 +81,11 @@ func TestResolve(t *testing.T) { TypeMeta: metav1.TypeMeta{Kind: "Broker", APIVersion: "eventing.knative.dev/v1beta1"}, ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "default"}, } + pipeChannel := &messagingv1beta1.Channel{ + TypeMeta: metav1.TypeMeta{Kind: "Channel", APIVersion: "messaging.knative.dev/v1beta1"}, + ObjectMeta: metav1.ObjectMeta{Name: "pipe", Namespace: "default"}, + } - assert.NilError(t, err) cases := []resolveCase{ {"ksvc:mysvc", &duckv1.Destination{ Ref: &duckv1.KReference{Kind: "Service", @@ -97,6 +103,16 @@ func TestResolve(t *testing.T) { APIVersion: "eventing.knative.dev/v1beta1", Namespace: "default", Name: "default"}}, ""}, + {"channel:pipe", + &duckv1.Destination{ + Ref: &duckv1.KReference{Kind: "Channel", + APIVersion: "messaging.knative.dev/v1beta1", + Namespace: "default", + Name: "pipe", + }, + }, + ""}, + {"http://target.example.com", &duckv1.Destination{ URI: targetExampleCom, }, ""}, @@ -104,7 +120,7 @@ func TestResolve(t *testing.T) { {"svc:foo", nil, "please use prefix 'ksvc' for knative service"}, {"service:foo", nil, "please use prefix 'ksvc' for knative service"}, } - dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default", mysvc, defaultBroker) + dynamicClient := dynamicfake.CreateFakeKnDynamicClient("default", mysvc, defaultBroker, pipeChannel) for _, c := range cases { i := &SinkFlags{c.sink} result, err := i.ResolveSink(dynamicClient, "default") diff --git a/test/e2e/sink_test.go b/test/e2e/sink_test.go index 82b0227a4f..c8490e5e68 100644 --- a/test/e2e/sink_test.go +++ b/test/e2e/sink_test.go @@ -49,6 +49,15 @@ func TestSink(t *testing.T) { assert.NilError(t, err) assert.Equal(t, out, "default") + // create a channel + test.ChannelCreate(r, "pipe") + + t.Log("Update Ping source with a sink to the channel") + pingSourceUpdateSink(r, "testpingsource0", "channel:pipe") + out, err = test.GetResourceFieldsWithJSONPath(t, it, "pingsource", "testpingsource0", jpSinkRefNameInSpec) + assert.NilError(t, err) + assert.Equal(t, out, "pipe") + t.Log("delete Ping sources") pingSourceDelete(r, "testpingsource0") }