Skip to content

Commit 852e871

Browse files
authored
fix: empty tmp dir instead of removing it (#2203)
* fix: empty tmp dir instead of removing it The tmp directory is used for a number of things including when editig k8s resources using kubectl edit. Removing it after running commands will lead to failures in certain commands. Signed-off-by: Evans Mungai <evans@replicated.com> * Better error message when reading tmp dir Signed-off-by: Evans Mungai <evans@replicated.com> * Use helpers.RemoveAll to empty the tmp dir Signed-off-by: Evans Mungai <evans@replicated.com> * Remove unnecessary test file Signed-off-by: Evans Mungai <evans@replicated.com> --------- Signed-off-by: Evans Mungai <evans@replicated.com>
1 parent 3254941 commit 852e871

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/runtimeconfig/runtimeconfig.go

Lines changed: 8 additions & 1 deletion
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,7 +28,13 @@ func Get() *ecv1beta1.RuntimeConfigSpec {
2728
}
2829

2930
func Cleanup() {
30-
os.RemoveAll(EmbeddedClusterTmpSubDir())
31+
tmpDir := EmbeddedClusterTmpSubDir()
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)
37+
}
3138
}
3239

3340
// EmbeddedClusterHomeDirectory returns the parent directory. Inside this parent directory we

0 commit comments

Comments
 (0)