From c834703bf521c13f84531f549ed4fd2f07f49260 Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Thu, 23 Feb 2023 21:45:58 +0530 Subject: [PATCH 1/5] Fix go1.19 related codegen issues Updated code by running ./hack/codegen.sh with go1.19. Needed for passing the tests. --- pkg/client/clientset/versioned/fake/register.go | 14 +++++++------- pkg/client/clientset/versioned/scheme/register.go | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 20862cffd..50707b118 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -39,14 +39,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index b3ba74848..da59cdf0e 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -39,14 +39,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. From 85f0b16af42351c37c146f2997c0418eab151219 Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Sun, 29 Jan 2023 21:00:21 +0800 Subject: [PATCH 2/5] [triggers/pkg] clean up ioutil for new go version Signed-off-by: xin.li --- pkg/interceptors/interceptors.go | 4 ++-- pkg/interceptors/server/server_test.go | 6 +++--- pkg/interceptors/webhook/webhook.go | 4 ++-- pkg/interceptors/webhook/webhook_test.go | 4 ++-- pkg/sink/sink.go | 10 +++++----- pkg/sink/validate_payload.go | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/interceptors/interceptors.go b/pkg/interceptors/interceptors.go index 65d42ea61..05cee74aa 100644 --- a/pkg/interceptors/interceptors.go +++ b/pkg/interceptors/interceptors.go @@ -21,7 +21,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" triggersv1alpha1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1" @@ -128,7 +128,7 @@ func Execute(ctx context.Context, client *http.Client, req *triggersv1beta1.Inte if err != nil { return nil, err } - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) defer res.Body.Close() if err != nil { return nil, err diff --git a/pkg/interceptors/server/server_test.go b/pkg/interceptors/server/server_test.go index 3cad62287..7d49eb085 100644 --- a/pkg/interceptors/server/server_test.go +++ b/pkg/interceptors/server/server_test.go @@ -5,7 +5,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "os" @@ -116,7 +116,7 @@ func TestServer_ServeHTTP(t *testing.T) { t.Fatalf("ServeHTTP() expected Content-Type header to be application/json but got: %s", resp.Header.Get("Content-Type")) } - respBody, _ := ioutil.ReadAll(resp.Body) + respBody, _ := io.ReadAll(resp.Body) defer resp.Body.Close() got := v1alpha1.InterceptorResponse{} if err := json.Unmarshal(respBody, &got); err != nil { @@ -172,7 +172,7 @@ func TestServer_ServeHTTP_Error(t *testing.T) { t.Fatalf("ServeHTTP() expected statusCode %d but got: %d", tc.wantResponseCode, resp.StatusCode) } - respBody, _ := ioutil.ReadAll(resp.Body) + respBody, _ := io.ReadAll(resp.Body) defer resp.Body.Close() if !strings.Contains(string(respBody), tc.wantResponseBody) { t.Fatalf("ServeHTTP() expected response to contain : %s \n but got %s: ", tc.wantResponseBody, string(respBody)) diff --git a/pkg/interceptors/webhook/webhook.go b/pkg/interceptors/webhook/webhook.go index 88bbe5c2b..89bab295f 100644 --- a/pkg/interceptors/webhook/webhook.go +++ b/pkg/interceptors/webhook/webhook.go @@ -19,7 +19,7 @@ package webhook import ( "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -74,7 +74,7 @@ func (w *Interceptor) ExecuteTrigger(request *http.Request) (*http.Response, err return resp, err } if resp.StatusCode != http.StatusOK { - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if err != nil { return resp, errors.New("failed to parse response body") } diff --git a/pkg/interceptors/webhook/webhook_test.go b/pkg/interceptors/webhook/webhook_test.go index d0553fd60..feaa1b37b 100644 --- a/pkg/interceptors/webhook/webhook_test.go +++ b/pkg/interceptors/webhook/webhook_test.go @@ -19,7 +19,7 @@ package webhook import ( "bytes" "encoding/json" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/http/httputil" @@ -91,7 +91,7 @@ func TestWebHookInterceptor(t *testing.T) { t.Fatalf("ExecuteTrigger: %v", err) } - resPayload, _ := ioutil.ReadAll(resp.Body) + resPayload, _ := io.ReadAll(resp.Body) defer resp.Body.Close() if diff := cmp.Diff(wantPayload, resPayload); diff != "" { t.Errorf("response payload (-want, +got) = %s", diff) diff --git a/pkg/sink/sink.go b/pkg/sink/sink.go index a9bad80e0..1ad135789 100644 --- a/pkg/sink/sink.go +++ b/pkg/sink/sink.go @@ -22,7 +22,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "os" "sync" @@ -150,7 +150,7 @@ func (r Sink) HandleEvent(response http.ResponseWriter, request *http.Request) { r.emitEvents(r.EventRecorder, &elTemp, events.TriggerProcessingStartedV1, nil) r.sendCloudEvents(request.Header, elTemp, eventID, events.TriggerProcessingStartedV1) - event, err := ioutil.ReadAll(request.Body) + event, err := io.ReadAll(request.Body) if err != nil { log.Errorf("Error reading event body: %s", err) r.recordCountMetrics(failTag) @@ -341,7 +341,7 @@ func (r Sink) processTriggerGroups(g triggersv1.EventListenerTriggerGroup, el *t // This request will be passed on to the triggers in this group triggerReq := request.Clone(request.Context()) triggerReq.Header = header - triggerReq.Body = ioutil.NopCloser(bytes.NewBuffer(payload)) + triggerReq.Body = io.NopCloser(bytes.NewBuffer(payload)) wg.Add(len(trItems)) for _, t := range trItems { @@ -485,7 +485,7 @@ func (r Sink) ExecuteInterceptors(trInt []*triggersv1.TriggerInterceptor, in *ht Method: http.MethodPost, Header: request.Header, URL: in.URL, - Body: ioutil.NopCloser(bytes.NewBuffer(body)), + Body: io.NopCloser(bytes.NewBuffer(body)), } interceptor := webhook.NewInterceptor(i.Webhook, r.HTTPClient, namespace, log) res, err := interceptor.ExecuteTrigger(req) @@ -493,7 +493,7 @@ func (r Sink) ExecuteInterceptors(trInt []*triggersv1.TriggerInterceptor, in *ht return nil, nil, nil, err } - payload, err := ioutil.ReadAll(res.Body) + payload, err := io.ReadAll(res.Body) if err != nil { return nil, nil, nil, fmt.Errorf("error reading webhook interceptor response body: %w", err) } diff --git a/pkg/sink/validate_payload.go b/pkg/sink/validate_payload.go index 53cb96182..6691f2908 100644 --- a/pkg/sink/validate_payload.go +++ b/pkg/sink/validate_payload.go @@ -20,14 +20,14 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" ) func (r Sink) IsValidPayload(eventHandler http.Handler) http.Handler { return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) { - payload, err := ioutil.ReadAll(request.Body) - request.Body = ioutil.NopCloser(bytes.NewBuffer(payload)) + payload, err := io.ReadAll(request.Body) + request.Body = io.NopCloser(bytes.NewBuffer(payload)) if err != nil { r.recordCountMetrics(failTag) r.Logger.Errorf("Error reading event body: %s", err) From 7d6b1bc142bb2ce1cc54a919d45e4c0b7f9938bd Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Fri, 16 Dec 2022 23:28:26 +0800 Subject: [PATCH 3/5] [truggers/cmd] clean up ioutil for new go version Signed-off-by: xin.li --- cmd/binding-eval/cmd/root.go | 3 +-- cmd/cel-eval/cmd/root.go | 5 ++--- cmd/triggerrun/cmd/root.go | 5 ++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cmd/binding-eval/cmd/root.go b/cmd/binding-eval/cmd/root.go index 8c38fa88e..e1e2297ea 100644 --- a/cmd/binding-eval/cmd/root.go +++ b/cmd/binding-eval/cmd/root.go @@ -21,7 +21,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -138,7 +137,7 @@ func readHTTP(path string) (*http.Request, []byte, error) { return nil, nil, fmt.Errorf("error reading request: %w", err) } defer req.Body.Close() - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) if err != nil { return nil, nil, fmt.Errorf("error reading HTTP body: %w", err) } diff --git a/cmd/cel-eval/cmd/root.go b/cmd/cel-eval/cmd/root.go index ea85ca7a4..d069253bb 100644 --- a/cmd/cel-eval/cmd/root.go +++ b/cmd/cel-eval/cmd/root.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -118,7 +117,7 @@ func readExpression(path string) (string, error) { } defer f.Close() - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) if err != nil { return "", fmt.Errorf("error reading from file: %w", err) } @@ -138,7 +137,7 @@ func readHTTP(path string) (*http.Request, []byte, error) { return nil, nil, fmt.Errorf("error reading request: %w", err) } defer req.Body.Close() - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) if err != nil { return nil, nil, fmt.Errorf("error reading HTTP body: %w", err) } diff --git a/cmd/triggerrun/cmd/root.go b/cmd/triggerrun/cmd/root.go index 9f8d34ce3..e06a0860d 100644 --- a/cmd/triggerrun/cmd/root.go +++ b/cmd/triggerrun/cmd/root.go @@ -24,7 +24,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -179,13 +178,13 @@ func readHTTP(path string) (*http.Request, []byte, error) { return nil, nil, fmt.Errorf("error reading HTTP file: %w", err) } - body, err := ioutil.ReadAll(request.Body) + body, err := io.ReadAll(request.Body) defer request.Body.Close() if err != nil { return nil, nil, fmt.Errorf("error reading HTTP body: %w", err) } - request.Body = ioutil.NopCloser(bytes.NewReader(body)) + request.Body = io.NopCloser(bytes.NewReader(body)) return request, body, err } From b87b29a0e0d935fe14430cbdf235540e98d5e9b7 Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Fri, 16 Dec 2022 23:21:20 +0800 Subject: [PATCH 4/5] [third_party] clean up ioutil for new go version Signed-off-by: xin.li --- .../github.com/hashicorp/go-retryablehttp/client.go | 11 +++++------ .../hashicorp/golang-lru/simplelru/lru_interface.go | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/third_party/github.com/hashicorp/go-retryablehttp/client.go b/third_party/github.com/hashicorp/go-retryablehttp/client.go index 57116e960..77e4fae66 100644 --- a/third_party/github.com/hashicorp/go-retryablehttp/client.go +++ b/third_party/github.com/hashicorp/go-retryablehttp/client.go @@ -27,7 +27,6 @@ import ( "crypto/x509" "fmt" "io" - "io/ioutil" "log" "math" "math/rand" @@ -224,7 +223,7 @@ func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, erro // deal with it seeking so want it to match here instead of the // io.ReadSeeker case. case *bytes.Reader: - buf, err := ioutil.ReadAll(body) + buf, err := io.ReadAll(body) if err != nil { return nil, 0, err } @@ -238,7 +237,7 @@ func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, erro raw := body bodyReader = func() (io.Reader, error) { _, err := raw.Seek(0, 0) - return ioutil.NopCloser(raw), err + return io.NopCloser(raw), err } if lr, ok := raw.(LenReader); ok { contentLength = int64(lr.Len()) @@ -246,7 +245,7 @@ func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, erro // Read all in so we can reset case io.Reader: - buf, err := ioutil.ReadAll(body) + buf, err := io.ReadAll(body) if err != nil { return nil, 0, err } @@ -602,7 +601,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) { if c, ok := body.(io.ReadCloser); ok { req.Body = c } else { - req.Body = ioutil.NopCloser(body) + req.Body = io.NopCloser(body) } } @@ -738,7 +737,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) { // Try to read the response body so we can reuse this connection. func (c *Client) drainBody(body io.ReadCloser) { defer body.Close() - _, err := io.Copy(ioutil.Discard, io.LimitReader(body, respReadLimit)) + _, err := io.Copy(io.Discard, io.LimitReader(body, respReadLimit)) if err != nil { if c.logger() != nil { switch v := c.logger().(type) { diff --git a/third_party/github.com/hashicorp/golang-lru/simplelru/lru_interface.go b/third_party/github.com/hashicorp/golang-lru/simplelru/lru_interface.go index 92d70934d..a0b97e3f7 100644 --- a/third_party/github.com/hashicorp/golang-lru/simplelru/lru_interface.go +++ b/third_party/github.com/hashicorp/golang-lru/simplelru/lru_interface.go @@ -34,6 +34,6 @@ type LRUCache interface { // Clears all cache entries. Purge() - // Resizes cache, returning number evicted - Resize(int) int + // Resizes cache, returning number evicted + Resize(int) int } From 8ee8d92f3ed617538646e3df7d1f6e5027305aa3 Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Thu, 23 Feb 2023 22:19:18 +0530 Subject: [PATCH 5/5] Remove deprecated pkg ioutil from test --- test/configmap.go | 4 ++-- test/eventlistener_test.go | 4 ++-- test/logs.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/configmap.go b/test/configmap.go index 04b180b54..8fd5564bd 100644 --- a/test/configmap.go +++ b/test/configmap.go @@ -18,7 +18,7 @@ package test import ( "fmt" - "io/ioutil" + "os" "testing" corev1 "k8s.io/api/core/v1" @@ -30,7 +30,7 @@ import ( func ConfigMapFromTestFile(t *testing.T, name string) *corev1.ConfigMap { t.Helper() - b, err := ioutil.ReadFile(fmt.Sprintf("testdata/%s.yaml", name)) + b, err := os.ReadFile(fmt.Sprintf("testdata/%s.yaml", name)) if err != nil { t.Fatalf("ReadFile() = %v", err) } diff --git a/test/eventlistener_test.go b/test/eventlistener_test.go index f974fadce..9099c941f 100644 --- a/test/eventlistener_test.go +++ b/test/eventlistener_test.go @@ -24,9 +24,9 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "net/http" "net/url" + "os" "path/filepath" "strconv" "strings" @@ -68,7 +68,7 @@ const ( func loadExamplePREventBytes(t *testing.T) []byte { t.Helper() path := filepath.Join("testdata", examplePRJsonFilename) - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { t.Fatalf("Couldn't load test data example PullREquest event data: %v", err) } diff --git a/test/logs.go b/test/logs.go index f908eb59b..a89f88787 100644 --- a/test/logs.go +++ b/test/logs.go @@ -19,7 +19,7 @@ package test import ( "context" "fmt" - "io/ioutil" + "io" "strings" corev1 "k8s.io/api/core/v1" @@ -40,7 +40,7 @@ func CollectPodLogsWithLabel(c kubernetes.Interface, namespace, labelSelector st if err != nil { return "", err } - bs, err := ioutil.ReadAll(rc) + bs, err := io.ReadAll(rc) if err != nil { return "", err }