Skip to content

[ws-manager-mk2] Ensure content init can be restarted #17002

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

Merged
merged 1 commit into from
Mar 24, 2023
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
24 changes: 24 additions & 0 deletions components/ws-daemon/pkg/controller/workspace_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func (wso *WorkspaceOperations) InitWorkspaceContent(ctx context.Context, option
},
}

err = ensureCleanSlate(ws.Location)
if err != nil {
glog.Warnf("cannot ensure clean slate for workspace %s (this might break content init): %v", ws.InstanceID, err)
}

err = content.RunInitializer(ctx, ws.Location, options.Initializer, remoteContent, opts)
if err != nil {
glog.Infof("error running initializer %v", err)
Expand Down Expand Up @@ -274,6 +279,25 @@ func (wso *WorkspaceOperations) TakeSnapshot(ctx context.Context, workspaceID, s
return nil
}

func ensureCleanSlate(location string) error {
// do not remove the location itself but only
// the children
files, err := os.ReadDir(location)
if err != nil {
return err
}

for _, f := range files {
path := filepath.Join(location, f.Name())
err = os.RemoveAll(path)
if err != nil {
return err
}
}

return nil
}

func (wso *WorkspaceOperations) uploadWorkspaceLogs(ctx context.Context, opts DisposeOptions) (err error) {
// currently we're only uploading prebuild log files
logFiles, err := logs.ListPrebuildLogFiles(ctx, opts.WorkspaceLocation)
Expand Down