mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
cleanup: use os.ReadFile to read file
as ioutil.ReadFile is deprecated and suggestion is to use os.ReadFile 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
562dff0d19
commit
aba6979d29
@ -19,7 +19,6 @@ package e2e
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -79,7 +78,7 @@ func deleteCephfsPlugin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createORDeleteCephfsResources(action kubectlAction) {
|
func createORDeleteCephfsResources(action kubectlAction) {
|
||||||
csiDriver, err := ioutil.ReadFile(cephFSDirPath + csiDriverObject)
|
csiDriver, err := os.ReadFile(cephFSDirPath + csiDriverObject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// createORDeleteRbdResources is used for upgrade testing as csidriverObject is
|
// createORDeleteRbdResources is used for upgrade testing as csidriverObject is
|
||||||
// newly added, discarding file not found error.
|
// newly added, discarding file not found error.
|
||||||
@ -92,7 +91,7 @@ func createORDeleteCephfsResources(action kubectlAction) {
|
|||||||
e2elog.Failf("failed to %s CSIDriver object: %v", action, err)
|
e2elog.Failf("failed to %s CSIDriver object: %v", action, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cephConf, err := ioutil.ReadFile(examplePath + cephConfconfigMap)
|
cephConf, err := os.ReadFile(examplePath + cephConfconfigMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// createORDeleteCephfsResources is used for upgrade testing as cephConfConfigmap is
|
// createORDeleteCephfsResources is used for upgrade testing as cephConfConfigmap is
|
||||||
// newly added, discarding file not found error.
|
// newly added, discarding file not found error.
|
||||||
|
@ -19,7 +19,7 @@ package e2e
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ func deleteNamespace(c kubernetes.Interface, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func replaceNamespaceInTemplate(filePath string) (string, error) {
|
func replaceNamespaceInTemplate(filePath string) (string, error) {
|
||||||
read, err := ioutil.ReadFile(filePath)
|
read, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -120,7 +119,7 @@ func deleteRBDPlugin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createORDeleteRbdResources(action kubectlAction) {
|
func createORDeleteRbdResources(action kubectlAction) {
|
||||||
csiDriver, err := ioutil.ReadFile(rbdDirPath + csiDriverObject)
|
csiDriver, err := os.ReadFile(rbdDirPath + csiDriverObject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// createORDeleteRbdResources is used for upgrade testing as csidriverObject is
|
// createORDeleteRbdResources is used for upgrade testing as csidriverObject is
|
||||||
// newly added, discarding file not found error.
|
// newly added, discarding file not found error.
|
||||||
@ -133,7 +132,7 @@ func createORDeleteRbdResources(action kubectlAction) {
|
|||||||
e2elog.Failf("failed to %s CSIDriver object: %v", action, err)
|
e2elog.Failf("failed to %s CSIDriver object: %v", action, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cephConf, err := ioutil.ReadFile(examplePath + cephConfconfigMap)
|
cephConf, err := os.ReadFile(examplePath + cephConfconfigMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// createORDeleteRbdResources is used for upgrade testing as cephConf Configmap is
|
// createORDeleteRbdResources is used for upgrade testing as cephConf Configmap is
|
||||||
// newly added, discarding file not found error.
|
// newly added, discarding file not found error.
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -160,7 +160,7 @@ func deleteResource(scPath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func unmarshal(fileName string, obj interface{}) error {
|
func unmarshal(fileName string, obj interface{}) error {
|
||||||
f, err := ioutil.ReadFile(fileName)
|
f, err := os.ReadFile(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ceph/ceph-csi/internal/util/k8s"
|
"github.com/ceph/ceph-csi/internal/util/k8s"
|
||||||
@ -94,7 +93,7 @@ func GetKMS(tenant, kmsID string, secrets map[string]string) (EncryptionKMS, err
|
|||||||
func getKMSConfiguration() (map[string]interface{}, error) {
|
func getKMSConfiguration() (map[string]interface{}, error) {
|
||||||
var config map[string]interface{}
|
var config map[string]interface{}
|
||||||
// #nosec
|
// #nosec
|
||||||
content, err := ioutil.ReadFile(kmsConfigPath)
|
content, err := os.ReadFile(kmsConfigPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// kmsConfigPath exists and was successfully read
|
// kmsConfigPath exists and was successfully read
|
||||||
err = json.Unmarshal(content, &config)
|
err = json.Unmarshal(content, &config)
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -244,7 +243,7 @@ func GetKrbdSupportedFeatures() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val, err := ioutil.ReadFile(krbdSupportedFeaturesFile)
|
val, err := os.ReadFile(krbdSupportedFeaturesFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLogMsg("reading file %q failed: %v", krbdSupportedFeaturesFile, err)
|
log.ErrorLogMsg("reading file %q failed: %v", krbdSupportedFeaturesFile, err)
|
||||||
|
|
||||||
@ -1638,7 +1637,7 @@ func lookupRBDImageMetadataStash(metaDataPath string) (rbdImageMetadataStash, er
|
|||||||
var imgMeta rbdImageMetadataStash
|
var imgMeta rbdImageMetadataStash
|
||||||
|
|
||||||
fPath := filepath.Join(metaDataPath, stashFileName)
|
fPath := filepath.Join(metaDataPath, stashFileName)
|
||||||
encodedBytes, err := ioutil.ReadFile(fPath) // #nosec - intended reading from fPath
|
encodedBytes, err := os.ReadFile(fPath) // #nosec - intended reading from fPath
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return imgMeta, fmt.Errorf("failed to read stashed JSON image metadata from path (%s): %w", fPath, err)
|
return imgMeta, fmt.Errorf("failed to read stashed JSON image metadata from path (%s): %w", fPath, err)
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ceph/ceph-csi/internal/util/log"
|
"github.com/ceph/ceph-csi/internal/util/log"
|
||||||
@ -70,7 +69,7 @@ type ClusterMappingInfo struct {
|
|||||||
|
|
||||||
func readClusterMappingInfo(filename string) (*[]ClusterMappingInfo, error) {
|
func readClusterMappingInfo(filename string) (*[]ClusterMappingInfo, error) {
|
||||||
var info []ClusterMappingInfo
|
var info []ClusterMappingInfo
|
||||||
content, err := ioutil.ReadFile(filename) // #nosec:G304, file inclusion via variable.
|
content, err := os.ReadFile(filename) // #nosec:G304, file inclusion via variable.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("error fetching clusterID mapping %w", err)
|
err = fmt.Errorf("error fetching clusterID mapping %w", err)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func (cp *ConnPool) Destroy() {
|
|||||||
|
|
||||||
func (cp *ConnPool) generateUniqueKey(monitors, user, keyfile string) (string, error) {
|
func (cp *ConnPool) generateUniqueKey(monitors, user, keyfile string) (string, error) {
|
||||||
// the keyfile can be unique for operations, contents will be the same
|
// the keyfile can be unique for operations, contents will be the same
|
||||||
key, err := ioutil.ReadFile(keyfile) // #nosec:G304, file inclusion via variable.
|
key, err := os.ReadFile(keyfile) // #nosec:G304, file inclusion via variable.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not open keyfile %s: %w", keyfile, err)
|
return "", fmt.Errorf("could not open keyfile %s: %w", keyfile, err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ func readClusterInfo(pathToConfig, clusterID string) (*ClusterInfo, error) {
|
|||||||
var config []ClusterInfo
|
var config []ClusterInfo
|
||||||
|
|
||||||
// #nosec
|
// #nosec
|
||||||
content, err := ioutil.ReadFile(pathToConfig)
|
content, err := os.ReadFile(pathToConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("error fetching configuration for cluster ID %q: %w", clusterID, err)
|
err = fmt.Errorf("error fetching configuration for cluster ID %q: %w", clusterID, err)
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ package log
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -24,7 +23,7 @@ import (
|
|||||||
// compressed format.
|
// compressed format.
|
||||||
func GzipLogFile(pathToFile string) error {
|
func GzipLogFile(pathToFile string) error {
|
||||||
// Get all the bytes from the file.
|
// Get all the bytes from the file.
|
||||||
content, err := ioutil.ReadFile(pathToFile) // #nosec:G304, file inclusion via variable.
|
content, err := os.ReadFile(pathToFile) // #nosec:G304, file inclusion via variable.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user