Skip to content

Commit

Permalink
Address ioutil deprecation in touched files
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsn723 committed Jul 24, 2024
1 parent 7d9aedf commit 4dae54f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions prober/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"crypto/x509"
"encoding/base64"
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"os"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -338,7 +339,7 @@ func collectFileMetrics(logger log.Logger, files []string, registry *prometheus.
registry.MustRegister(fileNotAfter, fileNotBefore)

for _, f := range files {
data, err := ioutil.ReadFile(f)
data, err := os.ReadFile(f)
if err != nil {
level.Debug(logger).Log("msg", fmt.Sprintf("Error reading file %s: %s", f, err))
continue
Expand Down Expand Up @@ -449,7 +450,7 @@ func collectKubeconfigMetrics(logger log.Logger, kubeconfig KubeConfig, registry
return err
}
} else if c.Cluster.CertificateAuthority != "" {
data, err = ioutil.ReadFile(c.Cluster.CertificateAuthority)
data, err = os.ReadFile(c.Cluster.CertificateAuthority)
if err != nil {
level.Debug(logger).Log("msg", fmt.Sprintf("Error reading file %s: %s", c.Cluster.CertificateAuthority, err))
return err
Expand Down Expand Up @@ -485,7 +486,7 @@ func collectKubeconfigMetrics(logger log.Logger, kubeconfig KubeConfig, registry
return err
}
} else if u.User.ClientCertificate != "" {
data, err = ioutil.ReadFile(u.User.ClientCertificate)
data, err = os.ReadFile(u.User.ClientCertificate)
if err != nil {
level.Debug(logger).Log("msg", fmt.Sprintf("Error reading file %s: %s", u.User.ClientCertificate, err))
return err
Expand Down Expand Up @@ -593,7 +594,7 @@ func fetchCRL(cert, issuer *x509.Certificate) (*x509.RevocationList, error) {
}
defer resp.Body.Close()

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"net"
"os"
"time"
)

Expand Down Expand Up @@ -123,7 +123,7 @@ func GenerateCRL(entry *x509.RevocationListEntry, issuer *x509.Certificate, key

// WriteFile writes some content to a temporary file
func WriteFile(filename string, contents []byte) (string, error) {
tmpFile, err := ioutil.TempFile("", filename)
tmpFile, err := os.CreateTemp("", filename)
if err != nil {
return tmpFile.Name(), err
}
Expand Down

0 comments on commit 4dae54f

Please sign in to comment.