Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check the exit code #170

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions internal/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2330,17 +2330,30 @@ func (fs *FileSystem) runPlan(currentRunDir string, currentRunConfigPaths []stri
return err
}
defer db.Close()
err = db.Update(func(t *bolt.Tx) error {
err = db.Update(func(t *bolt.Tx) (errFinal error) {
logrus.Trace("planning finished. Update start")
defer logrus.Trace("planning finished. Update end")
// checks
logrus.Debug("planning finished. inside Update. just before checks start")
project, err := fs.readProject(t, workspaceId, projectId)
if err != nil {
logrus.Errorf("inside runPlan, failed to read the project after planning completed. Error: %q", err)
return err
errFinal = fmt.Errorf("inside runPlan, failed to read the project after planning completed. Error: %w", err)
return errFinal
}
// update state
defer func() {
logrus.Debug("planning finished. inside deferred Update. just before update start in defer")
logrus.Debugf("deferred Update project %+v", project)
if errFinal != nil {
logrus.Debugf("deferred Update project already an error: %q", errFinal)
return
}
if err := fs.updateProject(t, workspaceId, project); err != nil {
logrus.Debugf("deferred Update project error: %+v", err)
errFinal = fmt.Errorf("failed to update the project to unlock the plan generation. Error: %w", err)
}
logrus.Debug("planning finished. inside deferred Update near end")
}()
logrus.Debug("planning finished. inside Update. just before update start")
if strings.HasPrefix(currentRunSrcDir, "git+") {
project.Status[types.ProjectStatusRemoteInputSources] = true
Expand All @@ -2362,21 +2375,30 @@ func (fs *FileSystem) runPlan(currentRunDir string, currentRunConfigPaths []stri
logrus.Errorf("planning for project %s stopped because the context was closed. Error: %q", projectId, err)
}
}
if err := fs.updateProject(t, workspaceId, project); err != nil {
return fmt.Errorf("failed to update the project to unlock the plan generation. Error: %q", err)
}
// effects
logrus.Debug("planning finished. inside Update. just before effects start")
projInputsDir := filepath.Join(common.Config.DataDir, PROJECTS_DIR, projectId, INPUTS_DIR, EXPANDED_DIR)
dstPlanPath := filepath.Join(projInputsDir, M2K_PLAN_FILENAME)
srcPlanPath := filepath.Join(currentRunOutDir, M2K_PLAN_FILENAME)
if err := cmd.Wait(); err != nil {
project.Status[types.ProjectStatusPlan] = false
project.Status[types.ProjectStatusPlanError] = true
logrus.Errorf("failed to finish planning using move2kube. Error: %q", err)
return errFinal
}
if err := os.MkdirAll(projInputsDir, DEFAULT_DIRECTORY_PERMISSIONS); err != nil {
return fmt.Errorf("failed to create the project inputs expanded directory at path %s to copy the plan to. Error: %q", projInputsDir, err)
project.Status[types.ProjectStatusPlan] = false
project.Status[types.ProjectStatusPlanError] = true
logrus.Errorf("failed to create the project inputs expanded directory at path %s to copy the plan to. Error: %q", projInputsDir, err)
return errFinal
}
if err := CopyFile(dstPlanPath, srcPlanPath); err != nil {
return fmt.Errorf("failed to copy the plan file from %s to %s after planning finished. Error: %q", srcPlanPath, dstPlanPath, err)
project.Status[types.ProjectStatusPlan] = false
project.Status[types.ProjectStatusPlanError] = true
logrus.Errorf("failed to copy the plan file from %s to %s after planning finished. Error: %q", srcPlanPath, dstPlanPath, err)
return errFinal
}
return nil
return errFinal
})
if err != nil {
logrus.Errorf("failed to update the database after planning finished. Error: %q", err)
Expand Down
Loading