fix kn trigger list command to show correct v1/service sink output (#1428)

* fix kn trigger list command to show correct v1/service sink output

* Update pkg/kn/commands/flags/sink.go

Co-authored-by: Murugappan Chetty <itsmurugappan@gmail.com>

Co-authored-by: Murugappan Chetty <itsmurugappan@gmail.com>
This commit is contained in:
Abirdcfly 2021-08-18 18:44:08 +08:00 committed by GitHub
parent 00269396cf
commit 4a0ac33dcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -149,7 +149,7 @@ func parseSink(sink string) (string, string, string) {
// SinkToString prepares a sink for list output
func SinkToString(sink duckv1.Destination) string {
if sink.Ref != nil {
if sink.Ref.Kind == "Service" {
if sink.Ref.Kind == "Service" && strings.HasPrefix(sink.Ref.APIVersion, sinkMappings["ksvc"].Group) {
return fmt.Sprintf("ksvc:%s", sink.Ref.Name)
} else {
return fmt.Sprintf("%s:%s", strings.ToLower(sink.Ref.Kind), sink.Ref.Name)

View File

@ -194,6 +194,13 @@ func TestSinkToString(t *testing.T) {
Name: "default"}}
expected = "broker:default"
assert.Equal(t, expected, SinkToString(sink))
sink = duckv1.Destination{
Ref: &duckv1.KReference{Kind: "Service",
APIVersion: "v1",
Namespace: "my-namespace",
Name: "mysvc"}}
expected = "service:mysvc"
assert.Equal(t, expected, SinkToString(sink))
uri := "http://target.example.com"
targetExampleCom, err := apis.ParseURL(uri)

View File

@ -83,8 +83,9 @@ func newSourceUnstructuredObjWithSink(name, apiVersion, kind string) *unstructur
"spec": map[string]interface{}{
"sink": map[string]interface{}{
"ref": map[string]interface{}{
"kind": "Service",
"name": "foo",
"apiVersion": "serving.knative.dev/v1",
"kind": "Service",
"name": "foo",
},
},
},

View File

@ -188,8 +188,9 @@ func newSourceUnstructuredObj(name, apiVersion, kind string) *unstructured.Unstr
"spec": map[string]interface{}{
"sink": map[string]interface{}{
"ref": map[string]interface{}{
"kind": "Service",
"name": "foo",
"apiVersion": "serving.knative.dev/v1",
"kind": "Service",
"name": "foo",
},
},
},