mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
replace all the deprecated ioutil with io and os
This commit is contained in:
parent
e8ac6d8a8e
commit
584d994133
@ -1 +1 @@
|
||||
2.36
|
||||
2.37
|
||||
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||
package auditproxy
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -57,7 +57,7 @@ func main(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
func handler(w http.ResponseWriter, req *http.Request) {
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
log.Printf("could not read request body: %v", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
@ -18,7 +18,7 @@ package converter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@ -117,7 +117,7 @@ func doConversionV1(convertRequest *v1.ConversionRequest, convert convertFunc) *
|
||||
func serve(w http.ResponseWriter, r *http.Request, convert convertFunc) {
|
||||
var body []byte
|
||||
if r.Body != nil {
|
||||
if data, err := ioutil.ReadAll(r.Body); err == nil {
|
||||
if data, err := io.ReadAll(r.Body); err == nil {
|
||||
body = data
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ package dns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -66,7 +66,7 @@ func printHostsFile(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
func readFile(fileName string) string {
|
||||
fileData, err := ioutil.ReadFile(fileName)
|
||||
fileData, err := os.ReadFile(fileName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package guestbook
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -278,7 +278,7 @@ func dialHTTP(request, hostPort string) (string, error) {
|
||||
defer transport.CloseIdleConnections()
|
||||
if err == nil {
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err == nil {
|
||||
return string(body), nil
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ package mounttest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@ -146,7 +145,7 @@ func readFileContent(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
contentBytes, err := ioutil.ReadFile(path)
|
||||
contentBytes, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
fmt.Printf("error reading file content for %q: %v\n", path, err)
|
||||
return err
|
||||
@ -164,7 +163,7 @@ func readWriteNewFile(path string, perm os.FileMode) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := ioutil.WriteFile(path, []byte(initialContent), perm)
|
||||
err := os.WriteFile(path, []byte(initialContent), perm)
|
||||
if err != nil {
|
||||
fmt.Printf("error writing new file %q: %v\n", path, err)
|
||||
return err
|
||||
@ -188,7 +187,7 @@ func testFileContent(filePath string, retryDuration int, breakOnExpectedContent
|
||||
|
||||
retryTime := time.Second * time.Duration(retryDuration)
|
||||
for start := time.Now(); time.Since(start) < retryTime; time.Sleep(2 * time.Second) {
|
||||
contentBytes, err = ioutil.ReadFile(filePath)
|
||||
contentBytes, err = os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading file %s: %v, retrying\n", filePath, err)
|
||||
continue
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -164,7 +164,7 @@ func handleRunRequest(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("error reading body: %v", err), 400)
|
||||
return
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -426,7 +425,7 @@ func dialHTTP(request string, addr net.Addr) (string, error) {
|
||||
defer transport.CloseIdleConnections()
|
||||
if err == nil {
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err == nil {
|
||||
return string(body), nil
|
||||
}
|
||||
@ -524,7 +523,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
f, err := ioutil.TempFile("/uploads", "upload")
|
||||
f, err := os.CreateTemp("/uploads", "upload")
|
||||
if err != nil {
|
||||
result["error"] = "Unable to open file for write"
|
||||
bytes, err := json.Marshal(result)
|
||||
|
@ -35,7 +35,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -349,7 +349,7 @@ func contactSingle(e string, state *State) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err = ioutil.ReadAll(resp.Body)
|
||||
body, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
state.Logf("Warning: unable to read response from '%v': '%v'", e, err)
|
||||
return
|
||||
|
@ -18,7 +18,7 @@ package nosnatproxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
@ -80,7 +80,7 @@ func checknosnat(w http.ResponseWriter, req *http.Request) {
|
||||
w.WriteHeader(500)
|
||||
fmt.Fprintf(w, "error querying %q, err: %v", url, err)
|
||||
} else {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
fmt.Fprintf(w, "error reading body of response from %q, err: %v", url, err)
|
||||
|
@ -18,7 +18,7 @@ package nosnat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@ -141,7 +141,7 @@ func check(ip string, pip string, nip string) error {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package openidmetadata
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -163,7 +162,7 @@ func (k *claims) String() string {
|
||||
}
|
||||
|
||||
func gettoken() (string, error) {
|
||||
b, err := ioutil.ReadFile(tokenPath)
|
||||
b, err := os.ReadFile(tokenPath)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ package webhook
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -93,7 +93,7 @@ func delegateV1beta1AdmitToV1(f admitv1Func) admitv1beta1Func {
|
||||
func serve(w http.ResponseWriter, r *http.Request, admit admitHandler) {
|
||||
var body []byte
|
||||
if r.Body != nil {
|
||||
if data, err := ioutil.ReadAll(r.Body); err == nil {
|
||||
if data, err := io.ReadAll(r.Body); err == nil {
|
||||
body = data
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
1.4
|
||||
1.5
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@ -118,7 +117,7 @@ func loadNewProfiles() (success bool, newProfiles []string) {
|
||||
|
||||
success = true
|
||||
for _, dir := range dirs {
|
||||
infos, err := ioutil.ReadDir(dir)
|
||||
infos, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
klog.Warningf("Error reading %s: %v", dir, err)
|
||||
success = false
|
||||
@ -207,12 +206,17 @@ func loadProfiles(path string) error {
|
||||
|
||||
// If the given fileinfo is a symlink, return the FileInfo of the target. Otherwise, return the
|
||||
// given fileinfo.
|
||||
func resolveSymlink(basePath string, info os.FileInfo) (os.FileInfo, error) {
|
||||
if info.Mode()&os.ModeSymlink == 0 {
|
||||
// Not a symlink.
|
||||
return info, nil
|
||||
func resolveSymlink(basePath string, entry os.DirEntry) (os.FileInfo, error) {
|
||||
if info, err := entry.Info(); err != nil {
|
||||
return nil, fmt.Errorf("error getting the fileInfo: %v", err)
|
||||
} else {
|
||||
if info.Mode()&os.ModeSymlink == 0 {
|
||||
// Not a symlink.
|
||||
return info, nil
|
||||
}
|
||||
}
|
||||
fpath := filepath.Join(basePath, info.Name())
|
||||
|
||||
fpath := filepath.Join(basePath, entry.Name())
|
||||
resolvedName, err := filepath.EvalSymlinks(fpath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error resolving symlink %s: %v", fpath, err)
|
||||
|
@ -1 +1 @@
|
||||
1.5
|
||||
1.6
|
||||
|
@ -20,7 +20,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
@ -77,7 +77,7 @@ func shellOut(sendStdin, script string) {
|
||||
stdin.Write([]byte(sendStdin))
|
||||
stdin.Close()
|
||||
|
||||
out, err := ioutil.ReadAll(stdout)
|
||||
out, err := io.ReadAll(stdout)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to execute %v: %v, err: %v", script, string(out), err)
|
||||
}
|
||||
@ -104,7 +104,7 @@ func main() {
|
||||
|
||||
// If domain is not provided, try to get it from resolv.conf
|
||||
if *domain == "" {
|
||||
resolvConfBytes, err := ioutil.ReadFile("/etc/resolv.conf")
|
||||
resolvConfBytes, err := os.ReadFile("/etc/resolv.conf")
|
||||
resolvConf := string(resolvConfBytes)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to read /etc/resolv.conf")
|
||||
|
Loading…
Reference in New Issue
Block a user