Skip to content

Commit

Permalink
fix: remove external transformer temp directories on interrupt (#1019)
Browse files Browse the repository at this point in the history
Signed-off-by: Mehant Kammakomati <[email protected]>
  • Loading branch information
kmehant authored Apr 13, 2023
1 parent dea5d6e commit 61b8944
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 12 additions & 0 deletions lib/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/konveyor/move2kube/common"
"github.com/konveyor/move2kube/qaengine"
"github.com/konveyor/move2kube/transformer"
"github.com/konveyor/move2kube/transformer/external"
plantypes "github.com/konveyor/move2kube/types/plan"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -116,4 +117,15 @@ func Destroy() {
if err != nil {
logrus.Debug("failed to delete temp directory. Error : ", err)
}

err = os.RemoveAll(external.DetectContainerOutputDir)
if err != nil {
logrus.Debug("failed to delete temp directory. Error : ", err)
}

err = os.RemoveAll(external.TransformContainerOutputDir)
if err != nil {
logrus.Debug("failed to delete temp directory. Error : ", err)
}

}
14 changes: 8 additions & 6 deletions transformer/external/executabletransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ type ExecutableYamlConfig struct {
}

var (
detectContainerOutputDir = "/var/tmp/m2k_detect_output"
transformContainerOutputDir = "/var/tmp/m2k_transform_output"
// DetectContainerOutputDir is the directory where external transformer detect output is stored
DetectContainerOutputDir = "/var/tmp/m2k_detect_output"
// TransformContainerOutputDir is the directory where external transformer transform output is stored
TransformContainerOutputDir = "/var/tmp/m2k_transform_output"
)

const (
Expand Down Expand Up @@ -89,8 +91,8 @@ func (t *Executable) Init(tc transformertypes.Transformer, env *environment.Envi
logrus.Infof("Starting transformer that requires QA without QA.")
}
}
detectContainerOutputDir = filepath.Join(detectContainerOutputDir, uniuri.NewLen(5))
transformContainerOutputDir = filepath.Join(transformContainerOutputDir, uniuri.NewLen(5))
DetectContainerOutputDir = filepath.Join(DetectContainerOutputDir, uniuri.NewLen(5))
TransformContainerOutputDir = filepath.Join(TransformContainerOutputDir, uniuri.NewLen(5))
env.EnvInfo.EnvPlatformConfig = environmenttypes.EnvPlatformConfig{
Container: t.ExecConfig.Container,
Platforms: t.ExecConfig.Platforms,
Expand All @@ -117,7 +119,7 @@ func (t *Executable) DirectoryDetect(dir string) (services map[string][]transfor
return nil, fmt.Errorf("failed to copy the detect input path to container. Error: %w", err)
}
containerDetectInputPath := filepath.Join(containerInputDir, detectInputFile)
containerDetectOutputPath := filepath.Join(detectContainerOutputDir, detectOutputFile)
containerDetectOutputPath := filepath.Join(DetectContainerOutputDir, detectOutputFile)
if env, exists := common.LookupEnv(detectOutputPathEnvKey, t.ExecConfig.EnvList); exists {
containerDetectOutputPath = env.Value
}
Expand Down Expand Up @@ -162,7 +164,7 @@ func (t *Executable) Transform(newArtifacts []transformertypes.Artifact, already
}

transformInputPath := filepath.Join(containerInputDir, transformInputFile)
transformOutputPath := filepath.Join(transformContainerOutputDir, transformOutputFile)
transformOutputPath := filepath.Join(TransformContainerOutputDir, transformOutputFile)
if env, exists := common.LookupEnv(transformOutputPathEnvKey, t.ExecConfig.EnvList); exists {
transformOutputPath = env.Value
}
Expand Down

0 comments on commit 61b8944

Please sign in to comment.