Repository: knative/pkg
Pull request #1694 (2020-09-09 17:01:59)

Remove branch examples referencing master.
There's no need to reference master in these examples. Let's drop them.

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1694#" title="Author self-approved">markusthoemmes</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[test/OWNERS](https://github.com/knative/pkg/blob/master/test/OWNERS)~~ [markusthoemmes]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/resolver/addressable_resolver.go b/resolver/addressable_resolver.go
index d15632f23..14c59a603 100644
--- a/resolver/addressable_resolver.go
+++ b/resolver/addressable_resolver.go
@@ -22,6 +22,7 @@ import (
 	"fmt"
 
 	corev1 "k8s.io/api/core/v1"
+	apierrs "k8s.io/apimachinery/pkg/api/errors"
 	"k8s.io/apimachinery/pkg/api/meta"
 	"k8s.io/apimachinery/pkg/types"
 
@@ -137,16 +138,17 @@ func (r *URIResolver) URIFromKReference(ref *duckv1.KReference, parent interface
 // URIFromObjectReference resolves an ObjectReference to a URI string.
 func (r *URIResolver) URIFromObjectReference(ref *corev1.ObjectReference, parent interface{}) (*apis.URL, error) {
 	if ref == nil {
-		return nil, errors.New("ref is nil")
+		return nil, apierrs.NewBadRequest("ref is nil")
 	}
 
+	gvr, _ := meta.UnsafeGuessKindToResource(ref.GroupVersionKind())
 	if err := r.tracker.TrackReference(tracker.Reference{
 		APIVersion: ref.APIVersion,
 		Kind:       ref.Kind,
 		Namespace:  ref.Namespace,
 		Name:       ref.Name,
 	}, parent); err != nil {
-		return nil, fmt.Errorf("failed to track %+v: %w", ref, err)
+		return nil, apierrs.NewNotFound(gvr.GroupResource(), ref.Name)
 	}
 
 	// K8s Services are special cased. They can be called, even though they do not satisfy the
@@ -161,30 +163,29 @@ func (r *URIResolver) URIFromObjectReference(ref *corev1.ObjectReference, parent
 		return url, nil
 	}
 
-	gvr, _ := meta.UnsafeGuessKindToResource(ref.GroupVersionKind())
 	_, lister, err := r.informerFactory.Get(gvr)
 	if err != nil {
-		return nil, fmt.Errorf("failed to get lister for %+v: %w", gvr, err)
+		return nil, apierrs.NewNotFound(gvr.GroupResource(), "Lister")
 	}
 
 	obj, err := lister.ByNamespace(ref.Namespace).Get(ref.Name)
 	if err != nil {
-		return nil, fmt.Errorf("failed to get ref %+v: %w", ref, err)
+		return nil, apierrs.NewNotFound(gvr.GroupResource(), ref.Name)
 	}
 
 	addressable, ok := obj.(*duckv1.AddressableType)
 	if !ok {
-		return nil, fmt.Errorf("%+v (%T) is not an AddressableType", ref, ref)
+		return nil, apierrs.NewBadRequest(fmt.Sprintf("%+v (%T) is not an AddressableType", ref, ref))
 	}
 	if addressable.Status.Address == nil {
-		return nil, fmt.Errorf("address not set for %+v", ref)
+		return nil, apierrs.NewBadRequest(fmt.Sprintf("address not set for %+v", ref))
 	}
 	url := addressable.Status.Address.URL
 	if url == nil {
-		return nil, fmt.Errorf("URL missing in address of %+v", ref)
+		return nil, apierrs.NewBadRequest(fmt.Sprintf("URL missing in address of %+v", ref))
 	}
 	if url.Host == "" {
-		return nil, fmt.Errorf("hostname missing in address of %+v", ref)
+		return nil, apierrs.NewBadRequest(fmt.Sprintf("hostname missing in address of %+v", ref))
 	}
 	return url, nil
 }


Test patch:
diff --git a/resolver/addressable_resolver_test.go b/resolver/addressable_resolver_test.go
index a989da260..b7d94f069 100644
--- a/resolver/addressable_resolver_test.go
+++ b/resolver/addressable_resolver_test.go
@@ -328,7 +328,7 @@ func TestGetURIDestinationV1Beta1(t *testing.T) {
 			wantErr: fmt.Sprintf("address not set for %+v", getUnaddressableRef()),
 		}, "notFound": {
 			dest:    duckv1beta1.Destination{Ref: getUnaddressableRef()},
-			wantErr: fmt.Sprintf("failed to get ref %+v: %s %q not found", getUnaddressableRef(), unaddressableResource, unaddressableName),
+			wantErr: fmt.Sprintf("%s %q not found", unaddressableResource, unaddressableName),
 		}}
 
 	for n, tc := range tests {
@@ -510,7 +510,7 @@ func TestGetURIDestinationV1(t *testing.T) {
 			wantErr: fmt.Sprintf("address not set for %+v", getUnaddressableRef()),
 		}, "notFound": {
 			dest:    duckv1.Destination{Ref: getUnaddressableKnativeRef()},
-			wantErr: fmt.Sprintf("failed to get ref %+v: %s %q not found", getUnaddressableRef(), unaddressableResource, unaddressableName),
+			wantErr: fmt.Sprintf("%s %q not found", unaddressableResource, unaddressableName),
 		}}
 
 	for n, tc := range tests {
@@ -548,12 +548,11 @@ func TestURIFromObjectReferenceErrors(t *testing.T) {
 	}{"nil": {
 		wantErr: "ref is nil",
 	}, "fail tracker with bad object": {
-		ref: getInvalidObjectReference(),
-		wantErr: fmt.Sprintf(`failed to track %+v: invalid Reference:
-Namespace: a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')`, getInvalidObjectReference()),
+		ref:     getInvalidObjectReference(),
+		wantErr: `sinks.duck.knative.dev "testsink" not found`,
 	}, "fail get": {
 		ref:     getAddressableRef(),
-		wantErr: fmt.Sprintf(`failed to get ref %+v: sinks.duck.knative.dev "testsink" not found`, getAddressableRef()),
+		wantErr: `sinks.duck.knative.dev "testsink" not found`,
 	}}
 
 	for n, tc := range tests {
diff --git a/test/ghutil/fakeghutil/fakeghutil.go b/test/ghutil/fakeghutil/fakeghutil.go
index 2829b1cef..2c84d7d8c 100644
--- a/test/ghutil/fakeghutil/fakeghutil.go
+++ b/test/ghutil/fakeghutil/fakeghutil.go
@@ -209,7 +209,7 @@ func (fgc *FakeGithubClient) RemoveLabelForIssue(org, repo string, issueNumber i
 }
 
 // ListPullRequests lists pull requests within given repo, filters by head user and branch name if
-// provided as "user:ref-name", and by base name if provided, i.e. "master"
+// provided as "user:ref-name", and by base name if provided, i.e. "release-0.19"
 func (fgc *FakeGithubClient) ListPullRequests(org, repo, head, base string) ([]*github.PullRequest, error) {
 	var res []*github.PullRequest
 	PRs, ok := fgc.PullRequests[repo]
@@ -296,7 +296,7 @@ func (fgc *FakeGithubClient) EditPullRequest(org, repo string, ID int, title, bo
 	return PR, nil
 }
 
-// CreatePullRequest creates PullRequest, passing head user and branch name "user:ref-name", and base branch name like "master"
+// CreatePullRequest creates PullRequest, passing head user and branch name "user:ref-name", and base branch name like "release-0.19"
 func (fgc *FakeGithubClient) CreatePullRequest(org, repo, head, base, title, body string) (*github.PullRequest, error) {
 	PRNumber := fgc.getNextNumber()
 	stateStr := string(ghutil.PullRequestOpenState)
diff --git a/test/ghutil/pullrequest.go b/test/ghutil/pullrequest.go
index c96d8bd3b..2a4303460 100644
--- a/test/ghutil/pullrequest.go
+++ b/test/ghutil/pullrequest.go
@@ -37,7 +37,7 @@ const (
 type PullRequestState string
 
 // ListPullRequests lists pull requests within given repo, filters by head user and branch name if
-// provided as "user:ref-name", and by base name if provided, i.e. "master"
+// provided as "user:ref-name", and by base name if provided, i.e. "release-0.19"
 func (gc *GithubClient) ListPullRequests(org, repo, head, base string) ([]*github.PullRequest, error) {
 	PRsListOptions := github.PullRequestListOptions{
 		State: string(PullRequestAllState),
@@ -184,7 +184,7 @@ func (gc *GithubClient) EditPullRequest(org, repo string, ID int, title, body st
 	return res, err
 }
 
-// CreatePullRequest creates PullRequest, passing head user and branch name "user:ref-name", and base branch name like "master"
+// CreatePullRequest creates PullRequest, passing head user and branch name "user:ref-name", and base branch name like "release-0.19"
 func (gc *GithubClient) CreatePullRequest(org, repo, head, base, title, body string) (*github.PullRequest, error) {
 	b := true
 	PR := &github.NewPullRequest{