diff --git a/benchmark/pkg/metricsfetcher/scraper/scraper_test.go b/benchmark/pkg/metricsfetcher/scraper/scraper_test.go index cfb9c9a6df..537ae12ac3 100644 --- a/benchmark/pkg/metricsfetcher/scraper/scraper_test.go +++ b/benchmark/pkg/metricsfetcher/scraper/scraper_test.go @@ -17,7 +17,6 @@ limitations under the License. package scraper import ( - "io/ioutil" "os" "reflect" "testing" @@ -76,7 +75,7 @@ func TestGetMetricsForRun(t *testing.T) { var latencyFilesContents [][]byte latencyFiles := []string{"APIResponsiveness_testA_xyz123.txt", "APIResponsiveness_testB_xy123c.txt", "PodStartupLatency_testA_xyz123.txt"} for _, latencyFile := range latencyFiles { - fileContents, err := ioutil.ReadFile(wd + "/test-data/" + latencyFile) + fileContents, err := os.ReadFile(wd + "/test-data/" + latencyFile) if err != nil { panic(err) } diff --git a/benchmark/pkg/metricsfetcher/util/util.go b/benchmark/pkg/metricsfetcher/util/util.go index 63de9e2d3e..e21bdf7fcc 100644 --- a/benchmark/pkg/metricsfetcher/util/util.go +++ b/benchmark/pkg/metricsfetcher/util/util.go @@ -18,7 +18,7 @@ package util import ( "fmt" - "io/ioutil" + "io" "k8s.io/contrib/test-utils/utils" ) @@ -84,7 +84,7 @@ func (utils GCSLogUtils) GetJobRunFileContents(job string, run int, filepath str return nil, fmt.Errorf("couldn't read file from GCS: %v", err) } defer response.Body.Close() - return ioutil.ReadAll(response.Body) + return io.ReadAll(response.Body) } // ListJobRunFilesWithPrefix returns the list of files with a given path prefix in the job run's root dir. diff --git a/clusterloader2/cmd/clusterloader.go b/clusterloader2/cmd/clusterloader.go index 95d0d1da16..4ed2bc6d2e 100644 --- a/clusterloader2/cmd/clusterloader.go +++ b/clusterloader2/cmd/clusterloader.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "net/http" _ "net/http/pprof" "os" @@ -26,6 +25,7 @@ import ( "time" "gopkg.in/yaml.v2" + corev1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes" "k8s.io/klog/v2" @@ -448,7 +448,7 @@ func dumpTestConfig(ctx test.Context, config *api.Config) error { return fmt.Errorf("marshaling config error: %w", err) } filePath := path.Join(ctx.GetClusterLoaderConfig().ReportDir, "generatedConfig_"+config.Name+".yaml") - if err := ioutil.WriteFile(filePath, b, 0644); err != nil { + if err := os.WriteFile(filePath, b, 0644); err != nil { return fmt.Errorf("saving file error: %w", err) } klog.Infof("Test config successfully dumped to: %s", filePath) diff --git a/clusterloader2/pkg/config/template_functions.go b/clusterloader2/pkg/config/template_functions.go index 4dc9daf75d..5d57212970 100644 --- a/clusterloader2/pkg/config/template_functions.go +++ b/clusterloader2/pkg/config/template_functions.go @@ -19,7 +19,6 @@ package config import ( "fmt" "io/fs" - "io/ioutil" "math" "math/rand" "os" @@ -236,7 +235,7 @@ func includeFile(file interface{}) (string, error) { } } fileStr = os.ExpandEnv(fileStr) - data, err := ioutil.ReadFile(fileStr) + data, err := os.ReadFile(fileStr) if err != nil { return "", fmt.Errorf("unable to read file: %v", err) } diff --git a/clusterloader2/pkg/config/template_provider.go b/clusterloader2/pkg/config/template_provider.go index ba61147dcd..354ec9b89f 100644 --- a/clusterloader2/pkg/config/template_provider.go +++ b/clusterloader2/pkg/config/template_provider.go @@ -21,7 +21,6 @@ import ( "bytes" "fmt" "io/fs" - "io/ioutil" "os" "reflect" "regexp" @@ -32,6 +31,7 @@ import ( template "github.com/google/safetext/yamltemplate" goerrors "github.com/go-errors/errors" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/perf-tests/clusterloader2/api" "k8s.io/perf-tests/clusterloader2/pkg/errors" @@ -169,7 +169,7 @@ func (tp *TemplateProvider) TemplateInto(path string, mapping map[string]interfa // LoadTestSuite creates test suite config from file specified by the given path. func LoadTestSuite(path string) (api.TestSuite, error) { - bin, err := ioutil.ReadFile(path) + bin, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("test suite reading error: %v", err) } @@ -196,7 +196,7 @@ func validateTestSuite(suite api.TestSuite) error { } func updateMappingFromFile(mapping map[string]interface{}, path string) error { - bin, err := ioutil.ReadFile(path) + bin, err := os.ReadFile(path) if err != nil { return fmt.Errorf("test overrides reading error: %v", err) } diff --git a/clusterloader2/pkg/measurement/common/executors/promql_executor.go b/clusterloader2/pkg/measurement/common/executors/promql_executor.go index e56a4648c4..a97b245d32 100644 --- a/clusterloader2/pkg/measurement/common/executors/promql_executor.go +++ b/clusterloader2/pkg/measurement/common/executors/promql_executor.go @@ -19,7 +19,6 @@ package executors import ( "context" "fmt" - "io/ioutil" "os" "time" @@ -65,7 +64,7 @@ func (t *testSeries) seriesLoadingString() string { } func loadFromFile(filename string) (*testSeries, error) { - b, err := ioutil.ReadFile(filename) + b, err := os.ReadFile(filename) if err != nil { return nil, err } @@ -88,7 +87,7 @@ type PromqlExecutor struct { // NewPromqlExecutor creates a new executor with time series and rules loaded from file // Samples loaded from test file starts at time.Time.UTC(0,0) func NewPromqlExecutor(timeSeriesFile string) (*PromqlExecutor, error) { - //Load time series from file + // Load time series from file f, err := loadFromFile(timeSeriesFile) if err != nil { return nil, fmt.Errorf("could not parse time series file: %v", err) @@ -104,7 +103,7 @@ func NewPromqlExecutor(timeSeriesFile string) (*PromqlExecutor, error) { return nil, fmt.Errorf("could not initialize lazy loader: %v", err) } - //Load rule groups + // Load rule groups opts := &rules.ManagerOptions{ QueryFunc: rules.EngineQueryFunc(ll.QueryEngine(), ll.Storage()), Appendable: ll.Storage(), @@ -124,7 +123,7 @@ func NewPromqlExecutor(timeSeriesFile string) (*PromqlExecutor, error) { return nil, fmt.Errorf("could not load rules file: %v", ers) } - //Load data into ll + // Load data into ll ll.WithSamplesTill(time.Now(), func(e error) { if err != nil { err = e diff --git a/clusterloader2/pkg/measurement/common/executors/utils.go b/clusterloader2/pkg/measurement/common/executors/utils.go index edd20b8c68..9d1ab393fb 100644 --- a/clusterloader2/pkg/measurement/common/executors/utils.go +++ b/clusterloader2/pkg/measurement/common/executors/utils.go @@ -17,7 +17,6 @@ limitations under the License. package executors import ( - "io/ioutil" "os" "gopkg.in/yaml.v2" @@ -45,7 +44,7 @@ type prometheusRuleManifest struct { } func createRulesFile(rulesManifestFile string) (*os.File, error) { - r, err := ioutil.ReadFile(rulesManifestFile) + r, err := os.ReadFile(rulesManifestFile) if err != nil { return nil, err } @@ -56,7 +55,7 @@ func createRulesFile(rulesManifestFile string) (*os.File, error) { return nil, err } - tempFile, err := ioutil.TempFile("", "") + tempFile, err := os.CreateTemp("", "") if err != nil { return nil, err } diff --git a/clusterloader2/pkg/measurement/common/metrics/kubelet_metrics.go b/clusterloader2/pkg/measurement/common/metrics/kubelet_metrics.go index e873b8025a..2cbfc95e2c 100644 --- a/clusterloader2/pkg/measurement/common/metrics/kubelet_metrics.go +++ b/clusterloader2/pkg/measurement/common/metrics/kubelet_metrics.go @@ -19,7 +19,7 @@ package metrics import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "sort" "strconv" @@ -57,7 +57,7 @@ func GrabKubeletMetricsWithoutProxy(nodeName, path string) (KubeletMetrics, erro return KubeletMetrics{}, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return KubeletMetrics{}, err } diff --git a/clusterloader2/pkg/metadata/metadata.go b/clusterloader2/pkg/metadata/metadata.go index 3d98b8aaff..d173aa1ee3 100644 --- a/clusterloader2/pkg/metadata/metadata.go +++ b/clusterloader2/pkg/metadata/metadata.go @@ -18,7 +18,7 @@ package metadata import ( "encoding/json" - "io/ioutil" + "os" "k8s.io/perf-tests/clusterloader2/pkg/framework" ) @@ -49,5 +49,5 @@ func write(obj map[string]string, outputFile string) error { if err != nil { return err } - return ioutil.WriteFile(outputFile, out, 0644) + return os.WriteFile(outputFile, out, 0644) } diff --git a/clusterloader2/pkg/prometheus/clients/gcp_managed.go b/clusterloader2/pkg/prometheus/clients/gcp_managed.go index ede3bdc275..f6f002b104 100644 --- a/clusterloader2/pkg/prometheus/clients/gcp_managed.go +++ b/clusterloader2/pkg/prometheus/clients/gcp_managed.go @@ -19,7 +19,7 @@ package prom import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -45,7 +45,7 @@ func (mpc *gcpManagedPrometheusClient) Query(query string, queryTime time.Time) return nil, err } defer res.Body.Close() - resBody, err := ioutil.ReadAll(res.Body) + resBody, err := io.ReadAll(res.Body) if statusCode := res.StatusCode; statusCode > 299 { return resBody, fmt.Errorf("response failed with status code %d", statusCode) } diff --git a/clusterloader2/pkg/test/simple_test_executor.go b/clusterloader2/pkg/test/simple_test_executor.go index c11005c78c..27047dbcf1 100644 --- a/clusterloader2/pkg/test/simple_test_executor.go +++ b/clusterloader2/pkg/test/simple_test_executor.go @@ -18,7 +18,7 @@ package test import ( "fmt" - "io/ioutil" + "os" "path" "strings" "time" @@ -103,7 +103,7 @@ func (ste *simpleExecutor) ExecuteTest(ctx Context, conf *api.Config) *errors.Er // TODO(krzysied): Remember to keep original filename style for backward compatibility. fileName := strings.Join([]string{summary.SummaryName(), conf.Name + testDistinctor, summary.SummaryTime().Format(time.RFC3339)}, "_") filePath := path.Join(ctx.GetClusterLoaderConfig().ReportDir, strings.Join([]string{fileName, summary.SummaryExt()}, ".")) - if err := ioutil.WriteFile(filePath, []byte(summary.SummaryContent()), 0644); err != nil { + if err := os.WriteFile(filePath, []byte(summary.SummaryContent()), 0644); err != nil { errList.Append(fmt.Errorf("writing to file %v error: %v", filePath, err)) continue } diff --git a/dns/jsonify/main.go b/dns/jsonify/main.go index 7ce9e13abd..d44ecae5dc 100644 --- a/dns/jsonify/main.go +++ b/dns/jsonify/main.go @@ -21,7 +21,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "os" "path/filepath" "time" @@ -134,7 +133,7 @@ func run() error { // getFileList returns a list of all files with extension .out. func getFileList(dir string) ([]string, error) { var fileNames []string - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return fileNames, err } @@ -149,7 +148,7 @@ func getFileList(dir string) ([]string, error) { func readBenchmarkResult(path string) (*BenchmarkResult, error) { var result BenchmarkResult - bin, err := ioutil.ReadFile(path) + bin, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("reading error: %v", err) } @@ -234,5 +233,5 @@ func saveMetric(metric *perftype.PerfData, path string) error { if err := json.Indent(formatted, output.Bytes(), "", " "); err != nil { return err } - return ioutil.WriteFile(path, formatted.Bytes(), 0664) + return os.WriteFile(path, formatted.Bytes(), 0664) } diff --git a/perfdash/config.go b/perfdash/config.go index c60d5e0654..6674c808ed 100644 --- a/perfdash/config.go +++ b/perfdash/config.go @@ -18,8 +18,9 @@ package main import ( "fmt" - "io/ioutil" + "io" "net/http" + "os" "strconv" "strings" @@ -722,7 +723,7 @@ func urlConfigRead(url string) ([]byte, error) { return nil, fmt.Errorf("error fetching prow config from %s: %v", url, err) } defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("error reading prow config from %s: %v", url, err) } @@ -730,7 +731,7 @@ func urlConfigRead(url string) ([]byte, error) { } func fileConfigRead(path string) ([]byte, error) { - return ioutil.ReadFile(path) + return os.ReadFile(path) } func getProwConfig(configPaths []string) (Jobs, error) { diff --git a/perfdash/gcs_metrics_bucket.go b/perfdash/gcs_metrics_bucket.go index f286c289a8..1b16b4f7a8 100644 --- a/perfdash/gcs_metrics_bucket.go +++ b/perfdash/gcs_metrics_bucket.go @@ -19,13 +19,14 @@ package main import ( "context" "fmt" - "io/ioutil" + "io" "strconv" "strings" "cloud.google.com/go/storage" "google.golang.org/api/iterator" "google.golang.org/api/option" + "k8s.io/klog" ) @@ -137,7 +138,7 @@ func (b *GCSMetricsBucket) ReadFile(job string, buildNumber int, path string) ([ } defer rc.Close() - data, err := ioutil.ReadAll(rc) + data, err := io.ReadAll(rc) if err != nil { return nil, err } diff --git a/perfdash/github-configs-fetcher.go b/perfdash/github-configs-fetcher.go index 477ad5a477..6324734a5d 100644 --- a/perfdash/github-configs-fetcher.go +++ b/perfdash/github-configs-fetcher.go @@ -18,12 +18,13 @@ package main import ( "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" "gopkg.in/yaml.v2" + "k8s.io/klog" ) @@ -72,7 +73,7 @@ func getGithubDirContents(url string) ([]githubDirContent, error) { if err != nil { return nil, fmt.Errorf("error calling github API %s: %v", url, err) } - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("error reading github response %s: %v", url, err) } diff --git a/perfdash/s3_metrics_bucket.go b/perfdash/s3_metrics_bucket.go index 3bb3a46bfc..ca2be8d07a 100644 --- a/perfdash/s3_metrics_bucket.go +++ b/perfdash/s3_metrics_bucket.go @@ -19,7 +19,7 @@ package main import ( "context" "fmt" - "io/ioutil" + "io" "strconv" "strings" @@ -117,5 +117,5 @@ func (s *S3MetricsBucket) ReadFile(job string, buildNumber int, path string) ([] } defer resp.Body.Close() - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) } diff --git a/util-images/access-tokens/cmd/main.go b/util-images/access-tokens/cmd/main.go index 42d7856f85..05538f831d 100644 --- a/util-images/access-tokens/cmd/main.go +++ b/util-images/access-tokens/cmd/main.go @@ -20,8 +20,6 @@ import ( "context" goflag "flag" flag "github.com/spf13/pflag" - "io/ioutil" - "k8s.io/client-go/rest" "net" "os" "path/filepath" @@ -29,8 +27,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" certutil "k8s.io/client-go/util/cert" - flowcontrol "k8s.io/client-go/util/flowcontrol" + "k8s.io/client-go/util/flowcontrol" "k8s.io/klog/v2" ) @@ -98,7 +97,7 @@ func newConfig(tokenFile, rootCAFile string) (*rest.Config, error) { if len(host) == 0 || len(port) == 0 { return nil, rest.ErrNotInCluster } - token, err := ioutil.ReadFile(tokenFile) + token, err := os.ReadFile(tokenFile) if err != nil { return nil, err }