mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
use os.ReadFile to replace ioutil.ReadFile
This commit is contained in:
parent
caeaff8a88
commit
0ce4c28a0f
|
|
@ -19,7 +19,6 @@ package plugin
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
|
@ -79,7 +78,7 @@ func (o *PluginListOptions) Run() error {
|
|||
continue
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
if _, ok := err.(*os.PathError); ok {
|
||||
fmt.Fprintf(o.ErrOut, "Unable to read directory %q from your PATH: %v. Skipping...\n", dir, err)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
|
@ -171,7 +170,7 @@ func CreateManifest(arg common.Argument, name string) error {
|
|||
|
||||
manifestStr, err := templates.RenderManifest(options)
|
||||
|
||||
if err := ioutil.WriteFile(arg.FilePath, []byte(manifestStr), 0644); err != nil {
|
||||
if err := os.WriteFile(arg.FilePath, []byte(manifestStr), 0644); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("write file %s failed", arg.FilePath))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package artifact
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
|
@ -141,7 +140,7 @@ func (m *Md5Check) Execute(runtime connector.Runtime) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
oldMd5, err := ioutil.ReadFile(oldFile)
|
||||
oldMd5, err := os.ReadFile(oldFile)
|
||||
if err != nil {
|
||||
return errors.Wrapf(errors.WithStack(err), "read old md5 file %s failed", oldFile)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package customscripts
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -79,7 +78,7 @@ func (t *CustomScriptTask) Execute(runtime connector.Runtime) error {
|
|||
// wrap use bash file if shell has many lines.
|
||||
RunBash := t.script.Bash
|
||||
if strings.Index(RunBash, "\n") > 0 {
|
||||
tmpFile, err := ioutil.TempFile(os.TempDir(), t.taskDir)
|
||||
tmpFile, err := os.CreateTemp(os.TempDir(), t.taskDir)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "create tmp Bash: %s/%s in local node, err:%s", os.TempDir(), t.taskDir, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@
|
|||
package kubernetes
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"os"
|
||||
)
|
||||
|
||||
func NewClient(kubeConfig string) (*kubernetes.Clientset, error) {
|
||||
data, err := ioutil.ReadFile(kubeConfig)
|
||||
data, err := os.ReadFile(kubeConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ package common
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
|
@ -54,7 +54,7 @@ func NewArtifactRuntime(arg ArtifactArgument) (*ArtifactRuntime, error) {
|
|||
return nil, errors.Wrap(err, "Failed to look up current directory")
|
||||
}
|
||||
|
||||
fileByte, err := ioutil.ReadFile(fp)
|
||||
fileByte, err := os.ReadFile(fp)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Failed to read file %s", fp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import (
|
|||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
|
|
@ -187,7 +186,7 @@ func validateOptions(cfg Cfg) (Cfg, error) {
|
|||
}
|
||||
|
||||
if len(cfg.PrivateKey) == 0 && len(cfg.KeyFile) > 0 {
|
||||
content, err := ioutil.ReadFile(cfg.KeyFile)
|
||||
content, err := os.ReadFile(cfg.KeyFile)
|
||||
if err != nil {
|
||||
return cfg, errors.Wrapf(err, "Failed to read keyfile %q", cfg.KeyFile)
|
||||
}
|
||||
|
|
@ -462,7 +461,7 @@ func (c *connection) Scp(src, dst string, host Host) error {
|
|||
}
|
||||
|
||||
func (c *connection) copyDirToRemote(src, dst string, scrErr *scpErr, host Host) {
|
||||
localFiles, err := ioutil.ReadDir(src)
|
||||
localFiles, err := os.ReadDir(src)
|
||||
if err != nil {
|
||||
logger.Log.Errorf("read local path dir %s failed %v", src, err)
|
||||
scrErr.err = err
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -131,7 +130,7 @@ func WriteFile(fileName string, content []byte) error {
|
|||
}
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(fileName, content, common.FileMode0644); err != nil {
|
||||
if err := os.WriteFile(fileName, content, common.FileMode0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package etcd
|
|||
import (
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -245,12 +244,12 @@ func (f *FetchCertsForExternalEtcd) Execute(runtime connector.Runtime) error {
|
|||
dstCert := fmt.Sprintf("%s/%s", pkiPath, dstCertFileName)
|
||||
dstCertsFiles = append(dstCertsFiles, dstCertFileName)
|
||||
|
||||
data, err := ioutil.ReadFile(certPath)
|
||||
data, err := os.ReadFile(certPath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to copy certificate content")
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(dstCert, data, 0600); err != nil {
|
||||
if err := os.WriteFile(dstCert, data, 0600); err != nil {
|
||||
return errors.Wrap(err, "failed to copy certificate content")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
|
@ -313,7 +312,7 @@ func sha256sum(path string) (string, error) {
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(file)
|
||||
data, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package images
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
|
@ -227,7 +227,7 @@ func (c *CopyImagesToRegistry) Execute(runtime connector.Runtime) error {
|
|||
imagesPath = filepath.Join(runtime.GetWorkDir(), "images")
|
||||
}
|
||||
|
||||
indexFile, err := ioutil.ReadFile(filepath.Join(imagesPath, "index.json"))
|
||||
indexFile, err := os.ReadFile(filepath.Join(imagesPath, "index.json"))
|
||||
if err != nil {
|
||||
return errors.Errorf("read index.json failed: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ package k3s
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
|
@ -117,7 +117,7 @@ func (k *K3sStatus) LoadKubeConfig(runtime connector.Runtime, kubeConf *common.K
|
|||
newServer := fmt.Sprintf("server: https://%s:%d", kubeConf.Cluster.ControlPlaneEndpoint.Address, kubeConf.Cluster.ControlPlaneEndpoint.Port)
|
||||
newKubeConfigStr := strings.Replace(k.KubeConfig, oldServer, newServer, -1)
|
||||
|
||||
if err := ioutil.WriteFile(kubeConfigPath, []byte(newKubeConfigStr), 0644); err != nil {
|
||||
if err := os.WriteFile(kubeConfigPath, []byte(newKubeConfigStr), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ package k8e
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
|
@ -117,7 +117,7 @@ func (k *K8eStatus) LoadKubeConfig(runtime connector.Runtime, kubeConf *common.K
|
|||
newServer := fmt.Sprintf("server: https://%s:%d", kubeConf.Cluster.ControlPlaneEndpoint.Address, kubeConf.Cluster.ControlPlaneEndpoint.Port)
|
||||
newKubeConfigStr := strings.Replace(k.KubeConfig, oldServer, newServer, -1)
|
||||
|
||||
if err := ioutil.WriteFile(kubeConfigPath, []byte(newKubeConfigStr), 0644); err != nil {
|
||||
if err := os.WriteFile(kubeConfigPath, []byte(newKubeConfigStr), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ package kubernetes
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
|
@ -145,7 +145,7 @@ func (k *KubernetesStatus) LoadKubeConfig(runtime connector.Runtime, kubeConf *c
|
|||
newServer := fmt.Sprintf("server: https://%s:%d", kubeConf.Cluster.ControlPlaneEndpoint.Address, kubeConf.Cluster.ControlPlaneEndpoint.Port)
|
||||
newKubeConfigStr := strings.Replace(kubeConfigStr, oldServer, newServer, -1)
|
||||
|
||||
if err := ioutil.WriteFile(kubeConfigPath, []byte(newKubeConfigStr), 0644); err != nil {
|
||||
if err := os.WriteFile(kubeConfigPath, []byte(newKubeConfigStr), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue