Skip to content

Commit

Permalink
Deprecate io/utils, To #46562644 (#2496)
Browse files Browse the repository at this point in the history
Signed-off-by: cheyang <[email protected]>

Signed-off-by: cheyang <[email protected]>
  • Loading branch information
cheyang authored Jan 8, 2023
1 parent b3683c6 commit 2967f96
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 80 deletions.
5 changes: 2 additions & 3 deletions pkg/controllers/v1alpha1/databackup/implement.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"reflect"
"strconv"
Expand Down Expand Up @@ -491,11 +490,11 @@ func (r *DataBackupReconcilerImplement) generateDataBackupValueFile(ctx reconcil
return
}

valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-%s-backuper-values.yaml", databackup.Namespace, databackup.Name, dataBackup.RuntimeType))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-%s-backuper-values.yaml", databackup.Namespace, databackup.Name, dataBackup.RuntimeType))
if err != nil {
return
}
err = ioutil.WriteFile(valueFile.Name(), data, 0400)
err = os.WriteFile(valueFile.Name(), data, 0400)
if err != nil {
return
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/csi/recover/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ package recover
import (
"context"
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/fluid-cloudnative/fluid/pkg/common"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/dataset/volume"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubelet"
"github.com/fluid-cloudnative/fluid/pkg/utils/mountinfo"
"github.com/golang/glog"
"github.com/pkg/errors"
"io/ioutil"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
Expand All @@ -35,12 +39,8 @@ import (
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
k8sexec "k8s.io/utils/exec"
"k8s.io/utils/mount"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"strconv"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -74,7 +74,7 @@ type containerStat struct {

func initializeKubeletClient() (*kubelet.KubeletClient, error) {
// get CSI sa token
tokenByte, err := ioutil.ReadFile(serviceAccountTokenFile)
tokenByte, err := os.ReadFile(serviceAccountTokenFile)
if err != nil {
return nil, errors.Wrap(err, "in cluster mode, find token failed")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/csi/recover/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package recover

import (
"errors"
"io/ioutil"
"os"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -77,7 +77,7 @@ func Test_initializeKubeletClient(t *testing.T) {
fakeClientKey = ""
fakeKubeletTimeout = "120"
)
patch1 := ApplyFunc(ioutil.ReadFile, func(filename string) ([]byte, error) {
patch1 := ApplyFunc(os.ReadFile, func(filename string) ([]byte, error) {
return []byte(fakeToken), nil
})
defer patch1.Reset()
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/alluxio/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package alluxio

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -128,11 +127,11 @@ func (e *AlluxioEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestCon
return
}

valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
if err != nil {
return
}
err = ioutil.WriteFile(valueFile.Name(), data, 0400)
err = os.WriteFile(valueFile.Name(), data, 0400)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/alluxio/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package alluxio

import (
"fmt"
"io/ioutil"
"os"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
Expand Down Expand Up @@ -85,7 +84,7 @@ func (e *AlluxioEngine) generateAlluxioValueFile(runtime *datav1alpha1.AlluxioRu
}

//2. Get the template value file
valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", e.name, e.runtimeType))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", e.name, e.runtimeType))
if err != nil {
e.Log.Error(err, "failed to create value file", "valueFile", valueFile.Name())
return valueFileName, err
Expand All @@ -94,7 +93,7 @@ func (e *AlluxioEngine) generateAlluxioValueFile(runtime *datav1alpha1.AlluxioRu
valueFileName = valueFile.Name()
e.Log.V(1).Info("Save the values file", "valueFile", valueFileName)

err = ioutil.WriteFile(valueFileName, data, 0400)
err = os.WriteFile(valueFileName, data, 0400)
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/ddc/eac/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package eac

import (
"fmt"
"os"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/common"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/helm"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubectl"
"io/ioutil"
"os"

"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -83,7 +83,7 @@ func (e *EACEngine) generateEACValueFile(runtime *datav1alpha1.EACRuntime) (valu
}

//2. Get the template value file
valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", e.name, e.runtimeType))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", e.name, e.runtimeType))
if err != nil {
e.Log.Error(err, "failed to create value file", "valueFile", valueFile.Name())
return valueFileName, err
Expand All @@ -92,7 +92,7 @@ func (e *EACEngine) generateEACValueFile(runtime *datav1alpha1.EACRuntime) (valu
valueFileName = valueFile.Name()
e.Log.V(1).Info("Save the values file", "valueFile", valueFileName)

err = ioutil.WriteFile(valueFileName, data, 0400)
err = os.WriteFile(valueFileName, data, 0400)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/goosefs/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package goosefs

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -123,11 +122,11 @@ func (e *GooseFSEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestCon
return
}

valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
if err != nil {
return
}
err = ioutil.WriteFile(valueFile.Name(), data, 0400)
err = os.WriteFile(valueFile.Name(), data, 0400)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/goosefs/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package goosefs

import (
"fmt"
"io/ioutil"
"os"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
Expand Down Expand Up @@ -86,7 +85,7 @@ func (e *GooseFSEngine) generateGooseFSValueFile(runtime *datav1alpha1.GooseFSRu
}

//2. Get the template value file
valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", e.name, e.runtimeType))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", e.name, e.runtimeType))
if err != nil {
e.Log.Error(err, "failed to create value file", "valueFile", valueFile.Name())
return valueFileName, err
Expand All @@ -95,7 +94,7 @@ func (e *GooseFSEngine) generateGooseFSValueFile(runtime *datav1alpha1.GooseFSRu
valueFileName = valueFile.Name()
e.Log.V(1).Info("Save the values file", "valueFile", valueFileName)

err = ioutil.WriteFile(valueFileName, data, 0400)
err = os.WriteFile(valueFileName, data, 0400)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/jindo/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package jindo

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -153,11 +152,11 @@ func (e *JindoEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestConte
return
}

valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
if err != nil {
return
}
err = ioutil.WriteFile(valueFile.Name(), data, 0400)
err = os.WriteFile(valueFile.Name(), data, 0400)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/jindo/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package jindo

import (
"fmt"
"io/ioutil"
"os"

"github.com/fluid-cloudnative/fluid/pkg/utils"
Expand Down Expand Up @@ -63,15 +62,15 @@ func (e *JindoEngine) generateJindoValueFile() (valueFileName string, err error)
if err != nil {
return
}
valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", e.name, e.runtimeType))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", e.name, e.runtimeType))
if err != nil {
e.Log.Error(err, "failed to create value file", "valueFile", valueFile.Name())
return valueFileName, err
}
valueFileName = valueFile.Name()
e.Log.V(1).Info("Save the values file", "valueFile", valueFileName)

err = ioutil.WriteFile(valueFileName, data, 0400)
err = os.WriteFile(valueFileName, data, 0400)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/juicefs/data_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package juicefs

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -165,11 +164,11 @@ func (j *JuiceFSEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestCon
}
j.Log.Info("dataload value", "value", string(data))

valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
if err != nil {
return
}
err = ioutil.WriteFile(valueFile.Name(), data, 0400)
err = os.WriteFile(valueFile.Name(), data, 0400)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/juicefs/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package juicefs

import (
"fmt"
"io/ioutil"
"os"

"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -86,7 +85,7 @@ func (j *JuiceFSEngine) generateJuicefsValueFile(runtime *datav1alpha1.JuiceFSRu
}

//2. Get the template value file
valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", j.name, j.runtimeType))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", j.name, j.runtimeType))
if err != nil {
j.Log.Error(err, "failed to create value file", "valueFile", valueFile.Name())
return valueFileName, err
Expand All @@ -95,7 +94,7 @@ func (j *JuiceFSEngine) generateJuicefsValueFile(runtime *datav1alpha1.JuiceFSRu
valueFileName = valueFile.Name()
j.Log.Info("Save the values file", "valueFile", valueFileName)

err = ioutil.WriteFile(valueFileName, data, 0400)
err = os.WriteFile(valueFileName, data, 0400)
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/thin/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package thin

import (
"fmt"
"io/ioutil"
"os"

"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -89,7 +88,7 @@ func (t *ThinEngine) generateThinValueFile(runtime *datav1alpha1.ThinRuntime, pr
}

//2. Get the template value file
valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", t.name, t.runtimeType))
valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-values.yaml", t.name, t.runtimeType))
if err != nil {
t.Log.Error(err, "failed to create value file", "valueFile", valueFile.Name())
return valueFileName, err
Expand All @@ -98,7 +97,7 @@ func (t *ThinEngine) generateThinValueFile(runtime *datav1alpha1.ThinRuntime, pr
valueFileName = valueFile.Name()
t.Log.Info("Save the values file", "valueFile", valueFileName)

err = ioutil.WriteFile(valueFileName, data, 0400)
err = os.WriteFile(valueFileName, data, 0400)
if err != nil {
return
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dump

import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"runtime"
Expand Down Expand Up @@ -75,7 +74,7 @@ func InstallgoroutineDumpGenerator() {
func coredump(fileName string) {
log.Info("Dump stacktrace to file", "fileName", fileName)
trace := StackTrace(true)
err := ioutil.WriteFile(fileName, []byte(trace), 0644)
err := os.WriteFile(fileName, []byte(trace), 0644)
if err != nil {
log.Error(err, "Failed to write coredump.")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
package utils

import (
"io/ioutil"
"os"
"testing"
)
Expand All @@ -32,7 +31,7 @@ func TestPathExists(t *testing.T) {
}

func TestGetChartsDirectory(t *testing.T) {
f, err := ioutil.TempFile("", "test")
f, err := os.CreateTemp("", "test")
if err != nil {
t.Errorf("MkdirTemp failed due to %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/utils/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package helm

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -41,7 +40,7 @@ var helmCmd = []string{"ddc-helm"}
// It returns the name of the value file and error
func GenerateValueFile(values interface{}) (valueFileName string, err error) {
// 1. generate the template file
valueFile, err := ioutil.TempFile(os.TempDir(), "values")
valueFile, err := os.CreateTemp(os.TempDir(), "values")
if err != nil {
log.Error(err, "Failed to create tmp file", "tmpfile", valueFile.Name())
return "", err
Expand All @@ -60,7 +59,7 @@ func GenerateValueFile(values interface{}) (valueFileName string, err error) {
// returns generated template file: templateFileName
func GenerateHelmTemplate(name string, namespace string, valueFileName string, chartName string, options ...string) (templateFileName string, err error) {
tempName := fmt.Sprintf("%s.yaml", name)
templateFile, err := ioutil.TempFile("", tempName)
templateFile, err := os.CreateTemp("", tempName)
if err != nil {
return templateFileName, err
}
Expand Down
Loading

0 comments on commit 2967f96

Please sign in to comment.