Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Add workspace agent lifecycle state reporting #5785

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 24 commits into from
Jan 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix git auth override order
  • Loading branch information
mafredri committed Jan 23, 2023
commit 903e850c02b94b6e01d98112bf281751a3d5b5a8
26 changes: 13 additions & 13 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ func (a *agent) run(ctx context.Context) error {

// The startup script should only execute on the first run!
if oldMetadata == nil {
a.setLifecycle(codersdk.WorkspaceAgentLifecycleStarting)

// Perform overrides early so that Git auth can work even if users
// connect to a workspace that is not yet ready. We don't run this
// concurrently with the startup script to avoid conflicts between
// them.
if metadata.GitAuthConfigs > 0 {
err := gitauth.OverrideVSCodeConfigs(a.filesystem)
if err != nil {
a.logger.Warn(ctx, "failed to override vscode git auth configs", slog.Error(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should the agent quit here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't, this could fail for a multitude of reasons, like a user setting chmod 0000 on a folder. The worst that can happen is a degraded user experience (git auth in vscode not working). Ultimately we might want to:

  • Continue executing startup script after this
  • Set lifecycle to start_error because this failed
  • Result (error message) must be visible in build/startup logs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worst that can happen is a degraded user experience (git auth in vscode not working).

Yes, that's the situation I was considering. What can user do in this case? Restart the workspace until it works?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the change was done before, failure here doesn't really matter either (btw). Restarting will most likely not help, unless it's a problem mounting FS or similar. They'll most likely need to resolve the issue in the workspace, then restart, or create a new one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I've only added a note. I'll revisit this behavior when I add startup log streaming 👍🏻.

}
}

scriptDone := make(chan error, 1)
scriptStart := time.Now()
go func() {
Expand All @@ -252,8 +265,6 @@ func (a *agent) run(ctx context.Context) error {
timeout = t.C
}

a.setLifecycle(codersdk.WorkspaceAgentLifecycleStarting)

var err error
select {
case err = <-scriptDone:
Expand All @@ -274,17 +285,6 @@ func (a *agent) run(ctx context.Context) error {
a.logger.Info(ctx, "startup script completed", slog.F("execution_time", execTime))
}

// Perform overrides after startup script has completed to ensure
// there is no conflict with the user's scripts. We also want to
// ensure this is done before the workspace is marked as ready.
// Note, this is done even in the even that startup script failed.
if metadata.GitAuthConfigs > 0 {
err := gitauth.OverrideVSCodeConfigs(a.filesystem)
if err != nil {
a.logger.Warn(ctx, "failed to override vscode git auth configs", slog.Error(err))
}
}

a.setLifecycle(lifecycleStatus)
}()
}
Expand Down