Skip to content

Commit bf5db67

Browse files
authored
replace deprecated ioutil (#2531)
* replace deprecated ioutil * replace ioutil also in kubectl plugin
1 parent 8a1b2f4 commit bf5db67

File tree

8 files changed

+22
-23
lines changed

8 files changed

+22
-23
lines changed

kubectl-pg/cmd/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ package cmd
2525
import (
2626
"context"
2727
"fmt"
28-
"io/ioutil"
2928
"log"
29+
"os"
3030

3131
"github.com/spf13/cobra"
3232
v1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
@@ -56,7 +56,7 @@ func create(fileName string) {
5656
if err != nil {
5757
log.Fatal(err)
5858
}
59-
ymlFile, err := ioutil.ReadFile(fileName)
59+
ymlFile, err := os.ReadFile(fileName)
6060
if err != nil {
6161
log.Fatal(err)
6262
}

kubectl-pg/cmd/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ package cmd
2525
import (
2626
"context"
2727
"fmt"
28-
"io/ioutil"
2928
"log"
29+
"os"
3030

3131
"github.com/spf13/cobra"
3232
v1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
@@ -77,7 +77,7 @@ func deleteByFile(file string) {
7777
log.Fatal(err)
7878
}
7979

80-
ymlFile, err := ioutil.ReadFile(file)
80+
ymlFile, err := os.ReadFile(file)
8181
if err != nil {
8282
log.Fatal(err)
8383
}

kubectl-pg/cmd/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ package cmd
2525
import (
2626
"context"
2727
"fmt"
28-
"io/ioutil"
2928
"log"
29+
"os"
3030

3131
"github.com/spf13/cobra"
3232
v1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
@@ -60,7 +60,7 @@ func updatePgResources(fileName string) {
6060
if err != nil {
6161
log.Fatal(err)
6262
}
63-
ymlFile, err := ioutil.ReadFile(fileName)
63+
ymlFile, err := os.ReadFile(fileName)
6464
if err != nil {
6565
log.Fatal(err)
6666
}

pkg/cluster/pod_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cluster
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"testing"
99
"time"
@@ -86,7 +86,7 @@ func TestGetSwitchoverCandidate(t *testing.T) {
8686

8787
for _, tt := range tests {
8888
// mocking cluster members
89-
r := ioutil.NopCloser(bytes.NewReader([]byte(tt.clusterJson)))
89+
r := io.NopCloser(bytes.NewReader([]byte(tt.clusterJson)))
9090

9191
response := http.Response{
9292
StatusCode: 200,

pkg/cluster/sync_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cluster
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"testing"
99
"time"
@@ -201,7 +201,7 @@ func TestCheckAndSetGlobalPostgreSQLConfiguration(t *testing.T) {
201201

202202
// mocking a config after setConfig is called
203203
configJson := `{"postgresql": {"parameters": {"log_min_duration_statement": 200, "max_connections": 50}}}, "ttl": 20}`
204-
r := ioutil.NopCloser(bytes.NewReader([]byte(configJson)))
204+
r := io.NopCloser(bytes.NewReader([]byte(configJson)))
205205

206206
response := http.Response{
207207
StatusCode: 200,
@@ -531,7 +531,7 @@ func TestSyncStandbyClusterConfiguration(t *testing.T) {
531531
// mocking a config after getConfig is called
532532
mockClient := mocks.NewMockHTTPClient(ctrl)
533533
configJson := `{"ttl": 20}`
534-
r := ioutil.NopCloser(bytes.NewReader([]byte(configJson)))
534+
r := io.NopCloser(bytes.NewReader([]byte(configJson)))
535535
response := http.Response{
536536
StatusCode: 200,
537537
Body: r,
@@ -540,7 +540,7 @@ func TestSyncStandbyClusterConfiguration(t *testing.T) {
540540

541541
// mocking a config after setConfig is called
542542
standbyJson := `{"standby_cluster":{"create_replica_methods":["bootstrap_standby_with_wale","basebackup_fast_xlog"],"restore_command":"envdir \"/run/etc/wal-e.d/env-standby\" /scripts/restore_command.sh \"%f\" \"%p\""}}`
543-
r = ioutil.NopCloser(bytes.NewReader([]byte(standbyJson)))
543+
r = io.NopCloser(bytes.NewReader([]byte(standbyJson)))
544544
response = http.Response{
545545
StatusCode: 200,
546546
Body: r,
@@ -582,7 +582,7 @@ func TestSyncStandbyClusterConfiguration(t *testing.T) {
582582
assert.NoError(t, err)
583583

584584
configJson = `{"standby_cluster":{"create_replica_methods":["bootstrap_standby_with_wale","basebackup_fast_xlog"],"restore_command":"envdir \"/run/etc/wal-e.d/env-standby\" /scripts/restore_command.sh \"%f\" \"%p\""}, "ttl": 20}`
585-
r = ioutil.NopCloser(bytes.NewReader([]byte(configJson)))
585+
r = io.NopCloser(bytes.NewReader([]byte(configJson)))
586586
response = http.Response{
587587
StatusCode: 200,
588588
Body: r,

pkg/spec/types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"database/sql"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
87
"log"
98
"os"
109
"strings"
@@ -210,7 +209,7 @@ func GetOperatorNamespace() string {
210209
if namespaceFromEnvironment := os.Getenv("OPERATOR_NAMESPACE"); namespaceFromEnvironment != "" {
211210
return namespaceFromEnvironment
212211
}
213-
operatorNamespaceBytes, err := ioutil.ReadFile(fileWithNamespace)
212+
operatorNamespaceBytes, err := os.ReadFile(fileWithNamespace)
214213
if err != nil {
215214
log.Fatalf("Unable to detect operator namespace from within its pod due to: %v", err)
216215
}

pkg/util/patroni/patroni.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"math"
99
"net"
1010
"net/http"
@@ -104,7 +104,7 @@ func (p *Patroni) httpPostOrPatch(method string, url string, body *bytes.Buffer)
104104
}()
105105

106106
if resp.StatusCode != http.StatusOK {
107-
bodyBytes, err := ioutil.ReadAll(resp.Body)
107+
bodyBytes, err := io.ReadAll(resp.Body)
108108
if err != nil {
109109
return fmt.Errorf("could not read response: %v", err)
110110
}
@@ -123,7 +123,7 @@ func (p *Patroni) httpGet(url string) (string, error) {
123123
}
124124
defer response.Body.Close()
125125

126-
bodyBytes, err := ioutil.ReadAll(response.Body)
126+
bodyBytes, err := io.ReadAll(response.Body)
127127
if err != nil {
128128
return "", fmt.Errorf("could not read response: %v", err)
129129
}

pkg/util/patroni/patroni_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"math"
99
"net/http"
1010
"reflect"
@@ -122,7 +122,7 @@ func TestGetClusterMembers(t *testing.T) {
122122
{"name": "acid-test-cluster-2", "role": "replica", "state": "running", "api_url": "http://192.168.100.3:8008/patroni", "host": "192.168.100.3", "port": 5432, "timeline": 1, "lag": "unknown"},
123123
{"name": "acid-test-cluster-3", "role": "replica", "state": "running", "api_url": "http://192.168.100.3:8008/patroni", "host": "192.168.100.3", "port": 5432, "timeline": 1, "lag": 3000000000}
124124
]}`
125-
r := ioutil.NopCloser(bytes.NewReader([]byte(json)))
125+
r := io.NopCloser(bytes.NewReader([]byte(json)))
126126

127127
response := http.Response{
128128
StatusCode: 200,
@@ -161,7 +161,7 @@ func TestGetMemberData(t *testing.T) {
161161
}
162162

163163
json := `{"state": "running", "postmaster_start_time": "2021-02-19 14:31:50.053 CET", "role": "master", "server_version": 130004, "cluster_unlocked": false, "xlog": {"location": 123456789}, "timeline": 1, "database_system_identifier": "6462555844314089962", "pending_restart": true, "patroni": {"version": "2.1.1", "scope": "acid-test-cluster"}}`
164-
r := ioutil.NopCloser(bytes.NewReader([]byte(json)))
164+
r := io.NopCloser(bytes.NewReader([]byte(json)))
165165

166166
response := http.Response{
167167
StatusCode: 200,
@@ -230,7 +230,7 @@ func TestGetConfig(t *testing.T) {
230230
}
231231

232232
configJson := `{"loop_wait": 10, "maximum_lag_on_failover": 33554432, "postgresql": {"parameters": {"archive_mode": "on", "archive_timeout": "1800s", "autovacuum_analyze_scale_factor": 0.02, "autovacuum_max_workers": 5, "autovacuum_vacuum_scale_factor": 0.05, "checkpoint_completion_target": 0.9, "hot_standby": "on", "log_autovacuum_min_duration": 0, "log_checkpoints": "on", "log_connections": "on", "log_disconnections": "on", "log_line_prefix": "%t [%p]: [%l-1] %c %x %d %u %a %h ", "log_lock_waits": "on", "log_min_duration_statement": 500, "log_statement": "ddl", "log_temp_files": 0, "max_connections": 100, "max_replication_slots": 10, "max_wal_senders": 10, "tcp_keepalives_idle": 900, "tcp_keepalives_interval": 100, "track_functions": "all", "wal_level": "hot_standby", "wal_log_hints": "on"}, "use_pg_rewind": true, "use_slots": true}, "retry_timeout": 10, "slots": {"cdc": {"database": "foo", "plugin": "pgoutput", "type": "logical"}}, "ttl": 30}`
233-
r := ioutil.NopCloser(bytes.NewReader([]byte(configJson)))
233+
r := io.NopCloser(bytes.NewReader([]byte(configJson)))
234234

235235
response := http.Response{
236236
StatusCode: 200,
@@ -265,7 +265,7 @@ func TestSetPostgresParameters(t *testing.T) {
265265
}
266266

267267
configJson := `{"loop_wait": 10, "maximum_lag_on_failover": 33554432, "postgresql": {"parameters": {"archive_mode": "on", "archive_timeout": "1800s", "autovacuum_analyze_scale_factor": 0.02, "autovacuum_max_workers": 5, "autovacuum_vacuum_scale_factor": 0.05, "checkpoint_completion_target": 0.9, "hot_standby": "on", "log_autovacuum_min_duration": 0, "log_checkpoints": "on", "log_connections": "on", "log_disconnections": "on", "log_line_prefix": "%t [%p]: [%l-1] %c %x %d %u %a %h ", "log_lock_waits": "on", "log_min_duration_statement": 500, "log_statement": "ddl", "log_temp_files": 0, "max_connections": 50, "max_replication_slots": 10, "max_wal_senders": 10, "tcp_keepalives_idle": 900, "tcp_keepalives_interval": 100, "track_functions": "all", "wal_level": "logical", "wal_log_hints": "on"}, "use_pg_rewind": true, "use_slots": true}, "retry_timeout": 10, "slots": {"cdc": {"database": "foo", "plugin": "pgoutput", "type": "logical"}}, "ttl": 30}`
268-
r := ioutil.NopCloser(bytes.NewReader([]byte(configJson)))
268+
r := io.NopCloser(bytes.NewReader([]byte(configJson)))
269269

270270
response := http.Response{
271271
StatusCode: 200,

0 commit comments

Comments
 (0)