Skip to content
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
3 changes: 1 addition & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -62,7 +61,7 @@ func newRunCommand() *cobra.Command {

// User can specify a path to a template used for Git commit messages
if commitMessagePath != "" {
tpl, err := ioutil.ReadFile(commitMessagePath)
tpl, err := os.ReadFile(commitMessagePath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
log.Warnf("commit message template at %s does not exist, using default", commitMessagePath)
Expand Down
4 changes: 2 additions & 2 deletions cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"text/template"
"time"

Expand Down Expand Up @@ -37,7 +37,7 @@ If PATH is not given, will show you the default message that is used.
tplStr = common.DefaultGitCommitMessage
} else {
commitMessageTemplatePath = args[0]
tplData, err := ioutil.ReadFile(commitMessageTemplatePath)
tplData, err := os.ReadFile(commitMessageTemplatePath)
if err != nil {
log.Fatalf("%v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec:
project: default
source:
path: helm-guestbook
repoURL: https://github.com/argocd-example-apps/argocd-example-apps
repoURL: https://github.com/argoproj/argocd-example-apps
targetRevision: HEAD
```

Expand Down
11 changes: 5 additions & 6 deletions ext/git/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -118,10 +117,10 @@ func (c HTTPSCreds) Environ() (io.Closer, []string, error) {
// We need to actually create two temp files, one for storing cert data and
// another for storing the key. If we fail to create second fail, the first
// must be removed.
certFile, err := ioutil.TempFile(argoio.TempDir, "")
certFile, err := os.CreateTemp(argoio.TempDir, "")
if err == nil {
defer certFile.Close()
keyFile, err = ioutil.TempFile(argoio.TempDir, "")
keyFile, err = os.CreateTemp(argoio.TempDir, "")
if err != nil {
removeErr := os.Remove(certFile.Name())
if removeErr != nil {
Expand Down Expand Up @@ -204,7 +203,7 @@ func (f authFilePaths) Close() error {

func (c SSHCreds) Environ() (io.Closer, []string, error) {
// use the SHM temp dir from util, more secure
file, err := ioutil.TempFile(argoio.TempDir, "")
file, err := os.CreateTemp(argoio.TempDir, "")
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -275,10 +274,10 @@ func (g GitHubAppCreds) Environ() (io.Closer, []string, error) {
// We need to actually create two temp files, one for storing cert data and
// another for storing the key. If we fail to create second fail, the first
// must be removed.
certFile, err := ioutil.TempFile(argoio.TempDir, "")
certFile, err := os.CreateTemp(argoio.TempDir, "")
if err == nil {
defer certFile.Close()
keyFile, err = ioutil.TempFile(argoio.TempDir, "")
keyFile, err = os.CreateTemp(argoio.TempDir, "")
if err != nil {
removeErr := os.Remove(certFile.Name())
if removeErr != nil {
Expand Down
16 changes: 8 additions & 8 deletions ext/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package git

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -137,11 +137,11 @@ func TestCustomHTTPClient(t *testing.T) {
assert.NoError(t, err)
assert.NotEqual(t, "", keyFile)

certData, err := ioutil.ReadFile(certFile)
certData, err := os.ReadFile(certFile)
assert.NoError(t, err)
assert.NotEqual(t, "", string(certData))

keyData, err := ioutil.ReadFile(keyFile)
keyData, err := os.ReadFile(keyFile)
assert.NoError(t, err)
assert.NotEqual(t, "", string(keyData))

Expand Down Expand Up @@ -245,7 +245,7 @@ func TestLFSClient(t *testing.T) {
// TODO(alexmt): dockerize tests in and enabled it
t.Skip()

tempDir, err := ioutil.TempDir("", "git-client-lfs-test-")
tempDir, err := os.MkdirTemp("", "git-client-lfs-test-")
assert.NoError(t, err)
if err == nil {
defer func() { _ = os.RemoveAll(tempDir) }()
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestLFSClient(t *testing.T) {
assert.NoError(t, err)
if err == nil {
defer fileHandle.Close()
text, err := ioutil.ReadAll(fileHandle)
text, err := io.ReadAll(fileHandle)
assert.NoError(t, err)
if err == nil {
assert.Equal(t, "This is not a YAML, sorry.\n", string(text))
Expand All @@ -284,7 +284,7 @@ func TestLFSClient(t *testing.T) {
}

func TestVerifyCommitSignature(t *testing.T) {
p, err := ioutil.TempDir("", "test-verify-commit-sig")
p, err := os.MkdirTemp("", "test-verify-commit-sig")
if err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestNewFactory(t *testing.T) {
test.Flaky(t)
}

dirName, err := ioutil.TempDir("", "git-client-test-")
dirName, err := os.MkdirTemp("", "git-client-test-")
assert.NoError(t, err)
defer func() { _ = os.RemoveAll(dirName) }()

Expand Down Expand Up @@ -381,7 +381,7 @@ func TestNewFactory(t *testing.T) {
}

func TestListRevisions(t *testing.T) {
dir, err := ioutil.TempDir("", "test-list-revisions")
dir, err := os.MkdirTemp("", "test-list-revisions")
if err != nil {
panic(err.Error())
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/argocd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -136,7 +135,7 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
}
var gitC git.Client
if wbc.GitClient == nil {
tempRoot, err := ioutil.TempDir(os.TempDir(), fmt.Sprintf("git-%s", app.Name))
tempRoot, err := os.MkdirTemp(os.TempDir(), fmt.Sprintf("git-%s", app.Name))
if err != nil {
return err
}
Expand Down Expand Up @@ -220,12 +219,12 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis

commitOpts := &git.CommitOptions{}
if wbc.GitCommitMessage != "" {
cm, err := ioutil.TempFile("", "image-updater-commit-msg")
cm, err := os.CreateTemp("", "image-updater-commit-msg")
if err != nil {
return fmt.Errorf("cold not create temp file: %v", err)
}
logCtx.Debugf("Writing commit message to %s", cm.Name())
err = ioutil.WriteFile(cm.Name(), []byte(wbc.GitCommitMessage), 0600)
err = os.WriteFile(cm.Name(), []byte(wbc.GitCommitMessage), 0600)
if err != nil {
_ = cm.Close()
return fmt.Errorf("could not write commit message to %s: %v", cm.Name(), err)
Expand Down Expand Up @@ -269,7 +268,7 @@ func writeOverrides(app *v1alpha1.Application, wbc *WriteBackConfig, gitC git.Cl
// our generated new file is the same as the existing one, and if yes, we
// don't proceed further for commit.
if targetExists {
data, err := ioutil.ReadFile(targetFile)
data, err := os.ReadFile(targetFile)
if err != nil {
return err, false
}
Expand All @@ -279,7 +278,7 @@ func writeOverrides(app *v1alpha1.Application, wbc *WriteBackConfig, gitC git.Cl
}
}

err = ioutil.WriteFile(targetFile, override, 0600)
err = os.WriteFile(targetFile, override, 0600)
if err != nil {
return
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package argocd
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -1816,7 +1815,7 @@ func Test_CommitUpdates(t *testing.T) {
gitMock, dir, cleanup := mockGit(t)
defer cleanup()
kf := filepath.Join(dir, "kustomization.yml")
assert.NoError(t, ioutil.WriteFile(kf, []byte(`
assert.NoError(t, os.WriteFile(kf, []byte(`
kind: Kustomization
apiVersion: kustomize.config.k8s.io/v1beta1

Expand All @@ -1838,7 +1837,7 @@ replacements: []

err = commitChanges(app, wbc, nil)
assert.NoError(t, err)
kust, err := ioutil.ReadFile(kf)
kust, err := os.ReadFile(kf)
assert.NoError(t, err)
assert.YAMLEq(t, `
kind: Kustomization
Expand All @@ -1857,7 +1856,7 @@ replacements: []
app.Spec.Source.Kustomize.Images = v1alpha1.KustomizeImages{"foo:123", "bar=qux"}
err = commitChanges(app, wbc, nil)
assert.NoError(t, err)
kust, err = ioutil.ReadFile(kf)
kust, err = os.ReadFile(kf)
assert.NoError(t, err)
assert.YAMLEq(t, `
kind: Kustomization
Expand Down Expand Up @@ -2044,7 +2043,7 @@ func Test_parseTarget(t *testing.T) {
}

func mockGit(t *testing.T) (gitMock *gitmock.Client, dir string, cleanup func()) {
dir, err := ioutil.TempDir("", "wb-kust")
dir, err := os.MkdirTemp("", "wb-kust")
assert.NoError(t, err)
gitMock = &gitmock.Client{}
gitMock.On("Root").Return(dir)
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package registry

import (
"fmt"
"io/ioutil"
"os"
"time"

"github.com/argoproj-labs/argocd-image-updater/pkg/log"
Expand Down Expand Up @@ -40,7 +40,7 @@ func clearRegistries() {
// LoadRegistryConfiguration loads a YAML-formatted registry configuration from
// a given file at path.
func LoadRegistryConfiguration(path string, clear bool) error {
registryBytes, err := ioutil.ReadFile(path)
registryBytes, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions test/fixture/capture.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fixture

import (
"io/ioutil"
"io"
"os"
)

Expand All @@ -22,7 +22,7 @@ func CaptureStdout(callback func()) (string, error) {

w.Close()

data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)

if err != nil {
return "", err
Expand All @@ -46,7 +46,7 @@ func CaptureStderr(callback func()) (string, error) {
callback()
w.Close()

data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)

if err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions test/fixture/fileutil.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package fixture

// Fixture functions for tests related to files
import "os"

import "io/ioutil"
// Fixture functions for tests related to files

// MustReadFile must read a file from given path. Panics if it can't.
func MustReadFile(path string) string {
retBytes, err := ioutil.ReadFile(path)
retBytes, err := os.ReadFile(path)
if err != nil {
panic(err)
}
Expand Down