mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
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:
parent
15ed9709d4
commit
562dff0d19
@ -320,7 +320,7 @@ func (kms *VaultTenantSA) getTokenPath() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(dir+"/token", []byte(token), 0600)
|
err = os.WriteFile(dir+"/token", []byte(token), 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to write token for ServiceAccount %s/%s: %w", kms.tenantSAName, kms.Tenant, err)
|
return "", fmt.Errorf("failed to write token for ServiceAccount %s/%s: %w", kms.tenantSAName, kms.Tenant, err)
|
||||||
}
|
}
|
||||||
|
@ -1625,7 +1625,7 @@ func stashRBDImageMetadata(volOptions *rbdVolume, metaDataPath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fPath := filepath.Join(metaDataPath, stashFileName)
|
fPath := filepath.Join(metaDataPath, stashFileName)
|
||||||
err = ioutil.WriteFile(fPath, encodedBytes, 0o600)
|
err = os.WriteFile(fPath, encodedBytes, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to stash JSON image metadata for image (%s) at path (%s): %w", volOptions, fPath, err)
|
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)
|
fPath := filepath.Join(metaDataPath, stashFileName)
|
||||||
err = ioutil.WriteFile(fPath, encodedBytes, 0600)
|
err = os.WriteFile(fPath, encodedBytes, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to stash JSON image metadata at path: (%s) for spec:(%s) : %w",
|
return fmt.Errorf("failed to stash JSON image metadata at path: (%s) for spec:(%s) : %w",
|
||||||
fPath, imgMeta.String(), err)
|
fPath, imgMeta.String(), err)
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ func WriteCephConfig() error {
|
|||||||
|
|
||||||
// create config file if it does not exist to support backward compatibility
|
// create config file if it does not exist to support backward compatibility
|
||||||
if _, err = os.Stat(CephConfigPath); os.IsNotExist(err) {
|
if _, err = os.Stat(CephConfigPath); os.IsNotExist(err) {
|
||||||
err = ioutil.WriteFile(CephConfigPath, cephConfig, 0o600)
|
err = os.WriteFile(CephConfigPath, cephConfig, 0o600)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -142,7 +142,7 @@ func TestGetClusterMappingInfo(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
mappingConfigFile := fmt.Sprintf("%s/mapping-%d.json", mappingBasePath, currentI)
|
mappingConfigFile := fmt.Sprintf("%s/mapping-%d.json", mappingBasePath, currentI)
|
||||||
if len(currentTT.mappingFilecontent) != 0 {
|
if len(currentTT.mappingFilecontent) != 0 {
|
||||||
err = ioutil.WriteFile(mappingConfigFile, currentTT.mappingFilecontent, 0o600)
|
err = os.WriteFile(mappingConfigFile, currentTT.mappingFilecontent, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to write to %q, error = %v", mappingConfigFile, err)
|
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)
|
clusterMappingConfigFile = fmt.Sprintf("%s/mapping.json", mappingBasePath)
|
||||||
err = ioutil.WriteFile(clusterMappingConfigFile, mappingFileContent, 0o600)
|
err = os.WriteFile(clusterMappingConfigFile, mappingFileContent, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to write mapping content error = %v", err)
|
t.Errorf("failed to write mapping content error = %v", err)
|
||||||
}
|
}
|
||||||
@ -318,7 +318,7 @@ func TestFetchMappedClusterIDAndMons(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal csi config info %v", err)
|
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 {
|
if err != nil {
|
||||||
t.Errorf("failed to write %s file content: %v", CsiConfigFile, err)
|
t.Errorf("failed to write %s file content: %v", CsiConfigFile, err)
|
||||||
}
|
}
|
||||||
@ -351,7 +351,7 @@ func TestFetchMappedClusterIDAndMons(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal mapping info %v", err)
|
t.Errorf("failed to marshal mapping info %v", err)
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(clusterMappingConfigFile, clusterMappingFileContent, 0o600)
|
err = os.WriteFile(clusterMappingConfigFile, clusterMappingFileContent, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to write %s file content: %v", clusterMappingFileContent, err)
|
t.Errorf("failed to write %s file content: %v", clusterMappingFileContent, err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -81,7 +80,7 @@ func TestConnPool(t *testing.T) {
|
|||||||
|
|
||||||
// create a keyfile with some contents
|
// create a keyfile with some contents
|
||||||
keyfile := "/tmp/conn_utils.keyfile"
|
keyfile := "/tmp/conn_utils.keyfile"
|
||||||
err := ioutil.WriteFile(keyfile, []byte("the-key"), 0o600)
|
err := os.WriteFile(keyfile, []byte("the-key"), 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to create keyfile: %v", err)
|
t.Errorf("failed to create keyfile: %v", err)
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -54,7 +53,7 @@ func TestCSIConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = ""
|
data = ""
|
||||||
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
|
err = os.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Test setup error %s", err)
|
t.Errorf("Test setup error %s", err)
|
||||||
}
|
}
|
||||||
@ -66,7 +65,7 @@ func TestCSIConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = "[{\"clusterIDBad\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}]"
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Test setup error %s", err)
|
t.Errorf("Test setup error %s", err)
|
||||||
}
|
}
|
||||||
@ -78,7 +77,7 @@ func TestCSIConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitorsBad\":[\"mon1\",\"mon2\",\"mon3\"]}]"
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Test setup error %s", err)
|
t.Errorf("Test setup error %s", err)
|
||||||
}
|
}
|
||||||
@ -90,7 +89,7 @@ func TestCSIConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",2,\"mon3\"]}]"
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Test setup error %s", err)
|
t.Errorf("Test setup error %s", err)
|
||||||
}
|
}
|
||||||
@ -102,7 +101,7 @@ func TestCSIConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}]"
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Test setup error %s", err)
|
t.Errorf("Test setup error %s", err)
|
||||||
}
|
}
|
||||||
@ -121,7 +120,7 @@ func TestCSIConfig(t *testing.T) {
|
|||||||
|
|
||||||
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}," +
|
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}," +
|
||||||
"{\"clusterID\":\"" + clusterID1 + "\",\"monitors\":[\"mon4\",\"mon5\",\"mon6\"]}]"
|
"{\"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 {
|
if err != nil {
|
||||||
t.Errorf("Test setup error %s", err)
|
t.Errorf("Test setup error %s", err)
|
||||||
}
|
}
|
||||||
@ -134,7 +133,7 @@ func TestCSIConfig(t *testing.T) {
|
|||||||
|
|
||||||
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}," +
|
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}," +
|
||||||
"{\"clusterID\":\"" + clusterID1 + "\",\"monitors\":[\"mon4\",\"mon5\",\"mon6\"]}]"
|
"{\"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 {
|
if err != nil {
|
||||||
t.Errorf("Test setup error %s", err)
|
t.Errorf("Test setup error %s", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user