diff options
author | Rajamohan Raj <rajamohan.raj@intel.com> | 2020-09-14 19:47:54 +0000 |
---|---|---|
committer | Ritu Sood <ritu.sood@intel.com> | 2020-09-24 19:03:49 +0000 |
commit | 564929b805c014f5e7ea16b5839ebb621b8c8a57 (patch) | |
tree | 100ca9e65a4e0385ee6d1d13cebc43e25625a084 /src/orchestrator/pkg | |
parent | f1a368f93708ee0a27f0740e353408ab0f19e147 (diff) |
Cleanup tmp resources after instantiation
In this patch,we clean up the tmp files
and directories generated during the
process of instantiation.
They include the tmp dirs with
prefix : /tmp/helm-tmpl and /tmp/k8s-ext
Issue-ID: MULTICLOUD-1206
Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com>
Change-Id: I02d11bb2f8d920e35aae7343f041a53b1cd3f057
Diffstat (limited to 'src/orchestrator/pkg')
-rw-r--r-- | src/orchestrator/pkg/module/instantiation.go | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/orchestrator/pkg/module/instantiation.go b/src/orchestrator/pkg/module/instantiation.go index de723242..0ae76006 100644 --- a/src/orchestrator/pkg/module/instantiation.go +++ b/src/orchestrator/pkg/module/instantiation.go @@ -20,6 +20,8 @@ import ( "encoding/base64" "encoding/json" "fmt" + "os" + "strings" "time" gpic "github.com/onap/multicloud-k8s/src/orchestrator/pkg/gpic" @@ -97,10 +99,12 @@ func NewInstantiationClient() *InstantiationClient { func (c InstantiationClient) Approve(p string, ca string, v string, di string) error { s, err := NewDeploymentIntentGroupClient().GetDeploymentIntentGroupState(di, p, ca, v) if err != nil { + log.Info("DeploymentIntentGroup has no state info ", log.Fields{"DeploymentIntentGroup: ":di}) return pkgerrors.Wrap(err, "DeploymentIntentGroup has no state info: "+di) } stateVal, err := state.GetCurrentStateFromStateInfo(s) if err != nil { + log.Info("Error getting current state from DeploymentIntentGroup stateInfo", log.Fields{"DeploymentIntentGroup ":di}) return pkgerrors.Errorf("Error getting current state from DeploymentIntentGroup stateInfo: " + di) } switch stateVal { @@ -218,6 +222,30 @@ func GetSortedTemplateForApp(appName, p, ca, v, rName, cp string, overrideValues return sortedTemplates, err } +func calculateDirPath(fp string) string { + sa := strings.Split(fp, "/") + return "/" + sa[1] + "/" + sa[2] + "/" +} + +func cleanTmpfiles(sortedTemplates []helm.KubernetesResourceTemplate) error { + dp := calculateDirPath(sortedTemplates[0].FilePath) + for _, st := range sortedTemplates{ + log.Info("Clean up ::", log.Fields{"file: ": st.FilePath}) + err := os.Remove(st.FilePath) + if err != nil { + log.Error("Error while deleting file", log.Fields{"file: ":st.FilePath}) + return err + } + } + err := os.RemoveAll(dp) + if err != nil { + log.Error("Error while deleting dir", log.Fields{"Dir: ":dp}) + return err + } + log.Info("Clean up temp-dir::", log.Fields{"Dir: ": dp}) + return nil +} + /* Instantiate methods takes in projectName, compositeAppName, compositeAppVersion, DeploymentIntentName. This method is responsible for template resolution, intent @@ -296,6 +324,7 @@ func (c InstantiationClient) Instantiate(p string, ca string, v string, di strin if err != nil { deleteAppContext(context) + log.Error("Unable to get the sorted templates for app", log.Fields{}) return pkgerrors.Wrap(err, "Unable to get the sorted templates for app") } @@ -307,6 +336,8 @@ func (c InstantiationClient) Instantiate(p string, ca string, v string, di strin return pkgerrors.Wrapf(err, "Unable to get the resources for app :: %s", eachApp.Metadata.Name) } + defer cleanTmpfiles(sortedTemplates) + specData, err := NewAppIntentClient().GetAllIntentsByApp(eachApp.Metadata.Name, p, ca, v, gIntent) if err != nil { deleteAppContext(context) @@ -338,6 +369,7 @@ func (c InstantiationClient) Instantiate(p string, ca string, v string, di strin deleteAppContext(context) return pkgerrors.Wrap(err, "Error while verifying resources in app: ") } + } jappOrderInstr, err := json.Marshal(appOrderInstr) if err != nil { @@ -482,7 +514,7 @@ func (c InstantiationClient) Terminate(p string, ca string, v string, di string) } if stateVal != state.StateEnum.Instantiated { - return pkgerrors.Errorf("DeploymentIntentGroup is not instantiated" + di) + return pkgerrors.Errorf("DeploymentIntentGroup is not instantiated :" + di) } currentCtxId := state.GetLastContextIdFromStateInfo(s) |