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

POD-1217 | Fix rebuilding workspace when project clone failed #1536

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmd/agent/workspace/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func prepareWorkspace(ctx context.Context, workspaceInfo *provider2.AgentWorkspa
}
}

if workspaceInfo.CLIOptions.Recreate && !workspaceInfo.CLIOptions.Reset {
if workspaceInfo.CLIOptions.Recreate && !workspaceInfo.CLIOptions.Reset && exists {
log.Info("Rebuiling without resetting a git based workspace, keeping old content folder")
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/agent/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ func CloneRepositoryForWorkspace(
gitInfo := git.NewGitInfo(source.GitRepository, source.GitBranch, source.GitCommit, source.GitPRReference, source.GitSubPath)
err := git.CloneRepositoryWithEnv(ctx, gitInfo, extraEnv, workspaceDir, helper, cloner, log)
if err != nil {
// cleanup workspace dir if clone failed, otherwise we won't try to clone again when rebuilding this workspace
if cleanupErr := cleanupWorkspaceDir(workspaceDir); cleanupErr != nil {
return fmt.Errorf("clone repository: %w, cleanup workspace: %w", err, cleanupErr)
}
return fmt.Errorf("clone repository: %w", err)
}

Expand Down Expand Up @@ -331,6 +335,10 @@ func getGitOptions(options provider2.CLIOptions) []git.Option {
return gitOpts
}

func cleanupWorkspaceDir(workspaceDir string) error {
return os.RemoveAll(workspaceDir)
}

func setupSSHKey(key string, agentPath string) ([]string, func(), error) {
keyFile, err := os.CreateTemp("", "")
if err != nil {
Expand Down
Loading