Skip to content

Commit

Permalink
fix: remove deprecated ioutil (#528)
Browse files Browse the repository at this point in the history
Signed-off-by: fengshunli <1171313930@qq.com>
  • Loading branch information
fengshunli committed Jun 7, 2023
1 parent c0ffe84 commit b58645a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/base64"
"fmt"
"github.com/argoproj/gitops-engine/pkg/utils/text"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -78,7 +77,7 @@ func (s *settings) parseManifests() ([]*unstructured.Unstructured, string, error
if ext := strings.ToLower(filepath.Ext(info.Name())); ext != ".json" && ext != ".yml" && ext != ".yaml" {
return nil
}
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package diff
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
Expand Down Expand Up @@ -43,7 +43,7 @@ func printDiff(result *DiffResult) (string, error) {

// printDiffInternal prints a diff between two unstructured objects using an external diff utility and returns the output.
func printDiffInternal(name string, live *unstructured.Unstructured, target *unstructured.Unstructured) ([]byte, error) {
tempDir, err := ioutil.TempDir("", "argocd-diff")
tempDir, err := os.MkdirTemp("", "argocd-diff")
if err != nil {
return nil, err
}
Expand All @@ -55,7 +55,7 @@ func printDiffInternal(name string, live *unstructured.Unstructured, target *uns
return nil, err
}
}
err = ioutil.WriteFile(targetFile, targetData, 0644)
err = os.WriteFile(targetFile, targetData, 0644)
if err != nil {
return nil, err
}
Expand All @@ -67,7 +67,7 @@ func printDiffInternal(name string, live *unstructured.Unstructured, target *uns
return nil, err
}
}
err = ioutil.WriteFile(liveFile, liveData, 0644)
err = os.WriteFile(liveFile, liveData, 0644)
if err != nil {
return nil, err
}
Expand All @@ -92,7 +92,7 @@ func mustToUnstructured(obj interface{}) *unstructured.Unstructured {
}

func unmarshalFile(path string) *unstructured.Unstructured {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Package provides functionality that allows assessing the health state of a Kuber
package health

import (
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -21,7 +21,7 @@ func assertAppHealth(t *testing.T, yamlPath string, expectedStatus HealthStatusC
}

func getHealthStatus(yamlPath string, t *testing.T) *HealthStatus {
yamlBytes, err := ioutil.ReadFile(yamlPath)
yamlBytes, err := os.ReadFile(yamlPath)
require.NoError(t, err)
var obj unstructured.Unstructured
err = yaml.Unmarshal(yamlBytes, &obj)
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/kube/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kube
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -284,7 +284,7 @@ func (k *KubectlCmd) DeleteResource(ctx context.Context, config *rest.Config, gv
}

func (k *KubectlCmd) ManageResources(config *rest.Config, openAPISchema openapi.Resources) (ResourceOperations, func(), error) {
f, err := ioutil.TempFile(utils.TempDir, "")
f, err := os.CreateTemp(utils.TempDir, "")
if err != nil {
return nil, nil, fmt.Errorf("failed to generate temp file for kubeconfig: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/kube/resource_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -60,7 +60,7 @@ func (k *kubectlResourceOperations) runResourceCommand(ctx context.Context, obj
if err != nil {
return "", err
}
manifestFile, err := ioutil.TempFile(io.TempDir, "")
manifestFile, err := os.CreateTemp(io.TempDir, "")
if err != nil {
return "", fmt.Errorf("Failed to generate temp file for manifest: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/testing/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package testing

import (
"encoding/json"
"io/ioutil"
"os"
"strings"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)

func UnstructuredFromFile(path string) *unstructured.Unstructured {
file, err := ioutil.ReadFile(path)
file, err := os.ReadFile(path)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit b58645a

Please sign in to comment.