Skip to content

Commit efd892e

Browse files
authored
Merge pull request #1674 from oyiz-michael/fix/typos-and-modernize-ioutil
Fix spelling errors and modernize deprecated io/ioutil usage
2 parents e9bfa56 + eda74d8 commit efd892e

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

pkg/driver/efs_watch_dog.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package driver
1616
import (
1717
"fmt"
1818
"io"
19-
"io/ioutil"
2019
"os"
2120
"os/exec"
2221
"path/filepath"
@@ -224,7 +223,6 @@ func (w *execWatchdog) setup(efsClientSource string) error {
224223
}
225224

226225
/*
227-
*
228226
At image build time, static files installed by efs-utils in the config directory, i.e. CAs file, need
229227
to be saved in another place so that the other stateful files created at runtime, i.e. private key for
230228
client certificate, in the same config directory can be persisted to host with a host path volume.
@@ -240,7 +238,7 @@ func copyWithoutOverwriting(srcDir, dstDir string) error {
240238
return err
241239
}
242240

243-
entries, err := ioutil.ReadDir(srcDir)
241+
entries, err := os.ReadDir(srcDir)
244242
if err != nil {
245243
return err
246244
}
@@ -360,7 +358,7 @@ the newer stunnel binaries will fail to run as this option is no longer supporte
360358
To avoid any errors, we check for this config and remove it directly on startup.
361359
*/
362360
func (w *execWatchdog) removeLibwrapOption(stateDir string) error {
363-
stunnelFiles, err := ioutil.ReadDir(stateDir)
361+
stunnelFiles, err := os.ReadDir(stateDir)
364362
if err != nil {
365363
return fmt.Errorf("error reading directory %s: %v", efsStateDir, err)
366364
}
@@ -369,7 +367,7 @@ func (w *execWatchdog) removeLibwrapOption(stateDir string) error {
369367
if strings.HasPrefix(file.Name(), "stunnel-config.") {
370368
filePath := filepath.Join(stateDir, file.Name())
371369
if err := removeLibwrapFromFile(filePath); err != nil {
372-
klog.Warningf("Error proccessing stunnel file %s: %v", filePath, err)
370+
klog.Warningf("Error processing stunnel file %s: %v", filePath, err)
373371
}
374372
}
375373
}

pkg/driver/efs_watch_dog_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ limitations under the License.
1414
package driver
1515

1616
import (
17-
"io/ioutil"
1817
"os"
1918
"path/filepath"
2019
"strings"
@@ -151,7 +150,7 @@ func TestExecWatchdog(t *testing.T) {
151150
}
152151

153152
func createTempDir(t *testing.T) string {
154-
name, err := ioutil.TempDir("", "")
153+
name, err := os.MkdirTemp("", "")
155154
checkError(t, err)
156155
return name
157156
}
@@ -259,7 +258,7 @@ func TestSetupWithAdditionalDirectoryInStaticFilesDirectory(t *testing.T) {
259258
staticFileDirName := createTempDir(t)
260259
defer os.RemoveAll(staticFileDirName)
261260

262-
_, err := ioutil.TempDir(staticFileDirName, "")
261+
_, err := os.MkdirTemp(staticFileDirName, "")
263262
checkError(t, err)
264263

265264
w := newExecWatchdog(configDirName, staticFileDirName, "sleep", "300").(*execWatchdog)
@@ -270,7 +269,7 @@ func TestSetupWithAdditionalDirectoryInStaticFilesDirectory(t *testing.T) {
270269
}
271270

272271
func TestRemoveLibwrapOption(t *testing.T) {
273-
tempDir, err := ioutil.TempDir("", "test-stunnel-configs")
272+
tempDir, err := os.MkdirTemp("", "test-stunnel-configs")
274273
if err != nil {
275274
t.Fatalf("Failed to create temp dir: %v", err)
276275
}
@@ -285,7 +284,7 @@ connect = fs-123.efs.us-west-2.amazonaws.com:2049
285284
libwrap = no
286285
`)
287286
testFilePath := filepath.Join(tempDir, "stunnel-config.test")
288-
if err := ioutil.WriteFile(testFilePath, testConfig, 0644); err != nil {
287+
if err := os.WriteFile(testFilePath, testConfig, 0644); err != nil {
289288
t.Fatalf("Failed to write test config: %v", err)
290289
}
291290

@@ -295,7 +294,7 @@ libwrap = no
295294
t.Fatalf("removeLibwrapOption failed: %v", err)
296295
}
297296

298-
content, err := ioutil.ReadFile(testFilePath)
297+
content, err := os.ReadFile(testFilePath)
299298
if err != nil {
300299
t.Fatalf("Failed to read updated config: %v", err)
301300
}
@@ -306,7 +305,7 @@ libwrap = no
306305
}
307306

308307
func verifyFileContent(t *testing.T, fileName string, expectedFileContent string) {
309-
fileContent, err := ioutil.ReadFile(fileName)
308+
fileContent, err := os.ReadFile(fileName)
310309
if err != nil {
311310
t.Fatalf("Failed to read file %v, %v", fileName, err)
312311
}
@@ -317,7 +316,7 @@ func verifyFileContent(t *testing.T, fileName string, expectedFileContent string
317316
}
318317

319318
func verifyConfigFile(t *testing.T, configFilePath string) {
320-
configFileContent, err := ioutil.ReadFile(configFilePath)
319+
configFileContent, err := os.ReadFile(configFilePath)
321320
checkError(t, err)
322321
actualConfig := string(configFileContent)
323322
if actualConfig != expectedEfsUtilsConfig {

pkg/driver/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func removeNotReadyTaint(k8sClient cloud.KubernetesAPIClient) error {
526526
return nil
527527
}
528528

529-
// remove taint may failed, this keep retring until succeed, make sure the taint will eventually being removed
529+
// remove taint may fail, this keeps retrying until it succeeds, make sure the taint will eventually be removed
530530
func tryRemoveNotReadyTaintUntilSucceed(interval time.Duration, removeFn func() error) {
531531
for {
532532
err := removeFn()

pkg/driver/reaper.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package driver
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"os"
2322
"os/signal"
2423
"strings"
@@ -88,7 +87,7 @@ func waitIfZombieStunnel(p ps.Process) bool {
8887
if !strings.Contains(p.Executable(), "stunnel") && !strings.Contains(p.Executable(), "efs-proxy") {
8988
return false
9089
}
91-
data, err := ioutil.ReadFile(fmt.Sprintf("/proc/%v/status", p.Pid()))
90+
data, err := os.ReadFile(fmt.Sprintf("/proc/%v/status", p.Pid()))
9291
if err != nil {
9392
klog.Warningf("reaper: failed to read process %v's status: %v", p, err)
9493
return false

0 commit comments

Comments
 (0)