Skip to content

Commit

Permalink
Fix/go deprecations (#1857)
Browse files Browse the repository at this point in the history
* ioutil.Discard to io.Discard

Signed-off-by: Sandor Szücs <[email protected]>

* ioutil.NopCloser to io.NopCloser

Signed-off-by: Sandor Szücs <[email protected]>

* ioutil.ReadAll to io.ReadAll

Signed-off-by: Sandor Szücs <[email protected]>

* ioutil.ReadDir to os.ReadDir and ioutil.ReadFile to os.ReadFile

Signed-off-by: Sandor Szücs <[email protected]>

* ioutil.TempDir to os.MkdirTemp and ioutil.TempFile to os.CreateTemp

Signed-off-by: Sandor Szücs <[email protected]>

* ioutil.WriteFile to os.WriteFile

Signed-off-by: Sandor Szücs <[email protected]>

* fix obstacle in fs interface change

Signed-off-by: Sandor Szücs <[email protected]>

* set go to 1.17

Signed-off-by: Sandor Szücs <[email protected]>

* cleanup ioutil in doc reference

Signed-off-by: Sandor Szücs <[email protected]>

* set 1.16 as suggested

Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs authored Sep 21, 2021
1 parent 19afc43 commit 7f4a3e9
Show file tree
Hide file tree
Showing 75 changed files with 211 additions and 240 deletions.
4 changes: 2 additions & 2 deletions cmd/eskip/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/zalando/skipper/eskip"
)
Expand Down Expand Up @@ -144,7 +144,7 @@ func takePatchFilters(media []*medium) (prep, app []*eskip.Filter, err error) {
fstr = m.patchFilters
case patchPrependFile, patchAppendFile:
var b []byte
b, err = ioutil.ReadFile(m.patchFile)
b, err = os.ReadFile(m.patchFile)
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/eskip/readclient.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package main

import (
"io"
"os"

"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/eskipfile"
etcdclient "github.com/zalando/skipper/etcd"
innkeeperclient "github.com/zalando/skipper/innkeeper"
"io"
"io/ioutil"
"os"
)

type readClient interface {
Expand Down Expand Up @@ -80,7 +80,7 @@ func (r *stdinReader) LoadAndParseAll() ([]*eskip.RouteInfo, error) {
// and deletes the diff only after, it may not
// even be consistent to do continuous piping.
// May change in the future.
doc, err := ioutil.ReadAll(r.reader)
doc, err := io.ReadAll(r.reader)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/webhook/admission/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package admission
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -117,7 +117,7 @@ func Handler(admitter Admitter) http.HandlerFunc {
return
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
log.Errorf("Failed to read request: %v", err)
w.WriteHeader(http.StatusInternalServerError)
Expand Down
6 changes: 3 additions & 3 deletions cmd/webhook/admission/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package admission
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestResponseEncoding(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)

reviewResp := admissionsv1.AdmissionReview{}
rb, err := ioutil.ReadAll(resp.Body)
rb, err := io.ReadAll(resp.Body)
assert.NoError(t, err, "could not read response")

err = json.Unmarshal(rb, &reviewResp)
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestAdmitRouteGroups(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)

respReview := &admissionsv1.AdmissionReview{}
rb, err := ioutil.ReadAll(resp.Body)
rb, err := io.ReadAll(resp.Body)
assert.NoError(t, err, "could not read response")
err = json.Unmarshal(rb, &respReview)
assert.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"sort"
Expand Down Expand Up @@ -492,7 +491,7 @@ func (c *Config) Parse() error {

configKeys := make(map[string]interface{})
if c.ConfigFile != "" {
yamlFile, err := ioutil.ReadFile(c.ConfigFile)
yamlFile, err := os.ReadFile(c.ConfigFile)
if err != nil {
return fmt.Errorf("invalid config file: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions dataclients/kubernetes/clusterclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
"regexp"
"sort"
"time"
Expand Down Expand Up @@ -69,7 +69,7 @@ func buildHTTPClient(certFilePath string, inCluster bool, quit <-chan struct{})
return http.DefaultClient, nil
}

rootCA, err := ioutil.ReadFile(certFilePath)
rootCA, err := os.ReadFile(certFilePath)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions dataclients/kubernetes/defaultfilters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package kubernetes

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -23,21 +22,22 @@ type filterSet struct {
type defaultFilters map[definitions.ResourceID]*filterSet

func readDefaultFilters(dir string) (defaultFilters, error) {
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return nil, err
}

filters := make(defaultFilters)
for _, f := range files {
r := strings.Split(f.Name(), ".") // format: {service}.{namespace}
if len(r) != 2 || !(f.Mode().IsRegular() || f.Mode()&os.ModeSymlink != 0) || f.Size() > maxFileSize {
info, err := f.Info()
if len(r) != 2 || !(f.Type().IsRegular() || f.Type()&os.ModeSymlink != 0) || info.Size() > maxFileSize {
log.WithError(err).WithField("file", f.Name()).Debug("incompatible file")
continue
}

file := filepath.Join(dir, f.Name())
config, err := ioutil.ReadFile(file)
config, err := os.ReadFile(file)
if err != nil {
log.WithError(err).WithField("file", file).Debug("could not read file")
continue
Expand Down
21 changes: 10 additions & 11 deletions dataclients/kubernetes/kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"math/big"
mrand "math/rand"
"net"
Expand Down Expand Up @@ -1766,7 +1765,7 @@ func TestCreateRequest(t *testing.T) {
err error
url string
)
rc := ioutil.NopCloser(&buf)
rc := io.NopCloser(&buf)

client := &clusterClient{}

Expand Down Expand Up @@ -1874,7 +1873,7 @@ func TestBuildHTTPClient(t *testing.T) {
t.Errorf("should return invalid certificate")
}

err = ioutil.WriteFile("ca.empty.crt", []byte(""), 0644)
err = os.WriteFile("ca.empty.crt", []byte(""), 0644)
if err != nil {
t.Error(err)
}
Expand All @@ -1886,7 +1885,7 @@ func TestBuildHTTPClient(t *testing.T) {
}

//create CA file
err = ioutil.WriteFile("ca.temp.crt", generateSSCert(), 0644)
err = os.WriteFile("ca.temp.crt", generateSSCert(), 0644)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -3141,12 +3140,12 @@ func TestSkipperDefaultFilters(t *testing.T) {
"service1", "", "", "", "", "", "", definitions.BackendPort{Value: 8080}, 1.0,
testRule("www.example.org", testPathRule("/", "service1", definitions.BackendPort{Value: 8080})))}}

defaultFiltersDir, err := ioutil.TempDir("", "filters")
defaultFiltersDir, err := os.MkdirTemp("", "filters")
if err != nil {
t.Error(err)
}
file := filepath.Join(defaultFiltersDir, "service1.namespace1")
if err := ioutil.WriteFile(file, []byte("consecutiveBreaker(15)"), 0666); err != nil {
if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0666); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -3181,12 +3180,12 @@ func TestSkipperDefaultFilters(t *testing.T) {
testRule("www.example.org", testPathRule("/", "service1", definitions.BackendPort{Value: "port1"})))}}

// store default configuration in the file
dir, err := ioutil.TempDir("", "filters")
dir, err := os.MkdirTemp("", "filters")
if err != nil {
t.Error(err)
}
file := filepath.Join(dir, "service1.namespace1")
if err := ioutil.WriteFile(file, []byte("consecutiveBreaker(15)"), 0666); err != nil {
if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0666); err != nil {
t.Error(err)
}

Expand All @@ -3213,20 +3212,20 @@ func TestSkipperDefaultFilters(t *testing.T) {
})

t.Run("check getDefaultFilterConfigurations ignores files names not following the pattern, directories and huge files", func(t *testing.T) {
defaultFiltersDir, err := ioutil.TempDir("", "filters")
defaultFiltersDir, err := os.MkdirTemp("", "filters")
if err != nil {
t.Error(err)
}
invalidFileName := filepath.Join(defaultFiltersDir, "file.name.doesnt.match.our.pattern")
if err := ioutil.WriteFile(invalidFileName, []byte("consecutiveBreaker(15)"), 0666); err != nil {
if err := os.WriteFile(invalidFileName, []byte("consecutiveBreaker(15)"), 0666); err != nil {
t.Error(err)
}
err = os.Mkdir(filepath.Join(defaultFiltersDir, "some.directory"), os.ModePerm)
if err != nil {
t.Error(err)
}
bigFile := filepath.Join(defaultFiltersDir, "huge.file")
if err := ioutil.WriteFile(bigFile, make([]byte, 1024*1024+1), 0666); err != nil {
if err := os.WriteFile(bigFile, make([]byte, 1024*1024+1), 0666); err != nil {
t.Error(err)
}

Expand Down
3 changes: 1 addition & 2 deletions dataclients/kubernetes/kubernetestest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"regexp"

Expand Down Expand Up @@ -205,7 +204,7 @@ func itemsJSON(b *[]byte, o []interface{}) error {

func readAPIOptions(r io.Reader) (o TestAPIOptions, err error) {
var b []byte
b, err = ioutil.ReadAll(r)
b, err = io.ReadAll(r)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions dataclients/kubernetes/kubernetestest/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -126,7 +126,7 @@ func getJSON(u string, o interface{}) error {
return fmt.Errorf("unexpected status code: %d", rsp.StatusCode)
}

b, err := ioutil.ReadAll(rsp.Body)
b, err := io.ReadAll(rsp.Body)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions dataclients/kubernetes/kubernetestest/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http/httptest"
"os"
"path/filepath"
Expand Down Expand Up @@ -97,7 +96,7 @@ func rangeOverFixtures(t *testing.T, dir string, fs []os.FileInfo, test func(fix
}

func matchOutput(matchFile, output string) error {
b, err := ioutil.ReadFile(matchFile)
b, err := os.ReadFile(matchFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -197,7 +196,7 @@ func testFixture(t *testing.T, f fixtureSet) {
}

defer safeFileClose(t, ko)
b, err := ioutil.ReadAll(ko)
b, err := io.ReadAll(ko)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -240,7 +239,7 @@ func testFixture(t *testing.T, f fixtureSet) {
}

defer safeFileClose(t, eskp)
b, err := ioutil.ReadAll(eskp)
b, err := io.ReadAll(eskp)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -283,7 +282,7 @@ func testFixture(t *testing.T, f fixtureSet) {

if f.log != "" {
if err := matchOutput(f.log, logBuf.String()); err != nil {
b, err := ioutil.ReadFile(f.log)
b, err := os.ReadFile(f.log)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions dataclients/routestring/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package routestring_test

import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"time"
Expand Down Expand Up @@ -37,7 +37,7 @@ func Example() {
}

defer rsp.Body.Close()
content, err := ioutil.ReadAll(rsp.Body)
content, err := io.ReadAll(rsp.Body)
if err != nil {
log.Println(err)
return
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ index 837b6cf..aa69f09 100644
+/*
import (
"fmt"
"io/ioutil"
"os"
@@ -13,8 +14,13 @@ import (
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/routing"
Expand Down
4 changes: 2 additions & 2 deletions eskipfile/file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eskipfile

import (
"io/ioutil"
"os"

"github.com/zalando/skipper/eskip"
)
Expand All @@ -13,7 +13,7 @@ type Client struct{ routes []*eskip.Route }
// Opens an eskip file and parses it, returning a DataClient implementation. If reading or parsing the file
// fails, returns an error. This implementation doesn't provide file watch.
func Open(path string) (*Client, error) {
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions eskipfile/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package eskipfile

import (
"errors"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/routing"
"io"
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/routing"

log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -43,7 +43,7 @@ func RemoteWatch(o *RemoteWatchOptions) (routing.DataClient, error) {
return Watch(o.RemoteFile), nil
}

tempFilename, err := ioutil.TempFile("", "routes")
tempFilename, err := os.CreateTemp("", "routes")

if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 7f4a3e9

Please sign in to comment.