cleanup: use os.WriteFile to write files

as ioutil.WriteFile is deprecated and
suggestion is to use os.WriteFile as
per https://pkg.go.dev/io/ioutil updating
the same.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2022-01-21 14:58:27 +05:30 committed by mergify[bot]
parent 15ed9709d4
commit 562dff0d19
6 changed files with 17 additions and 20 deletions

View File

@ -320,7 +320,7 @@ func (kms *VaultTenantSA) getTokenPath() (string, error) {
return "", err
}
err = ioutil.WriteFile(dir+"/token", []byte(token), 0600)
err = os.WriteFile(dir+"/token", []byte(token), 0600)
if err != nil {
return "", fmt.Errorf("failed to write token for ServiceAccount %s/%s: %w", kms.tenantSAName, kms.Tenant, err)
}

View File

@ -1625,7 +1625,7 @@ func stashRBDImageMetadata(volOptions *rbdVolume, metaDataPath string) error {
}
fPath := filepath.Join(metaDataPath, stashFileName)
err = ioutil.WriteFile(fPath, encodedBytes, 0o600)
err = os.WriteFile(fPath, encodedBytes, 0o600)
if err != nil {
return fmt.Errorf("failed to stash JSON image metadata for image (%s) at path (%s): %w", volOptions, fPath, err)
}
@ -1673,7 +1673,7 @@ func updateRBDImageMetadataStash(metaDataPath, device string) error {
}
fPath := filepath.Join(metaDataPath, stashFileName)
err = ioutil.WriteFile(fPath, encodedBytes, 0600)
err = os.WriteFile(fPath, encodedBytes, 0600)
if err != nil {
return fmt.Errorf("failed to stash JSON image metadata at path: (%s) for spec:(%s) : %w",
fPath, imgMeta.String(), err)

View File

@ -17,7 +17,6 @@ limitations under the License.
package util
import (
"io/ioutil"
"os"
)
@ -57,7 +56,7 @@ func WriteCephConfig() error {
// create config file if it does not exist to support backward compatibility
if _, err = os.Stat(CephConfigPath); os.IsNotExist(err) {
err = ioutil.WriteFile(CephConfigPath, cephConfig, 0o600)
err = os.WriteFile(CephConfigPath, cephConfig, 0o600)
}
if err != nil {

View File

@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
@ -142,7 +142,7 @@ func TestGetClusterMappingInfo(t *testing.T) {
t.Parallel()
mappingConfigFile := fmt.Sprintf("%s/mapping-%d.json", mappingBasePath, currentI)
if len(currentTT.mappingFilecontent) != 0 {
err = ioutil.WriteFile(mappingConfigFile, currentTT.mappingFilecontent, 0o600)
err = os.WriteFile(mappingConfigFile, currentTT.mappingFilecontent, 0o600)
if err != nil {
t.Errorf("failed to write to %q, error = %v", mappingConfigFile, err)
}
@ -158,7 +158,7 @@ func TestGetClusterMappingInfo(t *testing.T) {
}
clusterMappingConfigFile = fmt.Sprintf("%s/mapping.json", mappingBasePath)
err = ioutil.WriteFile(clusterMappingConfigFile, mappingFileContent, 0o600)
err = os.WriteFile(clusterMappingConfigFile, mappingFileContent, 0o600)
if err != nil {
t.Errorf("failed to write mapping content error = %v", err)
}
@ -318,7 +318,7 @@ func TestFetchMappedClusterIDAndMons(t *testing.T) {
if err != nil {
t.Errorf("failed to marshal csi config info %v", err)
}
err = ioutil.WriteFile(csiConfigFile, csiConfigFileContent, 0o600)
err = os.WriteFile(csiConfigFile, csiConfigFileContent, 0o600)
if err != nil {
t.Errorf("failed to write %s file content: %v", CsiConfigFile, err)
}
@ -351,7 +351,7 @@ func TestFetchMappedClusterIDAndMons(t *testing.T) {
if err != nil {
t.Errorf("failed to marshal mapping info %v", err)
}
err = ioutil.WriteFile(clusterMappingConfigFile, clusterMappingFileContent, 0o600)
err = os.WriteFile(clusterMappingConfigFile, clusterMappingFileContent, 0o600)
if err != nil {
t.Errorf("failed to write %s file content: %v", clusterMappingFileContent, err)
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package util
import (
"io/ioutil"
"os"
"testing"
"time"
@ -81,7 +80,7 @@ func TestConnPool(t *testing.T) {
// create a keyfile with some contents
keyfile := "/tmp/conn_utils.keyfile"
err := ioutil.WriteFile(keyfile, []byte("the-key"), 0o600)
err := os.WriteFile(keyfile, []byte("the-key"), 0o600)
if err != nil {
t.Errorf("failed to create keyfile: %v", err)

View File

@ -17,7 +17,6 @@ limitations under the License.
package util
import (
"io/ioutil"
"os"
"testing"
)
@ -54,7 +53,7 @@ func TestCSIConfig(t *testing.T) {
}
data = ""
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
err = os.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -66,7 +65,7 @@ func TestCSIConfig(t *testing.T) {
}
data = "[{\"clusterIDBad\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
err = os.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -78,7 +77,7 @@ func TestCSIConfig(t *testing.T) {
}
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitorsBad\":[\"mon1\",\"mon2\",\"mon3\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
err = os.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -90,7 +89,7 @@ func TestCSIConfig(t *testing.T) {
}
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",2,\"mon3\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
err = os.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -102,7 +101,7 @@ func TestCSIConfig(t *testing.T) {
}
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
err = os.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -121,7 +120,7 @@ func TestCSIConfig(t *testing.T) {
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}," +
"{\"clusterID\":\"" + clusterID1 + "\",\"monitors\":[\"mon4\",\"mon5\",\"mon6\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
err = os.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -134,7 +133,7 @@ func TestCSIConfig(t *testing.T) {
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}," +
"{\"clusterID\":\"" + clusterID1 + "\",\"monitors\":[\"mon4\",\"mon5\",\"mon6\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
err = os.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}