Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cni/network/multitenancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -86,7 +86,7 @@ func (m *Multitenancy) DetermineSnatFeatureOnHost(snatFile, nmAgentSupportedApis

// Check if we've already retrieved NMAgent version and determined whether to disable snat on host
if jsonFile, retrieveSnatConfigErr = os.Open(snatFile); retrieveSnatConfigErr == nil {
bytes, _ := ioutil.ReadAll(jsonFile)
bytes, _ := io.ReadAll(jsonFile)
jsonFile.Close()
if retrieveSnatConfigErr = json.Unmarshal(bytes, &snatConfig); retrieveSnatConfigErr != nil {
log.Errorf("[cni-net] failed to unmarshal to snatConfig with error %v",
Expand All @@ -110,7 +110,7 @@ func (m *Multitenancy) DetermineSnatFeatureOnHost(snatFile, nmAgentSupportedApis
if resp.StatusCode == http.StatusOK {
var bodyBytes []byte
// if the list of APIs (strings) contains the nmAgentSnatSupportAPI we will disable snat on host
if bodyBytes, retrieveSnatConfigErr = ioutil.ReadAll(resp.Body); retrieveSnatConfigErr == nil {
if bodyBytes, retrieveSnatConfigErr = io.ReadAll(resp.Body); retrieveSnatConfigErr == nil {
bodyStr := string(bodyBytes)
if !strings.Contains(bodyStr, nmAgentSnatAndDnsSupportAPI) {
snatConfig.EnableSnatForDns = true
Expand Down
4 changes: 2 additions & 2 deletions cni/network/plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"reflect"
"time"
Expand Down Expand Up @@ -78,7 +78,7 @@ func validateConfig(jsonBytes []byte) error {

func getCmdArgsFromEnv() (string, *skel.CmdArgs, error) {
log.Printf("Going to read from stdin")
stdinData, err := ioutil.ReadAll(os.Stdin)
stdinData, err := io.ReadAll(os.Stdin)
if err != nil {
return "", nil, fmt.Errorf("error reading from stdin: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cnm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package cnm

import (
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -90,7 +89,7 @@ func (plugin *Plugin) EnableDiscovery() error {
// Write the listener URL to the spec file.
fileName := path + plugin.Name + ".spec"
url := plugin.Listener.URL.String()
err := ioutil.WriteFile(fileName, []byte(url), 0o644)
err := os.WriteFile(fileName, []byte(url), 0o644)
return err
}

Expand Down
8 changes: 4 additions & 4 deletions cns/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -55,7 +55,7 @@ type mockdo struct {

func (m *mockdo) Do(req *http.Request) (*http.Response, error) {
byteArray, _ := json.Marshal(m.objToReturn)
body := ioutil.NopCloser(bytes.NewReader(byteArray))
body := io.NopCloser(bytes.NewReader(byteArray))

return &http.Response{
StatusCode: m.httpStatusCodeToReturn,
Expand Down Expand Up @@ -146,8 +146,8 @@ func TestMain(m *testing.M) {
res *http.Response
)

tmpFileState, err := ioutil.TempFile(os.TempDir(), "cns-*.json")
tmpLogDir, err := ioutil.TempDir("", "cns-")
tmpFileState, err := os.CreateTemp(os.TempDir(), "cns-*.json")
tmpLogDir, err := os.MkdirTemp("", "cns-")
fmt.Printf("logdir: %+v", tmpLogDir)

if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cns/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package configuration

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -93,7 +92,7 @@ func ReadConfig() (*CNSConfig, error) {
}

func readConfigFromFile(f string) (*CNSConfig, error) {
content, err := ioutil.ReadFile(f)
content, err := os.ReadFile(f)
if err != nil {
return nil, errors.Wrapf(err, "failed to read config file %s", f)
}
Expand Down
3 changes: 1 addition & 2 deletions cns/networkcontainers/networkcontainers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"go/types"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -112,7 +111,7 @@ func DeleteLoopbackAdapter(adapterName string) error {

// This function gets the flattened network configuration (compliant with azure cni) in byte array format
func getNetworkConfig(configFilePath string) ([]byte, error) {
content, err := ioutil.ReadFile(configFilePath)
content, err := os.ReadFile(configFilePath)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -169,7 +169,7 @@ func StartProcess(path string, args []string) error {

// GetHostMetadata - retrieve VM metadata from wireserver
func GetHostMetadata(fileName string) (Metadata, error) {
content, err := ioutil.ReadFile(fileName)
content, err := os.ReadFile(fileName)
if err == nil {
var metadata Metadata
if err = json.Unmarshal(content, &metadata); err == nil {
Expand Down Expand Up @@ -225,7 +225,7 @@ func SaveHostMetadata(metadata Metadata, fileName string) error {
return fmt.Errorf("[Telemetry] marshal data failed with err %+v", err)
}

if err = ioutil.WriteFile(fileName, dataBytes, 0o644); err != nil {
if err = os.WriteFile(fileName, dataBytes, 0o644); err != nil {
log.Printf("[Telemetry] Writing metadata to file failed: %v", err)
}

Expand Down Expand Up @@ -257,7 +257,7 @@ func GetAzureCloud(url string) (string, error) {
return "", fmt.Errorf("Bad http status:%v", resp.Status)
}

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions ipam/fileIpam.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package ipam
import (
"encoding/json"
"errors"
"io/ioutil"
"net"
"os"
"runtime"
"strings"

Expand Down Expand Up @@ -123,7 +123,7 @@ func (source *fileIpamSource) refresh() error {
}

func getSDNInterfaces(fileLocation string) (*NetworkInterfaces, error) {
data, err := ioutil.ReadFile(fileLocation)
data, err := os.ReadFile(fileLocation)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package log

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -65,7 +64,7 @@ func TestPid(t *testing.T) {
fn := l.GetLogDirectory() + logName + ".log"
defer os.Remove(fn)

logBytes, err := ioutil.ReadFile(fn)
logBytes, err := os.ReadFile(fn)
if err != nil {
t.Fatalf("Failed to read log, %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions npm/cmd/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"bytes"
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -51,7 +51,7 @@ func testCommand(t *testing.T, tests []*testCases) {

require.NoError(t, err)

out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)
if tt.wantErr {
require.NotEmpty(t, out)
Expand Down
4 changes: 2 additions & 2 deletions npm/http/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package server

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -35,7 +35,7 @@ func TestGetNPMCacheHandler(t *testing.T) {
status, http.StatusOK)
}

byteArray, err := ioutil.ReadAll(rr.Body)
byteArray, err := io.ReadAll(rr.Body)
if err != nil {
t.Errorf("failed to read response's data : %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions npm/pkg/controlplane/controllers/v1/translatePolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package controllers

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"testing"
Expand Down Expand Up @@ -1116,7 +1116,7 @@ func TestTranslateEgress(t *testing.T) {
func readPolicyYaml(policyYaml string) (*networkingv1.NetworkPolicy, error) {
decode := scheme.Codecs.UniversalDeserializer().Decode
policyYamlLocation := filepath.Join(testPolicyDir, policyYaml)
b, err := ioutil.ReadFile(policyYamlLocation)
b, err := os.ReadFile(policyYamlLocation)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions npm/pkg/dataplane/debug/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
"os/exec"
"strconv"
"strings"
Expand All @@ -31,7 +32,7 @@ type Converter struct {

// NpmCacheFromFile initialize NPM cache from file.
func (c *Converter) NpmCacheFromFile(npmCacheJSONFile string) error {
byteArray, err := ioutil.ReadFile(npmCacheJSONFile)
byteArray, err := os.ReadFile(npmCacheJSONFile)
if err != nil {
return fmt.Errorf("failed to read %s file : %w", npmCacheJSONFile, err)
}
Expand Down Expand Up @@ -60,7 +61,7 @@ func (c *Converter) NpmCache() error {
return fmt.Errorf("failed to request NPM Cache : %w", err)
}
defer resp.Body.Close()
byteArray, err := ioutil.ReadAll(resp.Body)
byteArray, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response's data : %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions npm/pkg/dataplane/parse/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parse
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"

NPMIPtable "github.com/Azure/azure-container-networking/npm/pkg/dataplane/iptables"
Expand Down Expand Up @@ -44,7 +44,7 @@ func Iptables(tableName string) (*NPMIPtable.Table, error) {
// IptablesFile creates a Go object from specified iptable by reading from an iptables-save file.
func IptablesFile(tableName string, iptableSaveFile string) (*NPMIPtable.Table, error) {
iptableBuffer := bytes.NewBuffer(nil)
byteArray, err := ioutil.ReadFile(iptableSaveFile)
byteArray, err := os.ReadFile(iptableSaveFile)
if err != nil {
return nil, fmt.Errorf("%w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions platform/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package platform
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -38,7 +37,7 @@ const (

// GetOSInfo returns OS version information.
func GetOSInfo() string {
info, err := ioutil.ReadFile("/proc/version")
info, err := os.ReadFile("/proc/version")
if err != nil {
return "unknown"
}
Expand Down
3 changes: 1 addition & 2 deletions processlock/filelock_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package processlock

import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -73,7 +72,7 @@ func TestFileLock(t *testing.T) {
require.NoError(t, err, "Calling Release lock again should not throw error for already released lock:%v", err)

// read lockfile contents to check if contents match with pid of current process
b, errRead := ioutil.ReadFile(tt.lockfileName)
b, errRead := os.ReadFile(tt.lockfileName)
require.NoError(t, errRead, "Got error reading lockfile:%v", errRead)
pidStr := string(b)
pid, _ := strconv.Atoi(pidStr)
Expand Down
4 changes: 2 additions & 2 deletions server/tls/tlscertificate_retriever_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
)

const (
Expand Down Expand Up @@ -52,7 +52,7 @@ func (fcert *linuxTlsCertificateRetriever) GetPrivateKey() (crypto.PrivateKey, e

// ReadFile reads a from disk
func (fcert *linuxTlsCertificateRetriever) readFile() ([]byte, error) {
content, err := ioutil.ReadFile(fcert.settings.TLSCertificatePath)
content, err := os.ReadFile(fcert.settings.TLSCertificatePath)
if err != nil {
return nil, fmt.Errorf("Error reading file from path %s with error: %+v ", fcert.settings.TLSCertificatePath, err)
}
Expand Down
3 changes: 1 addition & 2 deletions server/tls/tlscertificate_retriever_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"os"
"testing"
Expand All @@ -25,7 +24,7 @@ func TestPemConsumptionLinux(t *testing.T) {
currentDirectory, _ := os.Getwd()
pemLocation := fmt.Sprintf("%s/%s.Pem", currentDirectory, commonName)

ioutil.WriteFile(pemLocation, pemContent, 0o644)
os.WriteFile(pemLocation, pemContent, 0o644)
defer os.Remove(pemLocation)

config := TlsSettings{
Expand Down
4 changes: 2 additions & 2 deletions server/tls/tlscertificate_retriever_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/billgraziano/dpapi"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (wtls *windowsTlsCertificateRetriever) GetPrivateKey() (crypto.PrivateKey,

// ReadFile reads a from disk
func (wtls *windowsTlsCertificateRetriever) readFile() ([]byte, error) {
content, err := ioutil.ReadFile(wtls.settings.TLSCertificatePath)
content, err := os.ReadFile(wtls.settings.TLSCertificatePath)
if err != nil {
return nil, fmt.Errorf("Error reading file from path %s with error: %+v ", wtls.settings.TLSCertificatePath, err)
}
Expand Down
Loading