Skip to content

Commit

Permalink
Add support for providing sink spec in GVR format
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasgun committed Aug 8, 2022
1 parent 5251985 commit 7d09284
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion pkg/kn/commands/flags/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,21 @@ func (i *SinkFlags) ResolveSink(ctx context.Context, knclient clientdynamic.KnDy
if prefix == "svc" || prefix == "service" {
return nil, fmt.Errorf("unsupported sink prefix: '%s', please use prefix 'ksvc' for knative service", prefix)
}
return nil, fmt.Errorf("unsupported sink prefix: '%s', if referring to a knative service in another namespace, 'ksvc:name:namespace' combination must be provided explicitly", prefix)
idx := strings.LastIndex(prefix, "/")
var groupVersion string
var kind string
if idx != -1 && idx < len(prefix)-1 {
groupVersion, kind = prefix[:idx], prefix[idx+1:]
} else {
kind = prefix
}
parsedVersion, _ := schema.ParseGroupVersion(groupVersion)

typ = schema.GroupVersionResource{
Group: parsedVersion.Group,
Version: parsedVersion.Version,
Resource: kind,
}
}
if ns != "" {
namespace = ns
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/flags/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestResolve(t *testing.T) {
{"http://target.example.com", &duckv1.Destination{
URI: targetExampleCom,
}, ""},
{"k8ssvc:foo", nil, "unsupported sink prefix: 'k8ssvc'"},
{"k8ssvc:foo", nil, "k8ssvc \"foo\" not found"},
{"svc:foo", nil, "please use prefix 'ksvc' for knative service"},
{"service:foo", nil, "please use prefix 'ksvc' for knative service"},
}
Expand Down

0 comments on commit 7d09284

Please sign in to comment.