delete io/ioutil package. (#5955)

Signed-off-by: yanggang <gang.yang@daocloud.io>
This commit is contained in:
杨刚 (成都)
2023-03-16 09:25:58 +08:00
committed by GitHub
parent 1d8ca4f2ef
commit ad9c6e8dee
31 changed files with 92 additions and 83 deletions

View File

@@ -18,7 +18,7 @@ package k8s
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"time"
@@ -43,7 +43,7 @@ func CreateSecretFromFiles(ctx context.Context, client TestClient, namespace str
data := make(map[string][]byte)
for key, filePath := range files {
contents, err := ioutil.ReadFile(filePath)
contents, err := os.ReadFile(filePath)
if err != nil {
return errors.WithMessagef(err, "Failed to read secret file %q", filePath)
}

View File

@@ -19,7 +19,7 @@ package k8s
import (
"context"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/pkg/errors"
@@ -47,7 +47,7 @@ func WaitUntilServiceAccountCreated(ctx context.Context, client TestClient, name
}
func PatchServiceAccountWithImagePullSecret(ctx context.Context, client TestClient, namespace, serviceAccount, dockerCredentialFile string) error {
credential, err := ioutil.ReadFile(dockerCredentialFile)
credential, err := os.ReadFile(dockerCredentialFile)
if err != nil {
return errors.Wrapf(err, "failed to read the docker credential file %q", dockerCredentialFile)
}

View File

@@ -19,7 +19,7 @@ package providers
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"cloud.google.com/go/storage"
@@ -103,7 +103,7 @@ func (s GCSStorage) DeleteObjectsInBucket(cloudCredentialsFile, bslBucket, bslPr
func (s GCSStorage) IsSnapshotExisted(cloudCredentialsFile, bslConfig, backupObject string, snapshotCheck SnapshotCheckPoint) error {
ctx := context.Background()
data, err := ioutil.ReadFile(cloudCredentialsFile)
data, err := os.ReadFile(cloudCredentialsFile)
if err != nil {
return errors.Wrapf(err, fmt.Sprintf("Failed reading gcloud credential file %s", cloudCredentialsFile))
}

View File

@@ -21,7 +21,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
@@ -109,7 +108,7 @@ func VeleroInstall(ctx context.Context, veleroCfg *VeleroConfig) error {
return nil
}
//configvSpherePlugin refers to https://github.com/vmware-tanzu/velero-plugin-for-vsphere/blob/v1.3.0/docs/vanilla.md
// configvSpherePlugin refers to https://github.com/vmware-tanzu/velero-plugin-for-vsphere/blob/v1.3.0/docs/vanilla.md
func configvSpherePlugin(cli TestClient) error {
var err error
vsphereSecret := "velero-vsphere-config-secret"
@@ -311,11 +310,10 @@ func patchResources(ctx context.Context, resources *unstructured.UnstructuredLis
// apply the image pull secret to avoid the image pull limit of Docker Hub
if len(options.RegistryCredentialFile) > 0 && resource.GetKind() == "ServiceAccount" &&
resource.GetName() == "velero" {
credential, err := ioutil.ReadFile(options.RegistryCredentialFile)
credential, err := os.ReadFile(options.RegistryCredentialFile)
if err != nil {
return errors.Wrapf(err, "failed to read the registry credential file %s", options.RegistryCredentialFile)
}
imagePullSecret = corev1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",

View File

@@ -23,7 +23,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
@@ -772,7 +771,7 @@ func InstallVeleroCLI(version string) (string, error) {
if err != nil {
return false, errors.WithMessagef(err, "failed to get Velero CLI tarball")
}
tempVeleroCliDir, err = ioutil.TempDir("", "velero-test")
tempVeleroCliDir, err = os.MkdirTemp("", "velero-test")
if err != nil {
return false, errors.WithMessagef(err, "failed to create temp dir for tarball extraction")
}
@@ -801,11 +800,11 @@ func getVeleroCliTarball(cliTarballUrl string) (*os.File, error) {
}
defer resp.Body.Close()
tarballBuf, err := ioutil.ReadAll(resp.Body)
tarballBuf, err := io.ReadAll(resp.Body)
if err != nil {
return nil, errors.WithMessagef(err, "failed to read buffer for tarball %s.", tarball)
}
tmpfile, err := ioutil.TempFile("", tarball)
tmpfile, err := os.CreateTemp("", tarball)
if err != nil {
return nil, errors.WithMessagef(err, "failed to create temp file for tarball %s locally.", tarball)
}