diff --git a/cmd/kubeadm/app/util/patches/patches.go b/cmd/kubeadm/app/util/patches/patches.go index 3b1ad23d0e3..fa0ca9fabd3 100644 --- a/cmd/kubeadm/app/util/patches/patches.go +++ b/cmd/kubeadm/app/util/patches/patches.go @@ -283,7 +283,11 @@ func getPatchSetsFromPath(targetPath string, knownTargets []string, output io.Wr goto return_path_error } if !info.IsDir() { - err = errors.New("not a directory") + err = &os.PathError{ + Op: "getPatchSetsFromPath", + Path: info.Name(), + Err: errors.New("not a directory"), + } goto return_path_error } diff --git a/cmd/kubeadm/app/util/patches/patches_test.go b/cmd/kubeadm/app/util/patches/patches_test.go index 7d2e8f18a67..eab7907d539 100644 --- a/cmd/kubeadm/app/util/patches/patches_test.go +++ b/cmd/kubeadm/app/util/patches/patches_test.go @@ -24,6 +24,7 @@ import ( "reflect" "testing" + "github.com/pkg/errors" "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" ) @@ -165,15 +166,16 @@ func TestCreatePatchSet(t *testing.T) { } func TestGetPatchSetsForPathMustBeDirectory(t *testing.T) { - tempFile, err := ioutil.TempFile("", "test-file") + tempFile, err := os.CreateTemp("", "test-file") if err != nil { t.Errorf("error creating temporary file: %v", err) } defer os.Remove(tempFile.Name()) _, _, _, err = getPatchSetsFromPath(tempFile.Name(), testKnownTargets, ioutil.Discard) - if err == nil { - t.Fatalf("expected error for non-directory path %q", tempFile.Name()) + var pathErr *os.PathError + if !errors.As(err, &pathErr) { + t.Fatalf("expected os.PathError for non-directory path %q, but got %v", tempFile.Name(), err) } }