From 431637a1d99cd1512a9f9e27518df4fe5a615911 Mon Sep 17 00:00:00 2001 From: Kaustubh Pande Date: Thu, 18 Mar 2021 19:11:54 +0530 Subject: [PATCH] add support for namespace for all commands that takes --sink option (#1264) --- CHANGELOG.adoc | 4 +++ 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_container_create.md | 2 +- docs/cmd/kn_source_container_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 | 28 +++++++++------- pkg/kn/commands/flags/sink_test.go | 45 ++++++++++++++++++++++++++ test/e2e-tests.sh | 14 +++++++- 16 files changed, 95 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2c54c4573..f6cc8b2ec 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -17,6 +17,10 @@ |=== | | Description | PR +| ✨ +| Add support for namespace for all commands that takes a --sink option +| https://github.com/knative/client/pull/1264[#1264] + | 🎁 | Add `--prune` & `--prune-all` options to delete the unreferenced revisions | https://github.com/knative/client/pull/1217[#1217] diff --git a/docs/cmd/kn_source_apiserver_create.md b/docs/cmd/kn_source_apiserver_create.md index c3b676378..7af099c5d 100644 --- a/docs/cmd/kn_source_apiserver_create.md +++ b/docs/cmd/kn_source_apiserver_create.md @@ -26,7 +26,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 3d8568ce5..693e6d23b 100644 --- a/docs/cmd/kn_source_apiserver_update.md +++ b/docs/cmd/kn_source_apiserver_update.md @@ -26,7 +26,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 d6eb50fee..3110006d5 100644 --- a/docs/cmd/kn_source_binding_create.md +++ b/docs/cmd/kn_source_binding_create.md @@ -20,7 +20,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 8b22afa82..18c1562c8 100644 --- a/docs/cmd/kn_source_binding_update.md +++ b/docs/cmd/kn_source_binding_update.md @@ -20,7 +20,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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_container_create.md b/docs/cmd/kn_source_container_create.md index 5e778f357..7fce6ba84 100644 --- a/docs/cmd/kn_source_container_create.md +++ b/docs/cmd/kn_source_container_create.md @@ -30,7 +30,7 @@ kn source container create NAME --image IMAGE --sink SINK --pull-secret string Image pull secret to set. An empty argument ("") clears the pull secret. The referenced secret must exist in the service's namespace. --request strings The resource requirement requests for this Service. For example, 'cpu=100m,memory=256Mi'. You can use this flag multiple times. To unset a resource request, append "-" to the resource name, e.g. '--request cpu-'. --service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace. - -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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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. --user int The user ID to run the container (e.g., 1001). --volume stringArray Add a volume from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret: or sc:). Example: --volume myvolume=cm:myconfigmap or --volume myvolume=secret:mysecret. You can use this flag multiple times. To unset a ConfigMap/Secret reference, append "-" to the name, e.g. --volume myvolume-. ``` diff --git a/docs/cmd/kn_source_container_update.md b/docs/cmd/kn_source_container_update.md index 047136c0e..82cdb1534 100644 --- a/docs/cmd/kn_source_container_update.md +++ b/docs/cmd/kn_source_container_update.md @@ -30,7 +30,7 @@ kn source container update NAME --image IMAGE --pull-secret string Image pull secret to set. An empty argument ("") clears the pull secret. The referenced secret must exist in the service's namespace. --request strings The resource requirement requests for this Service. For example, 'cpu=100m,memory=256Mi'. You can use this flag multiple times. To unset a resource request, append "-" to the resource name, e.g. '--request cpu-'. --service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace. - -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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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. --user int The user ID to run the container (e.g., 1001). --volume stringArray Add a volume from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret: or sc:). Example: --volume myvolume=cm:myconfigmap or --volume myvolume=secret:mysecret. You can use this flag multiple times. To unset a ConfigMap/Secret reference, append "-" to the name, e.g. --volume myvolume-. ``` diff --git a/docs/cmd/kn_source_ping_create.md b/docs/cmd/kn_source_ping_create.md index 5985455f1..bde2574fe 100644 --- a/docs/cmd/kn_source_ping_create.md +++ b/docs/cmd/kn_source_ping_create.md @@ -22,7 +22,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 64c8e337b..0792aa2de 100644 --- a/docs/cmd/kn_source_ping_update.md +++ b/docs/cmd/kn_source_ping_update.md @@ -22,7 +22,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 e49f40796..aba916c96 100644 --- a/docs/cmd/kn_subscription_create.md +++ b/docs/cmd/kn_subscription_create.md @@ -23,9 +23,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 59cd20243..ee00435ad 100644 --- a/docs/cmd/kn_subscription_update.md +++ b/docs/cmd/kn_subscription_update.md @@ -22,9 +22,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 616506f2c..106781c32 100644 --- a/docs/cmd/kn_trigger_create.md +++ b/docs/cmd/kn_trigger_create.md @@ -25,7 +25,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 2aad67a6e..b3d0afed8 100644 --- a/docs/cmd/kn_trigger_update.md +++ b/docs/cmd/kn_trigger_update.md @@ -29,7 +29,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, 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. + -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 ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', '--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 e8d660c15..b46d462c2 100644 --- a/pkg/kn/commands/flags/sink.go +++ b/pkg/kn/commands/flags/sink.go @@ -46,6 +46,7 @@ func (i *SinkFlags) AddWithFlagName(cmd *cobra.Command, fname, short string) { "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 + " ksvc:mysvc:mynamespace' for a Knative service 'mysvc' in another namespace 'mynamespace', " + "'" + 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." @@ -92,8 +93,7 @@ func (i *SinkFlags) ResolveSink(knclient clientdynamic.KnDynamicClient, namespac if i.sink == "" { return nil, nil } - - prefix, name := parseSink(i.sink) + prefix, name, ns := parseSink(i.sink) if prefix == "" { // URI target uri, err := apis.ParseURL(name) @@ -109,6 +109,9 @@ func (i *SinkFlags) ResolveSink(knclient clientdynamic.KnDynamicClient, namespac } return nil, fmt.Errorf("unsupported sink prefix: '%s'", prefix) } + if ns != "" { + namespace = ns + } obj, err := client.Resource(typ).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { return nil, err @@ -125,17 +128,20 @@ func (i *SinkFlags) ResolveSink(knclient clientdynamic.KnDynamicClient, namespac return destination, nil } -// parseSink takes the string given by the user into the prefix and the name of +// parseSink takes the string given by the user into the prefix, name and namespace of // the object. If the user put a URI instead, the prefix is empty and the name // is the whole URI. -func parseSink(sink string) (string, string) { - parts := strings.SplitN(sink, ":", 2) - if len(parts) == 1 { - return "ksvc", parts[0] - } else if parts[0] == "http" || parts[0] == "https" { - return "", sink - } else { - return parts[0], parts[1] +func parseSink(sink string) (string, string, string) { + parts := strings.SplitN(sink, ":", 3) + switch { + case len(parts) == 1: + return "ksvc", parts[0], "" + case parts[0] == "http" || parts[0] == "https": + return "", sink, "" + case len(parts) == 3: + return parts[0], parts[1], parts[2] + default: + return parts[0], parts[1], "" } } diff --git a/pkg/kn/commands/flags/sink_test.go b/pkg/kn/commands/flags/sink_test.go index 5e0fc35d1..19d0e1eac 100644 --- a/pkg/kn/commands/flags/sink_test.go +++ b/pkg/kn/commands/flags/sink_test.go @@ -132,3 +132,48 @@ func TestResolve(t *testing.T) { } } } + +func TestResolveWithNamespace(t *testing.T) { + mysvc := &servingv1.Service{ + TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "serving.knative.dev/v1"}, + ObjectMeta: metav1.ObjectMeta{Name: "mysvc", Namespace: "my-namespace"}, + } + defaultBroker := &eventingv1beta1.Broker{ + TypeMeta: metav1.TypeMeta{Kind: "Broker", APIVersion: "eventing.knative.dev/v1beta1"}, + ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "my-namespace"}, + } + pipeChannel := &messagingv1beta1.Channel{ + TypeMeta: metav1.TypeMeta{Kind: "Channel", APIVersion: "messaging.knative.dev/v1beta1"}, + ObjectMeta: metav1.ObjectMeta{Name: "pipe", Namespace: "my-namespace"}, + } + + cases := []resolveCase{ + {"ksvc:mysvc:my-namespace", &duckv1.Destination{ + Ref: &duckv1.KReference{Kind: "Service", + APIVersion: "serving.knative.dev/v1", + Namespace: "my-namespace", + Name: "mysvc"}}, ""}, + {"broker:default:my-namespace", &duckv1.Destination{ + Ref: &duckv1.KReference{Kind: "Broker", + APIVersion: "eventing.knative.dev/v1beta1", + Namespace: "my-namespace", + Name: "default"}}, ""}, + {"channel:pipe:my-namespace", &duckv1.Destination{ + Ref: &duckv1.KReference{Kind: "Channel", + APIVersion: "messaging.knative.dev/v1beta1", + Namespace: "my-namespace", + Name: "pipe"}}, ""}, + } + dynamicClient := dynamicfake.CreateFakeKnDynamicClient("my-namespace", mysvc, defaultBroker, pipeChannel) + for _, c := range cases { + i := &SinkFlags{c.sink} + result, err := i.ResolveSink(dynamicClient, "default") + if c.destination != nil { + assert.DeepEqual(t, result, c.destination) + assert.Equal(t, c.destination.Ref.Namespace, "my-namespace") + assert.NilError(t, err) + } else { + assert.ErrorContains(t, err, c.errContents) + } + } +} diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index d7da42700..a12b94c2b 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -54,11 +54,17 @@ integration_test() { go_test_e2e -timeout=45m ./test/e2e || fail_test } +smoke_test_clean_up(){ + kubectl delete ns $ns + kubectl delete ns $ns1 +} + smoke_test() { header "Running smoke tests" # Test namespace ns="kne2esmoketests" + ns1="kne2esmoketest" # Test image img=${KO_DOCKER_REPO}/helloworld @@ -66,7 +72,8 @@ smoke_test() { set -x kubectl create ns $ns || fail_test - trap "kubectl delete ns $ns" EXIT + kubectl create ns $ns1 || fail_test + trap smoke_test_clean_up EXIT sleep 4 # Wait for the namespace to get initialized by kube-controller-manager @@ -89,6 +96,11 @@ smoke_test() { ./kn service list -n $ns | grep -q svc1 || fail_test ./kn service delete svc1 -n $ns || fail_test ./kn source list-types || fail_test + ./kn service create mysvc --image $img -e TARGET=Knative -n $ns1 || fail_test + ./kn source ping create my-ping -n $ns --schedule "*/2 * * * *" --data '{ value: "hello" }' --sink ksvc:mysvc:$ns1 || fail_test + [[ "$(./kn source ping describe my-ping -n $ns -o=jsonpath={.spec.sink.ref.namespace})" != "$ns1" ]] && fail_test + ./kn source ping delete my-ping -n $ns || fail_test + ./kn service delete mysvc -n $ns1 || fail_test set +x }