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

Replace deprecated io/ioutil references #193

Merged
merged 1 commit into from
Apr 15, 2024
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
5 changes: 2 additions & 3 deletions cmd/meta_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/MusicDin/kubitect/pkg/app"
Expand Down Expand Up @@ -76,8 +76,7 @@ func clusters(ctx app.AppContext, local bool) (MetaClusters, error) {
path = ctx.ClustersDir()
}

files, err := ioutil.ReadDir(path)

files, err := os.ReadDir(path)
if err != nil {
return nil, fmt.Errorf("failed to read clusters directory: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions embed/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package embed
import (
"embed"
"io/fs"
"io/ioutil"
"os"
"path"
)
Expand Down Expand Up @@ -93,7 +92,7 @@ func MirrorResource(resPath, dstPath string) error {

resDstPath := path.Join(dstPath, resPath)
os.MkdirAll(path.Dir(resDstPath), os.ModePerm)
return ioutil.WriteFile(resDstPath, content, os.ModePerm)
return os.WriteFile(resDstPath, content, os.ModePerm)
}

mirrorDir := func(fPath string, f fs.DirEntry, err error) error {
Expand All @@ -112,7 +111,7 @@ func MirrorResource(resPath, dstPath string) error {
return err
}

return ioutil.WriteFile(resDstPath, content, os.ModePerm)
return os.WriteFile(resDstPath, content, os.ModePerm)
}

return fs.WalkDir(efs, resPath, mirrorDir)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cluster/cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cluster

import (
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestSync_InvalidInfraConfig(t *testing.T) {
err := os.MkdirAll(path.Dir(c.InfrastructureConfigPath()), 0777)
require.NoError(t, err)

err = ioutil.WriteFile(c.InfrastructureConfigPath(), []byte(cfg), 0777)
err = os.WriteFile(c.InfrastructureConfigPath(), []byte(cfg), 0777)
require.NoError(t, err)

assert.ErrorContains(t, c.Sync(), "infrastructure file (produced by Terraform) is invalid")
Expand Down
3 changes: 1 addition & 2 deletions pkg/cluster/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cluster

import (
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -34,7 +33,7 @@ func WriteConfigMockFile(t *testing.T) string {
cfg := "value: test"
cfgPath := path.Join(t.TempDir(), "cfg.yaml")

err := ioutil.WriteFile(cfgPath, []byte(cfg), os.ModePerm)
err := os.WriteFile(cfgPath, []byte(cfg), os.ModePerm)
assert.NoError(t, err)

return cfgPath
Expand Down
3 changes: 1 addition & 2 deletions pkg/tools/virtualenv/virtualenv_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package virtualenv

import (
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -16,7 +15,7 @@ func MockReqFile(t *testing.T) string {
reqFile := "netaddr==0.7.19"
reqPath := path.Join(t.TempDir(), "requirements.txt")

err := ioutil.WriteFile(reqPath, []byte(reqFile), os.ModePerm)
err := os.WriteFile(reqPath, []byte(reqFile), os.ModePerm)
require.NoError(t, err)

return reqPath
Expand Down
5 changes: 2 additions & 3 deletions pkg/utils/file/file_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package file

import (
"io/ioutil"
"os"
"path"
"strings"
Expand All @@ -21,7 +20,7 @@ func tmpFile(t *testing.T, name string, content ...string) string {
fPath := path.Join(t.TempDir(), name)
fData := strings.Join(content, " ")

err := ioutil.WriteFile(fPath, []byte(fData), os.ModePerm)
err := os.WriteFile(fPath, []byte(fData), os.ModePerm)
require.NoErrorf(t, err, "failed creating tmp file (%s): %v", name, err)

return fPath
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestWriteYaml(t *testing.T) {
err := WriteYaml(T{7}, fPath, os.ModePerm)
require.NoError(t, err)

f, err := ioutil.ReadFile(fPath)
f, err := os.ReadFile(fPath)
assert.Equal(t, "value: 7\n", string(f))
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/utils/keygen/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"path"

Expand All @@ -27,7 +26,7 @@ type (
// Note that the directory to which the key is
// written must exist.
func (k key) Write(path string) error {
return ioutil.WriteFile(path, k.value, 0600)
return os.WriteFile(path, k.value, 0600)
}

type (
Expand Down Expand Up @@ -93,14 +92,14 @@ func ReadKeyPair(dir, keyName string) (KeyPair, error) {
var pair keyPair

privKeyPath := path.Join(dir, keyName)
pair.private.value, err = ioutil.ReadFile(privKeyPath)
pair.private.value, err = os.ReadFile(privKeyPath)
if err != nil {
return nil, NewKeyFileError("private", keyName, err)
}

pubKeyName := keyName + ".pub"
pubKeyPath := path.Join(dir, pubKeyName)
pair.public.value, err = ioutil.ReadFile(pubKeyPath)
pair.public.value, err = os.ReadFile(pubKeyPath)
if err != nil {
return nil, NewKeyFileError("public", keyName+".pub", err)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/utils/keygen/keygen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keygen

import (
"errors"
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -20,7 +19,7 @@ func TestKeyWrite(t *testing.T) {
err := key.Write(keyPath)
require.NoError(t, err)

keyFile, err := ioutil.ReadFile(keyPath)
keyFile, err := os.ReadFile(keyPath)
require.NoError(t, err)
assert.Equal(t, "test", string(keyFile))
}
Expand Down Expand Up @@ -134,12 +133,12 @@ func TestKeyPair_Write(t *testing.T) {
require.NoError(t, kp.Write(tmpDir, keyName))

privKeyPath := path.Join(tmpDir, keyName)
privKey, err := ioutil.ReadFile(privKeyPath)
privKey, err := os.ReadFile(privKeyPath)
require.NoError(t, err)
require.Contains(t, string(privKey), "RSA PRIVATE KEY")

pubKeyPath := path.Join(tmpDir, keyName+".pub")
pubKey, err := ioutil.ReadFile(pubKeyPath)
pubKey, err := os.ReadFile(pubKeyPath)
require.NoError(t, err)
assert.Contains(t, string(pubKey), "ssh-rsa")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/template/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package template

import (
"bytes"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -106,7 +105,7 @@ func write(dstPath string, bytes []byte) error {
return err
}

return ioutil.WriteFile(dstPath, bytes, 0644)
return os.WriteFile(dstPath, bytes, 0644)
}

// TrimTemplate trims alls leading and trailing spaces from each line
Expand Down