Skip to content

Commit 181dce8

Browse files
committed
Use helpers.RemoveAll to empty the tmp dir
Signed-off-by: Evans Mungai <[email protected]>
1 parent 2096d98 commit 181dce8

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

pkg/runtimeconfig/runtimeconfig.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path/filepath"
77

88
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
9+
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
910
"github.com/sirupsen/logrus"
1011
"sigs.k8s.io/yaml"
1112
)
@@ -27,22 +28,12 @@ func Get() *ecv1beta1.RuntimeConfigSpec {
2728
}
2829

2930
func Cleanup() {
30-
emptyTmpDir()
31-
}
32-
33-
func emptyTmpDir() {
3431
tmpDir := EmbeddedClusterTmpSubDir()
35-
entries, err := os.ReadDir(tmpDir)
36-
if err != nil {
37-
logrus.Errorf("error reading %s tmp dir: %v", tmpDir, err)
38-
return
39-
}
40-
41-
for _, entry := range entries {
42-
path := filepath.Join(tmpDir, entry.Name())
43-
if err := os.RemoveAll(path); err != nil {
44-
logrus.Errorf("error removing item %s: %s", path, err)
45-
}
32+
// We should not delete the tmp dir, rather we should empty its contents leaving
33+
// it in place. This is because commands such as `kubectl edit <resource>`
34+
// will create files in the tmp dir
35+
if err := helpers.RemoveAll(tmpDir); err != nil {
36+
logrus.Errorf("error removing %s dir: %s", tmpDir, err)
4637
}
4738
}
4839

0 commit comments

Comments
 (0)