Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix go1.19 related codegen issues #1534

Merged
merged 5 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/binding-eval/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/cel-eval/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/triggerrun/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/client/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/client/clientset/versioned/scheme/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/interceptors/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

triggersv1alpha1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/interceptors/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions pkg/interceptors/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package webhook
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/interceptors/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package webhook
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/http/httputil"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/sink/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"sync"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -485,15 +485,15 @@ 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)
if err != nil {
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)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/sink/validate_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package test

import (
"fmt"
"io/ioutil"
"os"
"testing"

corev1 "k8s.io/api/core/v1"
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions test/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions test/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package test
import (
"context"
"fmt"
"io/ioutil"
"io"
"strings"

corev1 "k8s.io/api/core/v1"
Expand All @@ -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
}
Expand Down
11 changes: 5 additions & 6 deletions third_party/github.com/hashicorp/go-retryablehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"log"
"math"
"math/rand"
Expand Down Expand Up @@ -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
}
Expand All @@ -238,15 +237,15 @@ 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())
}

// 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
}
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}