Add support for providing sink spec in GVR format (#1717)

This commit is contained in:
Gunjan Vyas 2022-08-10 02:38:34 +05:30 committed by GitHub
parent ebc672993a
commit bf20fe2185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -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"},
}