Skip to content

Commit 52f018d

Browse files
authored
Merge pull request #577 from inteon/replace_deprecated_functions
Replace deprecated ioutil package
2 parents e3caf6f + a606db0 commit 52f018d

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
lines changed

cmd/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"os"
66

77
"github.com/jetstack/preflight/pkg/agent"
88
"github.com/jetstack/preflight/pkg/logs"
@@ -35,7 +35,7 @@ var agentRBACCmd = &cobra.Command{
3535
Long: `Print RBAC string by reading GVRs`,
3636
Run: func(cmd *cobra.Command, args []string) {
3737

38-
b, err := ioutil.ReadFile(agent.Flags.ConfigFilePath)
38+
b, err := os.ReadFile(agent.Flags.ConfigFilePath)
3939
if err != nil {
4040
logs.Log.Fatalf("Failed to read config file: %s", err)
4141
}

pkg/agent/run.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111
_ "net/http/pprof"
1212
"os"
@@ -50,7 +50,7 @@ func Run(cmd *cobra.Command, args []string) {
5050
}
5151
defer file.Close()
5252

53-
b, err := ioutil.ReadAll(file)
53+
b, err := io.ReadAll(file)
5454
if err != nil {
5555
logs.Log.Fatalf("Failed to read config file: %s", err)
5656
}
@@ -194,7 +194,7 @@ func gatherAndOutputData(config Config, preflightClient client.Client, dataGathe
194194

195195
if Flags.InputPath != "" {
196196
logs.Log.Printf("Reading data from local file: %s", Flags.InputPath)
197-
data, err := ioutil.ReadFile(Flags.InputPath)
197+
data, err := os.ReadFile(Flags.InputPath)
198198
if err != nil {
199199
logs.Log.Fatalf("failed to read local data file: %s", err)
200200
}
@@ -211,7 +211,7 @@ func gatherAndOutputData(config Config, preflightClient client.Client, dataGathe
211211
if err != nil {
212212
logs.Log.Fatal("failed to marshal JSON")
213213
}
214-
err = ioutil.WriteFile(Flags.OutputPath, data, 0644)
214+
err = os.WriteFile(Flags.OutputPath, data, 0644)
215215
if err != nil {
216216
logs.Log.Fatalf("failed to output to local file: %s", err)
217217
}
@@ -320,7 +320,7 @@ func postData(config Config, preflightClient client.Client, readings []*api.Data
320320
}
321321
if code := res.StatusCode; code < 200 || code >= 300 {
322322
errorContent := ""
323-
body, _ := ioutil.ReadAll(res.Body)
323+
body, _ := io.ReadAll(res.Body)
324324
if err == nil {
325325
errorContent = string(body)
326326
}

pkg/client/client_api_token.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net/http"
109
"path/filepath"
1110
"time"
@@ -66,7 +65,7 @@ func (c *APITokenClient) PostDataReadings(orgID, clusterID string, readings []*a
6665

6766
if code := res.StatusCode; code < 200 || code >= 300 {
6867
errorContent := ""
69-
body, err := ioutil.ReadAll(res.Body)
68+
body, err := io.ReadAll(res.Body)
7069
if err == nil {
7170
errorContent = string(body)
7271
}

pkg/client/client_oauth.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net/http"
109
"net/url"
1110
"path/filepath"
@@ -120,7 +119,7 @@ func (c *OAuthClient) PostDataReadings(orgID, clusterID string, readings []*api.
120119

121120
if code := res.StatusCode; code < 200 || code >= 300 {
122121
errorContent := ""
123-
body, err := ioutil.ReadAll(res.Body)
122+
body, err := io.ReadAll(res.Body)
124123
if err == nil {
125124
errorContent = string(body)
126125
}
@@ -187,7 +186,7 @@ func (c *OAuthClient) renewAccessToken() error {
187186
return errors.WithStack(err)
188187
}
189188

190-
body, err := ioutil.ReadAll(res.Body)
189+
body, err := io.ReadAll(res.Body)
191190
if err != nil {
192191
return errors.WithStack(err)
193192
}

pkg/client/client_unauthenticated.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net/http"
109
"path/filepath"
1110
"time"
@@ -62,7 +61,7 @@ func (c *UnauthenticatedClient) PostDataReadings(orgID, clusterID string, readin
6261

6362
if code := res.StatusCode; code < 200 || code >= 300 {
6463
errorContent := ""
65-
body, err := ioutil.ReadAll(res.Body)
64+
body, err := io.ReadAll(res.Body)
6665
if err == nil {
6766
errorContent = string(body)
6867
}

pkg/datagatherer/k8s/client_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package k8s
22

33
import (
4-
"io/ioutil"
54
"os"
65
"testing"
76

@@ -55,7 +54,7 @@ func TestNewDiscoveryClient_InferredKubeconfig(t *testing.T) {
5554
}
5655

5756
func writeConfigToFile(t *testing.T, cfg clientcmdapi.Config) string {
58-
f, err := ioutil.TempFile("", "testcase-*")
57+
f, err := os.CreateTemp("", "testcase-*")
5958
if err != nil {
6059
t.Fatal(err)
6160
}

pkg/datagatherer/local/local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package local
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"os"
77

88
"github.com/jetstack/preflight/pkg/datagatherer"
99
)
@@ -55,7 +55,7 @@ func (g *DataGatherer) WaitForCacheSync(stopCh <-chan struct{}) error {
5555

5656
// Fetch loads and returns the data from the LocalDatagatherer's dataPath
5757
func (g *DataGatherer) Fetch() (interface{}, int, error) {
58-
dataBytes, err := ioutil.ReadFile(g.dataPath)
58+
dataBytes, err := os.ReadFile(g.dataPath)
5959
if err != nil {
6060
return nil, -1, err
6161
}

0 commit comments

Comments
 (0)