Skip to content

Commit

Permalink
Replace deprecated ioutil module usage
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpiritXIII committed Sep 21, 2023
1 parent fd899f0 commit 967bbd0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
3 changes: 1 addition & 2 deletions e2e/operator_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"os"
"os/signal"
"strings"
Expand Down Expand Up @@ -264,7 +263,7 @@ func (tctx *OperatorContext) createBaseResources(ctx context.Context) ([]metav1.
}

if gcpServiceAccount != "" {
b, err := ioutil.ReadFile(gcpServiceAccount)
b, err := os.ReadFile(gcpServiceAccount)
if err != nil {
return nil, fmt.Errorf("read GCP service account file: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"strconv"
"time"
Expand Down Expand Up @@ -167,7 +167,7 @@ func New(logger logr.Logger, clientConfig *rest.Config, opts Options) (*Operator
return nil, fmt.Errorf("invalid options: %w", err)
}
// Create temporary directory to store webhook serving cert files.
certDir, err := ioutil.TempDir("", "operator-cert")
certDir, err := os.MkdirTemp("", "operator-cert")
if err != nil {
return nil, fmt.Errorf("create temporary certificate dir: %w", err)
}
Expand Down Expand Up @@ -482,10 +482,10 @@ func (o *Operator) ensureCerts(ctx context.Context, dir string) ([]byte, error)
return nil, errors.New("Flags key-base64 and cert-base64 must both be set.")
}
// Create cert/key files.
if err := ioutil.WriteFile(filepath.Join(dir, "tls.crt"), crt, 0666); err != nil {
if err := os.WriteFile(filepath.Join(dir, "tls.crt"), crt, 0666); err != nil {
return nil, fmt.Errorf("create cert file: %w", err)
}
if err := ioutil.WriteFile(filepath.Join(dir, "tls.key"), key, 0666); err != nil {
if err := os.WriteFile(filepath.Join(dir, "tls.key"), key, 0666); err != nil {
return nil, fmt.Errorf("create key file: %w", err)
}
return caData, nil
Expand Down
9 changes: 4 additions & 5 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package operator

import (
"context"
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -32,19 +31,19 @@ import (
)

func readKeyAndCertFiles(dir string, t *testing.T) ([]byte, []byte) {
outCert, err := ioutil.ReadFile(path.Join(dir, "tls.crt"))
outCert, err := os.ReadFile(path.Join(dir, "tls.crt"))
if err != nil {
t.Fatalf("error reading from cert file: %v", err)
}
outKey, err := ioutil.ReadFile(path.Join(dir, "tls.key"))
outKey, err := os.ReadFile(path.Join(dir, "tls.key"))
if err != nil {
t.Fatalf("error reading from key file: %v", err)
}
return outCert, outKey
}

func TestEnsureCertsExplicit(t *testing.T) {
dir, err := ioutil.TempDir("", "test_ensure_certs")
dir, err := os.MkdirTemp("", "test_ensure_certs")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -127,7 +126,7 @@ func TestEnsureCertsSelfSigned(t *testing.T) {
)
t.Cleanup(cancel)

dir, err := ioutil.TempDir("", "test_ensure_certs")
dir, err := os.MkdirTemp("", "test_ensure_certs")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package ui
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -48,7 +48,7 @@ func Handler(externalURL *url.URL) http.Handler {
fmt.Fprintf(w, "Error opening React index.html: %v", err)
return
}
idx, err := ioutil.ReadAll(f)
idx, err := io.ReadAll(f)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Error reading React index.html: %v", err)
Expand Down

0 comments on commit 967bbd0

Please sign in to comment.