Skip to content

Commit

Permalink
fix: remove outdated ioutil package dependencies (#2583)
Browse files Browse the repository at this point in the history
Signed-off-by: fengshunli <[email protected]>
  • Loading branch information
fengshunli authored Feb 16, 2023
1 parent 9f28159 commit 5241848
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 80 deletions.
8 changes: 4 additions & 4 deletions hack/gen-crd-spec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -293,7 +293,7 @@ func loadK8SDefinitions() (spec.Definitions, error) {
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -442,7 +442,7 @@ func generateKustomizeSchema(crds []*extensionsobj.CustomResourceDefinition, out
if err != nil {
return err
}
return ioutil.WriteFile(outputPath, data, 0644)
return os.WriteFile(outputPath, data, 0644)
}

// Generate CRD spec for Rollout Resource
Expand Down Expand Up @@ -480,7 +480,7 @@ func main() {
if path == "" {
panic(fmt.Sprintf("unknown kind: %s", crdKind))
}
err = ioutil.WriteFile(path, yamlBytes, 0644)
err = os.WriteFile(path, yamlBytes, 0644)
checkErr(err)
}
}
10 changes: 5 additions & 5 deletions hack/gen-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"sort"
"strings"

"gopkg.in/yaml.v2"

"github.com/argoproj/notifications-engine/pkg/docs"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/cmd"
Expand Down Expand Up @@ -42,7 +42,7 @@ func generateNotificationsDocs() {
func generatePluginsDocs() {
tf, o := options.NewFakeArgoRolloutsOptions()

//Set static config dir so that gen docs does not change depending on what machine it is ran on
// Set static config dir so that gen docs does not change depending on what machine it is ran on
configDir := "$HOME/.kube/cache"
o.ConfigFlags.CacheDir = &configDir

Expand All @@ -65,7 +65,7 @@ func generatePluginsDocs() {
func updateMkDocsNav(parent string, child string, files []string) error {
trimPrefixes(files, "docs/")
sort.Strings(files)
data, err := ioutil.ReadFile("mkdocs.yml")
data, err := os.ReadFile("mkdocs.yml")
if err != nil {
return err
}
Expand All @@ -89,7 +89,7 @@ func updateMkDocsNav(parent string, child string, files []string) error {
if err != nil {
return err
}
return ioutil.WriteFile("mkdocs.yml", newmkdocs, 0644)
return os.WriteFile("mkdocs.yml", newmkdocs, 0644)
}

func findNavItem(nav []interface{}, key string) (interface{}, int) {
Expand Down
6 changes: 3 additions & 3 deletions metricproviders/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand All @@ -27,7 +27,7 @@ import (
var unixNow = func() int64 { return timeutil.Now().Unix() }

const (
//ProviderType indicates the provider is datadog
// ProviderType indicates the provider is datadog
ProviderType = "Datadog"
DatadogTokensSecretName = "datadog"
DatadogApiKey = "api-key"
Expand Down Expand Up @@ -131,7 +131,7 @@ func (p *Provider) Run(run *v1alpha1.AnalysisRun, metric v1alpha1.Metric) v1alph

func (p *Provider) parseResponse(metric v1alpha1.Metric, response *http.Response) (string, v1alpha1.AnalysisPhase, error) {

bodyBytes, err := ioutil.ReadAll(response.Body)
bodyBytes, err := io.ReadAll(response.Body)

if err != nil {
return "", v1alpha1.AnalysisPhaseError, fmt.Errorf("Received no bytes in response: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions metricproviders/graphite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package graphite
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"math"
"net/http"
"net/url"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (api APIClient) Query(quer string) ([]dataPoint, error) {
}
defer r.Body.Close()

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return []dataPoint{}, err
}
Expand Down
8 changes: 4 additions & 4 deletions metricproviders/influxdb/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package influxdb
import (
"errors"
"fmt"
"io/ioutil"
"io"
"strings"
"testing"

Expand Down Expand Up @@ -39,7 +39,7 @@ func TestRunSuccessfully(t *testing.T) {
,,0,2020-02-17T22:19:49.747562847Z,2020-02-18T22:19:49.747562847Z,2020-02-18T22:08:44.850214724Z,6.6,f,test,1,adsfasdf
`
reader := strings.NewReader(csvTable)
result := influxdb2.NewQueryTableResult(ioutil.NopCloser(reader))
result := influxdb2.NewQueryTableResult(io.NopCloser(reader))
mock := &mockAPI{response: result}
p := NewInfluxdbProvider(mock, e)
metric := v1alpha1.Metric{
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestRunWithTimeseries(t *testing.T) {
,,0,2020-02-17T22:19:49.747562847Z,2020-02-18T22:19:49.747562847Z,2020-02-18T22:08:44.850214724Z,20,f,test,1,adsfasdf
`
reader := strings.NewReader(csvTable)
result := influxdb2.NewQueryTableResult(ioutil.NopCloser(reader))
result := influxdb2.NewQueryTableResult(io.NopCloser(reader))
mock := &mockAPI{response: result}
p := NewInfluxdbProvider(mock, e)
metric := v1alpha1.Metric{
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestRunWithEmptyResult(t *testing.T) {
,result,table,_start,_stop,_time,_value,_field,_measurement,a,b
`
reader := strings.NewReader(csvTable)
result := influxdb2.NewQueryTableResult(ioutil.NopCloser(reader))
result := influxdb2.NewQueryTableResult(io.NopCloser(reader))
mock := &mockAPI{response: result}
p := NewInfluxdbProvider(mock, *e)
metric := v1alpha1.Metric{
Expand Down
12 changes: 6 additions & 6 deletions metricproviders/kayenta/kayenta.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand All @@ -19,7 +19,7 @@ import (
)

const (
//ProviderType indicates the provider is kayenta
// ProviderType indicates the provider is kayenta
ProviderType = "Kayenta"
scoreURLFormat = `%s/canary/%s`

Expand Down Expand Up @@ -78,7 +78,7 @@ func getCanaryConfigId(metric v1alpha1.Metric, p *Provider) (string, error) {
return "", err
}

data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func (p *Provider) Run(run *v1alpha1.AnalysisRun, metric v1alpha1.Metric) v1alph
return metricutil.MarkMeasurementError(newMeasurement, err)
}

data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil {
return metricutil.MarkMeasurementError(newMeasurement, err)
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (p *Provider) Resume(run *v1alpha1.AnalysisRun, metric v1alpha1.Metric, mea
return metricutil.MarkMeasurementError(measurement, err)
}

data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil {
return metricutil.MarkMeasurementError(measurement, err)
}
Expand All @@ -194,7 +194,7 @@ func (p *Provider) Resume(run *v1alpha1.AnalysisRun, metric v1alpha1.Metric, mea

status, ok, err := unstructured.NestedBool(patch, "complete")
if ok {
if !status { //resume later since it is incomplete
if !status { // resume later since it is incomplete
resumeTime := metav1.NewTime(timeutil.Now().Add(resumeDelay))
measurement.ResumeAt = &resumeTime
measurement.Phase = v1alpha1.AnalysisPhaseRunning
Expand Down
Loading

0 comments on commit 5241848

Please sign in to comment.