Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move from ioutil to io/os instead #1338

Merged
merged 1 commit into from
Nov 14, 2022
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 kubectl-minio/cmd/resources/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package resources

import (
"io"
"io/fs"
"io/ioutil"
"log"
"path"
"strings"
Expand Down Expand Up @@ -117,7 +117,7 @@ func LoadTenantCRD(decode func(data []byte, defaults *schema.GroupVersionKind, i
if err != nil {
log.Fatal(err)
}
contentBytes, err := ioutil.ReadAll(contents)
contentBytes, err := io.ReadAll(contents)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func copyFileToMemFS(src, dst string, memFS filesys.FileSystem) error {
defer dstFileDesc.Close()

// Note: I had to read the whole string, for some reason io.Copy was not copying the whole content
input, err := ioutil.ReadAll(srcFileDesc)
input, err := io.ReadAll(srcFileDesc)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions logsearchapi/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -153,7 +153,7 @@ func (ls *LogSearch) ingestHandler(w http.ResponseWriter, r *http.Request) {
return
}

buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
ls.writeErrorResponse(w, 500, "Error reading request body", err)
return
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/minio.min.io/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -63,7 +62,7 @@ type hostsTemplateValues struct {
// GetNSFromFile assumes the operator is running inside a k8s pod and extract the
// current namespace from the /var/run/secrets/kubernetes.io/serviceaccount/namespace file
func GetNSFromFile() string {
namespace, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
namespace, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
if err != nil {
return "minio-operator"
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/apis/minio.min.io/v2/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -132,7 +131,7 @@ var (
// GetPodCAFromFile assumes the operator is running inside a k8s pod and extract the
// current ca certificate from /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
func GetPodCAFromFile() []byte {
namespace, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")
namespace, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")
if err != nil {
return nil
}
Expand All @@ -142,7 +141,7 @@ func GetPodCAFromFile() []byte {
// GetNSFromFile assumes the operator is running inside a k8s pod and extract the
// current namespace from the /var/run/secrets/kubernetes.io/serviceaccount/namespace file
func GetNSFromFile() string {
namespace, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
namespace, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
if err != nil {
return "minio-operator"
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/cluster/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -268,7 +267,7 @@ func (c *Controller) createSecret(ctx context.Context, tenant *miniov2.Tenant, l
}

func parseCertificate(r io.Reader) (*x509.Certificate, error) {
certPEMBlock, err := ioutil.ReadAll(r)
certPEMBlock, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/cluster/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -334,7 +333,7 @@ func drainBody(respBody io.ReadCloser) {
// the same connection for future uses.
// - http://stackoverflow.com/a/17961593/4465767
defer respBody.Close()
io.Copy(ioutil.Discard, respBody)
io.Copy(io.Discard, respBody)
}
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/controller/cluster/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -112,15 +111,15 @@ func (c *Controller) generateTLSCert() (*string, *string) {
privateKeyKey = "tls.key"
}
if val, ok := operatorTLSCert.Data[publicCertKey]; ok {
err := ioutil.WriteFile(publicCertPath, val, 0o644)
err := os.WriteFile(publicCertPath, val, 0o644)
if err != nil {
panic(err)
}
} else {
panic(fmt.Errorf("missing '%s' in %s/%s", publicCertKey, operatorTLSCert.Namespace, operatorTLSCert.Name))
}
if val, ok := operatorTLSCert.Data[privateKeyKey]; ok {
err := ioutil.WriteFile(publicKeyPath, val, 0o644)
err := os.WriteFile(publicKeyPath, val, 0o644)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -474,11 +473,11 @@ var serverCertsManager *xcerts.Manager
// from the provided paths. The private key may be encrypted and is
// decrypted using the ENV_VAR: OPERATOR_CERT_PASSWD.
func LoadX509KeyPair(certFile, keyFile string) (tls.Certificate, error) {
certPEMBlock, err := ioutil.ReadFile(certFile)
certPEMBlock, err := os.ReadFile(certFile)
if err != nil {
return tls.Certificate{}, err
}
keyPEMBlock, err := ioutil.ReadFile(keyFile)
keyPEMBlock, err := os.ReadFile(keyFile)
if err != nil {
return tls.Certificate{}, err
}
Expand Down
3 changes: 1 addition & 2 deletions subnet/subnet-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -337,7 +336,7 @@ func subnetReqDo(r *http.Request, headers map[string]string) (string, error) {
}

defer resp.Body.Close()
respBytes, e := ioutil.ReadAll(io.LimitReader(resp.Body, subnetRespBodyLimit))
respBytes, e := io.ReadAll(io.LimitReader(resp.Body, subnetRespBodyLimit))
if e != nil {
return "", e
}
Expand Down