Skip to content

Commit 5a0fe19

Browse files
authored
Merge pull request #3304 from iwankgb/go-1.19
Updating minimum Go version to 1.19
2 parents 31361f2 + 8794bc9 commit 5a0fe19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+175
-883
lines changed

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ issues:
3333
- "(method|func) [A-Z].* should be .*"
3434
# Stuttering affects exported names:
3535
- "type name will be used as .*\\.[A-Z]{1}.* by other packages, and that stutters"
36-
# TODO: Migrate away from io/ioutil
37-
- "\"io/ioutil\" has been deprecated since Go 1.16"
3836
exclude-rules:
3937
# utils/cpuload/netlink/netlink.go:102:15: Error return value of `binary.Write` is not checked (errcheck)
4038
# There are more similar issues in this file

client/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"encoding/json"
2626
"fmt"
2727
"io"
28-
"io/ioutil"
2928
"net/http"
3029
"path"
3130
"strings"
@@ -187,7 +186,7 @@ func (c *Client) httpGetJSONData(data, postData interface{}, url, infoName strin
187186
return fmt.Errorf("received empty response for %q from %q", infoName, url)
188187
}
189188
defer resp.Body.Close()
190-
body, err := ioutil.ReadAll(resp.Body)
189+
body, err := io.ReadAll(resp.Body)
191190
if err != nil {
192191
err = fmt.Errorf("unable to read all %q from %q: %v", infoName, url, err)
193192
return err

client/v2/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"bytes"
2020
"encoding/json"
2121
"fmt"
22-
"io/ioutil"
22+
"io"
2323
"net/http"
2424
"net/url"
2525
"path"
@@ -147,7 +147,7 @@ func (c *Client) httpGetResponse(postData interface{}, urlPath, infoName string)
147147
return nil, fmt.Errorf("received empty response for %q from %q", infoName, urlPath)
148148
}
149149
defer resp.Body.Close()
150-
body, err := ioutil.ReadAll(resp.Body)
150+
body, err := io.ReadAll(resp.Body)
151151
if err != nil {
152152
err = fmt.Errorf("unable to read all %q from %q: %v", infoName, urlPath, err)
153153
return nil, err

cmd/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/google/cadvisor/cmd
22

3-
go 1.17
3+
go 1.19
44

55
// Record that the cmd module requires the cadvisor library module.
66
// The github.com/google/cadvisor/cmd module is built using the Makefile

cmd/go.sum

Lines changed: 0 additions & 705 deletions
Large diffs are not rendered by default.

cmd/internal/storage/bigquery/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"flag"
2020
"fmt"
21-
"io/ioutil"
21+
"os"
2222
"strings"
2323

2424
"golang.org/x/oauth2"
@@ -62,7 +62,7 @@ func connect() (*oauth2.Token, *bigquery.Service, error) {
6262
if *pemFile == "" {
6363
return nil, nil, fmt.Errorf("no credentials specified")
6464
}
65-
pemBytes, err := ioutil.ReadFile(*pemFile)
65+
pemBytes, err := os.ReadFile(*pemFile)
6666
if err != nil {
6767
return nil, nil, fmt.Errorf("could not access credential file %v - %v", pemFile, err)
6868
}

cmd/internal/storage/kafka/kafka.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"crypto/x509"
2020
"encoding/json"
2121
"flag"
22-
"io/ioutil"
2322
"log"
2423
"os"
2524
"strings"
@@ -110,7 +109,7 @@ func generateTLSConfig() (*tls.Config, error) {
110109
return nil, err
111110
}
112111

113-
caCert, err := ioutil.ReadFile(*caFile)
112+
caCert, err := os.ReadFile(*caFile)
114113
if err != nil {
115114
return nil, err
116115
}

collector/generic_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package collector
1717
import (
1818
"encoding/json"
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"net/http"
2222
"regexp"
2323
"strconv"
@@ -145,7 +145,7 @@ func (collector *GenericCollector) Collect(metrics map[string][]v1.MetricVal) (t
145145

146146
defer response.Body.Close()
147147

148-
pageContent, err := ioutil.ReadAll(response.Body)
148+
pageContent, err := io.ReadAll(response.Body)
149149
if err != nil {
150150
return nextCollectionTime, nil, err
151151
}

collector/generic_collector_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package collector
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
2019
"net/http"
2120
"net/http/httptest"
2221
"os"
@@ -40,9 +39,9 @@ func TestEmptyConfig(t *testing.T) {
4039
`
4140

4241
// Create a temporary config file 'temp.json' with invalid json format
43-
assert.NoError(ioutil.WriteFile("temp.json", []byte(emptyConfig), 0777))
42+
assert.NoError(os.WriteFile("temp.json", []byte(emptyConfig), 0777))
4443

45-
configFile, err := ioutil.ReadFile("temp.json")
44+
configFile, err := os.ReadFile("temp.json")
4645
assert.NoError(err)
4746

4847
containerHandler := containertest.NewMockContainerHandler("mockContainer")
@@ -72,8 +71,8 @@ func TestConfigWithErrors(t *testing.T) {
7271
`
7372

7473
// Create a temporary config file 'temp.json' with invalid json format
75-
assert.NoError(ioutil.WriteFile("temp.json", []byte(invalid), 0777))
76-
configFile, err := ioutil.ReadFile("temp.json")
74+
assert.NoError(os.WriteFile("temp.json", []byte(invalid), 0777))
75+
configFile, err := os.ReadFile("temp.json")
7776
assert.NoError(err)
7877

7978
containerHandler := containertest.NewMockContainerHandler("mockContainer")
@@ -110,9 +109,9 @@ func TestConfigWithRegexErrors(t *testing.T) {
110109
`
111110

112111
// Create a temporary config file 'temp.json'
113-
assert.NoError(ioutil.WriteFile("temp.json", []byte(invalid), 0777))
112+
assert.NoError(os.WriteFile("temp.json", []byte(invalid), 0777))
114113

115-
configFile, err := ioutil.ReadFile("temp.json")
114+
configFile, err := os.ReadFile("temp.json")
116115
assert.NoError(err)
117116

118117
containerHandler := containertest.NewMockContainerHandler("mockContainer")
@@ -126,7 +125,7 @@ func TestConfig(t *testing.T) {
126125
assert := assert.New(t)
127126

128127
// Create an nginx collector using the config file 'sample_config.json'
129-
configFile, err := ioutil.ReadFile("config/sample_config.json")
128+
configFile, err := os.ReadFile("config/sample_config.json")
130129
assert.NoError(err)
131130

132131
containerHandler := containertest.NewMockContainerHandler("mockContainer")
@@ -139,7 +138,7 @@ func TestConfig(t *testing.T) {
139138

140139
func TestEndpointConfig(t *testing.T) {
141140
assert := assert.New(t)
142-
configFile, err := ioutil.ReadFile("config/sample_config_endpoint_config.json")
141+
configFile, err := os.ReadFile("config/sample_config_endpoint_config.json")
143142
assert.NoError(err)
144143

145144
containerHandler := containertest.NewMockContainerHandler("mockContainer")
@@ -158,7 +157,7 @@ func TestMetricCollection(t *testing.T) {
158157
assert := assert.New(t)
159158

160159
// Collect nginx metrics from a fake nginx endpoint
161-
configFile, err := ioutil.ReadFile("config/sample_config.json")
160+
configFile, err := os.ReadFile("config/sample_config.json")
162161
assert.NoError(err)
163162

164163
containerHandler := containertest.NewMockContainerHandler("mockContainer")
@@ -194,7 +193,7 @@ func TestMetricCollectionLimit(t *testing.T) {
194193
assert := assert.New(t)
195194

196195
// Collect nginx metrics from a fake nginx endpoint
197-
configFile, err := ioutil.ReadFile("config/sample_config.json")
196+
configFile, err := os.ReadFile("config/sample_config.json")
198197
assert.NoError(err)
199198

200199
containerHandler := containertest.NewMockContainerHandler("mockContainer")

collector/prometheus_collector_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ package collector
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
2019
"net/http"
2120
"net/http/httptest"
21+
"os"
2222
"testing"
2323

2424
"github.com/stretchr/testify/assert"
@@ -32,7 +32,7 @@ func TestPrometheus(t *testing.T) {
3232
assert := assert.New(t)
3333

3434
// Create a prometheus collector using the config file 'sample_config_prometheus.json'
35-
configFile, err := ioutil.ReadFile("config/sample_config_prometheus.json")
35+
configFile, err := os.ReadFile("config/sample_config_prometheus.json")
3636
assert.NoError(err)
3737
containerHandler := containertest.NewMockContainerHandler("mockContainer")
3838
collector, err := NewPrometheusCollector("Prometheus", configFile, 100, containerHandler, http.DefaultClient)
@@ -116,7 +116,7 @@ func TestPrometheusEndpointConfig(t *testing.T) {
116116
assert := assert.New(t)
117117

118118
//Create a prometheus collector using the config file 'sample_config_prometheus.json'
119-
configFile, err := ioutil.ReadFile("config/sample_config_prometheus_endpoint_config.json")
119+
configFile, err := os.ReadFile("config/sample_config_prometheus_endpoint_config.json")
120120
assert.NoError(err)
121121
containerHandler := containertest.NewMockContainerHandler("mockContainer")
122122
containerHandler.On("GetContainerIPAddress").Return(
@@ -133,7 +133,7 @@ func TestPrometheusShortResponse(t *testing.T) {
133133
assert := assert.New(t)
134134

135135
// Create a prometheus collector using the config file 'sample_config_prometheus.json'
136-
configFile, err := ioutil.ReadFile("config/sample_config_prometheus.json")
136+
configFile, err := os.ReadFile("config/sample_config_prometheus.json")
137137
assert.NoError(err)
138138
containerHandler := containertest.NewMockContainerHandler("mockContainer")
139139
collector, err := NewPrometheusCollector("Prometheus", configFile, 100, containerHandler, http.DefaultClient)
@@ -157,7 +157,7 @@ func TestPrometheusMetricCountLimit(t *testing.T) {
157157
assert := assert.New(t)
158158

159159
// Create a prometheus collector using the config file 'sample_config_prometheus.json'
160-
configFile, err := ioutil.ReadFile("config/sample_config_prometheus.json")
160+
configFile, err := os.ReadFile("config/sample_config_prometheus.json")
161161
assert.NoError(err)
162162
containerHandler := containertest.NewMockContainerHandler("mockContainer")
163163
collector, err := NewPrometheusCollector("Prometheus", configFile, 10, containerHandler, http.DefaultClient)
@@ -187,7 +187,7 @@ func TestPrometheusFiltersMetrics(t *testing.T) {
187187
assert := assert.New(t)
188188

189189
// Create a prometheus collector using the config file 'sample_config_prometheus_filtered.json'
190-
configFile, err := ioutil.ReadFile("config/sample_config_prometheus_filtered.json")
190+
configFile, err := os.ReadFile("config/sample_config_prometheus_filtered.json")
191191
assert.NoError(err)
192192
containerHandler := containertest.NewMockContainerHandler("mockContainer")
193193
collector, err := NewPrometheusCollector("Prometheus", configFile, 100, containerHandler, http.DefaultClient)
@@ -227,7 +227,7 @@ func TestPrometheusFiltersMetricsCountLimit(t *testing.T) {
227227
assert := assert.New(t)
228228

229229
// Create a prometheus collector using the config file 'sample_config_prometheus_filtered.json'
230-
configFile, err := ioutil.ReadFile("config/sample_config_prometheus_filtered.json")
230+
configFile, err := os.ReadFile("config/sample_config_prometheus_filtered.json")
231231
assert.NoError(err)
232232
containerHandler := containertest.NewMockContainerHandler("mockContainer")
233233
_, err = NewPrometheusCollector("Prometheus", configFile, 1, containerHandler, http.DefaultClient)

0 commit comments

Comments
 (0)