Skip to content

Commit b58645a

Browse files
authored
fix: remove deprecated ioutil (#528)
Signed-off-by: fengshunli <[email protected]>
1 parent c0ffe84 commit b58645a

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

agent/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/base64"
77
"fmt"
88
"github.com/argoproj/gitops-engine/pkg/utils/text"
9-
"io/ioutil"
109
"net/http"
1110
"os"
1211
"os/exec"
@@ -78,7 +77,7 @@ func (s *settings) parseManifests() ([]*unstructured.Unstructured, string, error
7877
if ext := strings.ToLower(filepath.Ext(info.Name())); ext != ".json" && ext != ".yml" && ext != ".yaml" {
7978
return nil
8079
}
81-
data, err := ioutil.ReadFile(path)
80+
data, err := os.ReadFile(path)
8281
if err != nil {
8382
return err
8483
}

pkg/diff/diff_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package diff
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"os"
77
"os/exec"
88
"path/filepath"
99
"strings"
@@ -43,7 +43,7 @@ func printDiff(result *DiffResult) (string, error) {
4343

4444
// printDiffInternal prints a diff between two unstructured objects using an external diff utility and returns the output.
4545
func printDiffInternal(name string, live *unstructured.Unstructured, target *unstructured.Unstructured) ([]byte, error) {
46-
tempDir, err := ioutil.TempDir("", "argocd-diff")
46+
tempDir, err := os.MkdirTemp("", "argocd-diff")
4747
if err != nil {
4848
return nil, err
4949
}
@@ -55,7 +55,7 @@ func printDiffInternal(name string, live *unstructured.Unstructured, target *uns
5555
return nil, err
5656
}
5757
}
58-
err = ioutil.WriteFile(targetFile, targetData, 0644)
58+
err = os.WriteFile(targetFile, targetData, 0644)
5959
if err != nil {
6060
return nil, err
6161
}
@@ -67,7 +67,7 @@ func printDiffInternal(name string, live *unstructured.Unstructured, target *uns
6767
return nil, err
6868
}
6969
}
70-
err = ioutil.WriteFile(liveFile, liveData, 0644)
70+
err = os.WriteFile(liveFile, liveData, 0644)
7171
if err != nil {
7272
return nil, err
7373
}
@@ -92,7 +92,7 @@ func mustToUnstructured(obj interface{}) *unstructured.Unstructured {
9292
}
9393

9494
func unmarshalFile(path string) *unstructured.Unstructured {
95-
data, err := ioutil.ReadFile(path)
95+
data, err := os.ReadFile(path)
9696
if err != nil {
9797
panic(err)
9898
}

pkg/health/health_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Package provides functionality that allows assessing the health state of a Kuber
55
package health
66

77
import (
8-
"io/ioutil"
8+
"os"
99
"testing"
1010

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

2323
func getHealthStatus(yamlPath string, t *testing.T) *HealthStatus {
24-
yamlBytes, err := ioutil.ReadFile(yamlPath)
24+
yamlBytes, err := os.ReadFile(yamlPath)
2525
require.NoError(t, err)
2626
var obj unstructured.Unstructured
2727
err = yaml.Unmarshal(yamlBytes, &obj)

pkg/utils/kube/ctl.go

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

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

286286
func (k *KubectlCmd) ManageResources(config *rest.Config, openAPISchema openapi.Resources) (ResourceOperations, func(), error) {
287-
f, err := ioutil.TempFile(utils.TempDir, "")
287+
f, err := os.CreateTemp(utils.TempDir, "")
288288
if err != nil {
289289
return nil, nil, fmt.Errorf("failed to generate temp file for kubeconfig: %v", err)
290290
}

pkg/utils/kube/resource_ops.go

Lines changed: 2 additions & 2 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+
"os"
1010
"strings"
1111

1212
"github.com/go-logr/logr"
@@ -60,7 +60,7 @@ func (k *kubectlResourceOperations) runResourceCommand(ctx context.Context, obj
6060
if err != nil {
6161
return "", err
6262
}
63-
manifestFile, err := ioutil.TempFile(io.TempDir, "")
63+
manifestFile, err := os.CreateTemp(io.TempDir, "")
6464
if err != nil {
6565
return "", fmt.Errorf("Failed to generate temp file for manifest: %v", err)
6666
}

pkg/utils/testing/unstructured.go

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

33
import (
44
"encoding/json"
5-
"io/ioutil"
5+
"os"
66
"strings"
77

88
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
99
"sigs.k8s.io/yaml"
1010
)
1111

1212
func UnstructuredFromFile(path string) *unstructured.Unstructured {
13-
file, err := ioutil.ReadFile(path)
13+
file, err := os.ReadFile(path)
1414
if err != nil {
1515
panic(err)
1616
}

0 commit comments

Comments
 (0)