From 5afd63f3b5766a71373c10d9d52e5b9eba69d549 Mon Sep 17 00:00:00 2001
From: Alvaro Aleman <alvaroaleman@users.noreply.github.com>
Date: Tue, 15 Mar 2022 18:25:04 -0400
Subject: [PATCH 1/4] Pointer: Add generic Pointer func

This adds a new, generic pointer func to the pointer package.
---
 go.mod                  |  8 +++++++-
 pointer/generic.go      |  5 +++++
 pointer/generic_test.go | 10 ++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 pointer/generic.go
 create mode 100644 pointer/generic_test.go

diff --git a/go.mod b/go.mod
index 71236960..41e29e24 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module k8s.io/utils
 
-go 1.12
+go 1.18
 
 require (
 	github.com/davecgh/go-spew v1.1.1
@@ -8,3 +8,9 @@ require (
 	github.com/stretchr/testify v1.3.0
 	k8s.io/klog/v2 v2.0.0
 )
+
+require (
+	github.com/go-logr/logr v0.1.0 // indirect
+	github.com/pmezard/go-difflib v1.0.0 // indirect
+	golang.org/x/text v0.3.0 // indirect
+)
diff --git a/pointer/generic.go b/pointer/generic.go
new file mode 100644
index 00000000..9757d8eb
--- /dev/null
+++ b/pointer/generic.go
@@ -0,0 +1,5 @@
+package pointer
+
+func Pointer[T any](in T) *T {
+	return &in
+}
diff --git a/pointer/generic_test.go b/pointer/generic_test.go
new file mode 100644
index 00000000..874e3314
--- /dev/null
+++ b/pointer/generic_test.go
@@ -0,0 +1,10 @@
+package pointer
+
+import "testing"
+
+func TestPointer(t *testing.T) {
+	ptr := Pointer(5)
+	if *ptr != 5 {
+		t.Errorf("expected pointer value to be 5, was %v", *ptr)
+	}
+}

From 5c43bf6bdf16bb0759e57a24f0abcdc916123da9 Mon Sep 17 00:00:00 2001
From: Alvaro Aleman <alvaroaleman@users.noreply.github.com>
Date: Mon, 21 Mar 2022 09:38:41 -0400
Subject: [PATCH 2/4] Inotify: Fix tests to pass go vet

---
 inotify/inotify_linux_test.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/inotify/inotify_linux_test.go b/inotify/inotify_linux_test.go
index cf56843f..dd5e662f 100644
--- a/inotify/inotify_linux_test.go
+++ b/inotify/inotify_linux_test.go
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build linux
 // +build linux
 
 package inotify
@@ -34,9 +35,11 @@ func TestInotifyEvents(t *testing.T) {
 	}
 
 	// Receive errors on the error channel on a separate goroutine
+	var watcherErrs []error
 	go func() {
 		for err := range watcher.Error {
-			t.Fatalf("error received: %s", err)
+			// Fatal inside a goroutine is not allowed
+			watcherErrs = append(watcherErrs, err)
 		}
 	}()
 
@@ -82,6 +85,12 @@ func TestInotifyEvents(t *testing.T) {
 	case <-time.After(1 * time.Second):
 		t.Fatal("event stream was not closed after 1 second")
 	}
+
+	for _, err := range watcherErrs {
+		if err != nil {
+			t.Errorf("watcher had error: %v", err)
+		}
+	}
 }
 
 func TestInotifyClose(t *testing.T) {

From c6efb676fbb5170511dcea8de057c9cf368dc08c Mon Sep 17 00:00:00 2001
From: Alvaro Aleman <alvaroaleman@users.noreply.github.com>
Date: Tue, 15 Mar 2022 18:38:55 -0400
Subject: [PATCH 3/4] Update CI to use go 1.18

---
 .github/workflows/test.yml | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 8031d8f6..ff20039b 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -4,16 +4,16 @@ jobs:
   build:
     strategy:
       matrix:
-        go-versions: [1.13.x]
+        go-versions: [1.18.x]
         platform: [windows-latest]
     runs-on: ${{ matrix.platform }}
     steps:
       - name: Install Go
-        uses: actions/setup-go@v1
+        uses: actions/setup-go@v3
         with:
-          go-version: ${{ matrix.go-version }}
+          go-version: ${{ matrix.go-versions }}
       - name: Checkout code
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
       - name: Build
         run: |
           go build ./...
@@ -24,16 +24,16 @@ jobs:
   test:
     strategy:
       matrix:
-        go-versions: [1.12.x, 1.13.x, 1.14.x]
+        go-versions: [1.18.x]
         platform: [ubuntu-latest, macos-latest]
     runs-on: ${{ matrix.platform }}
     steps:
     - name: Install Go
-      uses: actions/setup-go@v1
+      uses: actions/setup-go@v3
       with:
-        go-version: ${{ matrix.go-version }}
+        go-version: ${{ matrix.go-versions }}
     - name: Checkout code
-      uses: actions/checkout@v2
+      uses: actions/checkout@v3
     - name: Test
       run: |
         make test
@@ -41,28 +41,30 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Install Go
-        uses: actions/setup-go@v1
+        uses: actions/setup-go@v3
+        with:
+          go-version: 1.18.x
       - name: Checkout code
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
       - name: Lint
         run: |
-          docker run --rm -v `pwd`:/go/src/k8s.io/klog -w /go/src/k8s.io/klog \
-            golangci/golangci-lint:v1.23.8 golangci-lint run --disable-all -v \
+          docker run --rm -v `pwd`:/go/src/k8s.io/util -w /go/src/k8s.io/util \
+            golangci/golangci-lint:v1.45.0 golangci-lint run --go 1.18 --disable-all -v \
             -E govet -E misspell -E gofmt -E ineffassign -E golint
   apidiff:
     runs-on: ubuntu-latest
     if: github.base_ref
     steps:
       - name: Install Go
-        uses: actions/setup-go@v1
+        uses: actions/setup-go@v3
         with:
-          go-version: 1.13.x
+          go-version: 1.18.x
       - name: Add GOBIN to PATH
         run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
       - name: Install dependencies
-        run: go get golang.org/x/exp/cmd/apidiff
+        run: go install golang.org/x/exp/cmd/apidiff@latest
       - name: Checkout old code
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
         with:
           ref: ${{ github.base_ref }}
           path: "old"

From fb151ba15dbb54edf556ffb13adcc04d3b90ce77 Mon Sep 17 00:00:00 2001
From: Alvaro Aleman <alvaroaleman@users.noreply.github.com>
Date: Mon, 21 Mar 2022 09:52:30 -0400
Subject: [PATCH 4/4] forked/golang/net: Make tests pass

---
 internal/third_party/forked/golang/net/ip.go      | 13 +++++++++++++
 internal/third_party/forked/golang/net/ip_test.go |  5 ++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/internal/third_party/forked/golang/net/ip.go b/internal/third_party/forked/golang/net/ip.go
index 4340b6e7..9a3aea29 100644
--- a/internal/third_party/forked/golang/net/ip.go
+++ b/internal/third_party/forked/golang/net/ip.go
@@ -29,6 +29,19 @@ import (
 //
 
 type IP = stdnet.IP
+
+func IPUnmarshalText(text []byte) (IP, error) {
+	if len(text) == 0 {
+		return nil, nil
+	}
+	s := string(text)
+	x := ParseIP(s)
+	if x == nil {
+		return nil, &ParseError{Type: "IP address", Text: s}
+	}
+	return x, nil
+}
+
 type IPNet = stdnet.IPNet
 type ParseError = stdnet.ParseError
 
diff --git a/internal/third_party/forked/golang/net/ip_test.go b/internal/third_party/forked/golang/net/ip_test.go
index 6271f4fc..7bc97236 100644
--- a/internal/third_party/forked/golang/net/ip_test.go
+++ b/internal/third_party/forked/golang/net/ip_test.go
@@ -80,9 +80,8 @@ func TestParseIP(t *testing.T) {
 			// Tested in TestMarshalEmptyIP below.
 			continue
 		}
-		var out IP
-		if err := out.UnmarshalText([]byte(tt.in)); !reflect.DeepEqual(out, tt.out) || (tt.out == nil) != (err != nil) {
-			t.Errorf("IP.UnmarshalText(%q) = %v, %v, want %v", tt.in, out, err, tt.out)
+		if out, err := IPUnmarshalText([]byte(tt.in)); !reflect.DeepEqual(out, tt.out) || (tt.out == nil) != (err != nil) {
+			t.Errorf("IPUnmarshalText(%q) = %v, %v, want %v", tt.in, out, err, tt.out)
 		}
 	}
 }