Repository: knative/pkg
Pull request #2429 (2022-02-16 01:32:34)

[main] Upgrade to latest dependencies
Cron -knative-prow-robot

/cc knative/serving-writers knative/eventing-writers
/assign knative/serving-writers knative/eventing-writers

Produced by: knative-sandbox/knobots/actions/update-deps

Details:
```
bumping knative.dev/hack 7331bb1...0456e8b:
  > 0456e8b Update community files (# 152)
  > b9cb198 Update community files (# 151)
  > 0e30607 Update kntest path after https://github.com/knative/test-infra/pull/3087 (# 150)
```

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

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/2429#" title="Author self-approved">knative-automation</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **n3wscott** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @n3wscott` in a comment when ready.

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

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

- **[OWNERS](https://github.com/knative/pkg/blob/main/OWNERS)**

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":["n3wscott"]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative/pkg/pull/2429?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) Report
> Merging [#2429](https://codecov.io/gh/knative/pkg/pull/2429?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) (b7afe61) into [main](https://codecov.io/gh/knative/pkg/commit/3c00bb0157b9242359df6868e720861b6807773f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) (3c00bb0) will **increase** coverage by `0.03%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/knative/pkg/pull/2429/graphs/tree.svg?width=650&height=150&src=pr&token=rlqpDnfxbO&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative)](https://codecov.io/gh/knative/pkg/pull/2429?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative)

```diff
@@            Coverage Diff             @@
##             main    #2429      +/-   ##
==========================================
+ Coverage   63.43%   63.46%   +0.03%     
==========================================
  Files         228      228              
  Lines        9973     9973              
==========================================
+ Hits         6326     6329       +3     
+ Misses       3345     3344       -1     
+ Partials      302      300       -2     
```


| [Impacted Files](https://codecov.io/gh/knative/pkg/pull/2429?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative) | Coverage Δ | |
|---|---|---|
| [controller/controller.go](https://codecov.io/gh/knative/pkg/pull/2429/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative#diff-Y29udHJvbGxlci9jb250cm9sbGVyLmdv) | `86.13% <0.00%> (-0.37%)` | :arrow_down: |
| [test/gcs/mock/mock.go](https://codecov.io/gh/knative/pkg/pull/2429/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative#diff-dGVzdC9nY3MvbW9jay9tb2NrLmdv) | `92.47% <0.00%> (+2.15%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/knative/pkg/pull/2429?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/knative/pkg/pull/2429?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative). Last update [3c00bb0...b7afe61](https://codecov.io/gh/knative/pkg/pull/2429?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative).


Patch:
diff --git a/apis/url.go b/apis/url.go
index 89a4d2454..e54cb1d07 100644
--- a/apis/url.go
+++ b/apis/url.go
@@ -27,6 +27,7 @@ import (
 // URL is an alias of url.URL.
 // It has custom json marshal methods that enable it to be used in K8s CRDs
 // such that the CRD resource will have the URL but operator code can can work with url.URL struct
+// +kubebuilder:validation:Type=string
 type URL url.URL
 
 // ParseURL attempts to parse the given string as a URL.
diff --git a/changeset/commit.go b/changeset/commit.go
index 52c77998f..3668dfebd 100644
--- a/changeset/commit.go
+++ b/changeset/commit.go
@@ -17,6 +17,7 @@ limitations under the License.
 package changeset
 
 import (
+	"bufio"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -28,6 +29,10 @@ import (
 const (
 	commitIDFile      = "HEAD"
 	koDataPathEnvName = "KO_DATA_PATH"
+	// packedRefsFile is a file containing a list of refs, used to compact the
+	// list of refs instead of storing them on the filesystem directly.
+	// See https://git-scm.com/docs/git-pack-refs
+	packedRefsFile = "packed-refs"
 )
 
 var commitIDRE = regexp.MustCompile(`^[a-f0-9]{40}$`)
@@ -41,9 +46,27 @@ func Get() (string, error) {
 	}
 	commitID := strings.TrimSpace(string(data))
 	if rID := strings.TrimPrefix(commitID, "ref: "); rID != commitID {
+		// First try to read from the direct ref file - e.g. refs/heads/main
 		data, err := readFileFromKoData(rID)
 		if err != nil {
-			return "", err
+			if !os.IsNotExist(err) {
+				return "", err
+			}
+
+			// Ref file didn't exist - it might be contained in the packed-refs
+			// file.
+			var pferr error
+			data, pferr = findPackedRef(rID)
+			// Only return the sub-error if the packed-refs file exists, otherwise
+			// just let the original error return (e.g. treat it as if we didn't
+			// even attempt the operation). This is primarily to keep the error
+			// messages clean.
+			if pferr != nil {
+				if os.IsNotExist(pferr) {
+					return "", err
+				}
+				return "", pferr
+			}
 		}
 		commitID = strings.TrimSpace(string(data))
 	}
@@ -58,9 +81,49 @@ func Get() (string, error) {
 // to be wrapped into the container from /kodata by ko. If it fails, returns
 // the error it gets.
 func readFileFromKoData(filename string) ([]byte, error) {
+	f, err := koDataFile(filename)
+	if err != nil {
+		return nil, err
+	}
+	defer f.Close()
+	return ioutil.ReadAll(f)
+}
+
+// readFileFromKoData tries to open the file with given name under KO_DATA_PATH.
+// The file is expected to be wrapped into the container from /kodata by ko.
+// If it fails, returns the error it gets.
+func koDataFile(filename string) (*os.File, error) {
 	koDataPath := os.Getenv(koDataPathEnvName)
 	if koDataPath == "" {
 		return nil, fmt.Errorf("%q does not exist or is empty", koDataPathEnvName)
 	}
-	return ioutil.ReadFile(filepath.Join(koDataPath, filename))
+	return os.Open(filepath.Join(koDataPath, filename))
+}
+
+// findPackedRef searches the packed-ref file for ref values.
+// This can happen if the # of refs in a repo grows too much - git will try
+// and condense them into a file.
+// See https://git-scm.com/docs/git-pack-refs
+func findPackedRef(ref string) ([]byte, error) {
+	f, err := koDataFile(packedRefsFile)
+	if err != nil {
+		return nil, err
+	}
+	defer f.Close()
+
+	scanner := bufio.NewScanner(f)
+	for scanner.Scan() {
+		// We only care about lines with `<commit> <ref>` pairs.
+		// Why this might happen:
+		// 1. Lines starting with ^ refer to unpeeled tag SHAs
+		// 	  (e.g. the commits pointed to by annotated tags)
+		s := strings.Split(scanner.Text(), " ")
+		if len(s) != 2 {
+			continue
+		}
+		if ref == s[1] {
+			return []byte(s[0]), nil
+		}
+	}
+	return nil, fmt.Errorf("%q ref not found in packed-refs", ref)
 }
diff --git a/go.mod b/go.mod
index 7f5d14e88..94b63aa47 100644
--- a/go.mod
+++ b/go.mod
@@ -48,7 +48,7 @@ require (
 	k8s.io/code-generator v0.22.5
 	k8s.io/gengo v0.0.0-20211129171323-c02415ce4185
 	k8s.io/klog/v2 v2.40.1
-	knative.dev/hack v0.0.0-20220209225905-7331bb16ba00
+	knative.dev/hack v0.0.0-20220216040439-0456e8bf6547
 	sigs.k8s.io/yaml v1.3.0
 )
 
diff --git a/go.sum b/go.sum
index 8f5639cec..cf590afa0 100644
--- a/go.sum
+++ b/go.sum
@@ -1152,8 +1152,8 @@ k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c h1:jvamsI1tn9V0S8jicyX82q
 k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
 k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a h1:8dYfu/Fc9Gz2rNJKB9IQRGgQOh2clmRzNIPPY1xLY5g=
 k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
-knative.dev/hack v0.0.0-20220209225905-7331bb16ba00 h1:MbdDq3JZoCoUzYbw/liB0Idklk/fE2bXiSQnIRhgeC4=
-knative.dev/hack v0.0.0-20220209225905-7331bb16ba00/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
+knative.dev/hack v0.0.0-20220216040439-0456e8bf6547 h1:lEWsaG/yMLLp3onNushrawsHFXD4LXCXTo5FUUa2GiU=
+knative.dev/hack v0.0.0-20220216040439-0456e8bf6547/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
 pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
 pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
 rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
diff --git a/vendor/knative.dev/hack/README.md b/vendor/knative.dev/hack/README.md
index 570f37097..de565f7c5 100644
--- a/vendor/knative.dev/hack/README.md
+++ b/vendor/knative.dev/hack/README.md
@@ -111,7 +111,7 @@ main "$@"
 This is a helper script for Knative E2E test scripts. To use it:
 
 1. [optional] Customize the test cluster. Pass the flags as described
-   [here](../kntest/pkg/kubetest2/gke/README.md) to the `initialize` function
+   [here](../tools/kntest/pkg/kubetest2/gke/README.md) to the `initialize` function
    call if the default values don't fit your needs.
 
 1. Source the script.
diff --git a/vendor/knative.dev/hack/library.sh b/vendor/knative.dev/hack/library.sh
index 17ce662ed..8f7b3997e 100644
--- a/vendor/knative.dev/hack/library.sh
+++ b/vendor/knative.dev/hack/library.sh
@@ -695,7 +695,7 @@ function go_mod_gopath_hack() {
 # Parameters: $1..$n - parameters passed to the tool.
 function run_kntest() {
   if [[ ! -x "$(command -v kntest)" ]]; then
-    echo "--- FAIL: kntest not installed, please clone knative test-infra repo and run \`go install ./kntest/cmd/kntest\` to install it"; return 1;
+    echo "--- FAIL: kntest not installed, please clone knative test-infra repo and run \`go install ./tools/kntest/cmd/kntest\` to install it"; return 1;
   fi
   kntest "$@"
 }
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 1da7e5475..bdc8e5e00 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -1060,7 +1060,7 @@ k8s.io/utils/buffer
 k8s.io/utils/integer
 k8s.io/utils/pointer
 k8s.io/utils/trace
-# knative.dev/hack v0.0.0-20220209225905-7331bb16ba00
+# knative.dev/hack v0.0.0-20220216040439-0456e8bf6547
 ## explicit; go 1.14
 knative.dev/hack
 # sigs.k8s.io/structured-merge-diff/v4 v4.1.2


Test patch:
diff --git a/changeset/commit_test.go b/changeset/commit_test.go
index 6552971eb..057bccfe0 100644
--- a/changeset/commit_test.go
+++ b/changeset/commit_test.go
@@ -70,6 +70,15 @@ func TestReadFile(t *testing.T) {
 		koDataPath: "testdata/nonexisting",
 		wantErr:    true,
 		err:        errors.New("open testdata/nonexisting/HEAD: no such file or directory"),
+	}, {
+		name:       "packed-ref",
+		koDataPath: "testdata/packed-refs",
+		want:       testCommitID,
+	}, {
+		name:       "no refs with packed-ref",
+		koDataPath: "testdata/noncommited-packed-refs",
+		wantErr:    true,
+		err:        fmt.Errorf("%q ref not found in packed-refs", nonCommittedHeadRef),
 	}}
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {
diff --git a/changeset/testdata/noncommited-packed-refs/HEAD b/changeset/testdata/noncommited-packed-refs/HEAD
new file mode 100644
index 000000000..89fe2d356
--- /dev/null
+++ b/changeset/testdata/noncommited-packed-refs/HEAD
@@ -0,0 +1,1 @@
+ref: refs/heads/non_committed_branch
diff --git a/changeset/testdata/noncommited-packed-refs/packed-refs b/changeset/testdata/noncommited-packed-refs/packed-refs
new file mode 100644
index 000000000..e69de29bb
diff --git a/changeset/testdata/packed-refs/HEAD b/changeset/testdata/packed-refs/HEAD
new file mode 100644
index 000000000..19af7398c
--- /dev/null
+++ b/changeset/testdata/packed-refs/HEAD
@@ -0,0 +1,1 @@
+ref: refs/heads/foo
diff --git a/changeset/testdata/packed-refs/packed-refs b/changeset/testdata/packed-refs/packed-refs
new file mode 100644
index 000000000..634ca6720
--- /dev/null
+++ b/changeset/testdata/packed-refs/packed-refs
@@ -0,0 +1,4 @@
+a2d1bdfe929516d7da141aef68631a7ee6941b2d refs/tags/bar
+^51be315ed160e68627a3bc51a244ec77e470c667
+a2d1bdfe929516d7da141aef68631a7ee6941b2d refs/tags/baz
+a2d1bdfe929516d7da141aef68631a7ee6941b2d refs/heads/foo