- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: reinitialize agents when a prebuilt workspace is claimed#17475
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
c09c9b9476fe718c8bca67ce4eea52ac64e362db7cdcc7379ff66b3fefff5d9cebd5db26791389feebefb117b5ca22b4149bbd2c758042017e8dcee725f97ba9b156721ee970e54d7e727998581d93003763fc120f879c761784c9604eb27bf4d2cf38b4f0d20df5384bb3b6883972db146b1585eb16cd730d803150adc0b4ecf103fa3edf7e45919a63250872125ecb65eea7e1339f3c1a8ba65363dcc7ad9b6d394571d890747bb3870dbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
…d agent reinitializes
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -261,17 +261,6 @@ func (e *executor) plan(ctx, killCtx context.Context, env, vars []string, logr l | ||
| e.mut.Lock() | ||
| defer e.mut.Unlock() | ||
| planfilePath := getPlanFilePath(e.workdir) | ||
| args := []string{ | ||
| "plan", | ||
| @@ -341,6 +330,68 @@ func onlyDataResources(sm tfjson.StateModule) tfjson.StateModule { | ||
| return filtered | ||
| } | ||
| func (e *executor) logResourceReplacements(ctx context.Context, plan *tfjson.Plan) { | ||
SasSwart marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if plan == nil { | ||
| return | ||
| } | ||
| if len(plan.ResourceChanges) == 0 { | ||
| return | ||
| } | ||
| var ( | ||
| count int | ||
| replacements = make(map[string][]string, len(plan.ResourceChanges)) | ||
| ) | ||
| for _, ch := range plan.ResourceChanges { | ||
| // No change, no problem! | ||
| if ch.Change == nil { | ||
| continue | ||
| } | ||
| // No-op change, no problem! | ||
| if ch.Change.Actions.NoOp() { | ||
| continue | ||
| } | ||
| // No replacements, no problem! | ||
| if len(ch.Change.ReplacePaths) == 0 { | ||
| continue | ||
| } | ||
| // Replacing our resources, no problem! | ||
| if strings.Index(ch.Type, "coder_") == 0 { | ||
| continue | ||
| } | ||
| for _, p := range ch.Change.ReplacePaths { | ||
| var path string | ||
| switch p := p.(type) { | ||
| case []interface{}: | ||
| segs := p | ||
| list := make([]string, 0, len(segs)) | ||
| for _, s := range segs { | ||
| list = append(list, fmt.Sprintf("%v", s)) | ||
| } | ||
| path = strings.Join(list, ".") | ||
| default: | ||
| path = fmt.Sprintf("%v", p) | ||
| } | ||
| replacements[ch.Address] = append(replacements[ch.Address], path) | ||
SasSwart marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| count++ | ||
| } | ||
| if count > 0 { | ||
| e.server.logger.Warn(ctx, "plan introduces resource changes", slog.F("count", count)) | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| for n, p := range replacements { | ||
| e.server.logger.Warn(ctx, "resource will be replaced!", slog.F("name", n), slog.F("replacement_paths", strings.Join(p, ","))) | ||
SasSwart marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| } | ||
| } | ||
| // planResources must only be called while the lock is held. | ||
| func (e *executor) planResources(ctx, killCtx context.Context, planfilePath string) (*State, json.RawMessage, error) { | ||
| ctx, span := e.server.startTrace(ctx, tracing.FuncName()) | ||
| @@ -351,6 +402,8 @@ func (e *executor) planResources(ctx, killCtx context.Context, planfilePath stri | ||
| return nil, nil, xerrors.Errorf("show terraform plan file: %w", err) | ||
| } | ||
| e.logResourceReplacements(ctx, plan) | ||
SasSwart marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| rawGraph, err := e.graph(ctx, killCtx) | ||
| if err != nil { | ||
| return nil, nil, xerrors.Errorf("graph: %w", err) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -272,21 +272,16 @@ func provisionEnv( | ||
| ) | ||
| if metadata.GetIsPrebuild() { | ||
| env = append(env, provider.IsPrebuildEnvironmentVariable()+"=true") | ||
| } | ||
| tokens := metadata.GetRunningAgentAuthTokens() | ||
| if len(tokens) == 1 { | ||
| env = append(env, provider.RunningAgentTokenEnvironmentVariable("")+"="+tokens[0].Token) | ||
| } else { | ||
| for _, t := range tokens { | ||
SasSwart marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| // If there are multiple agents, provide all the tokens to terraform so that it can | ||
| // choose the correct one for each agent ID. | ||
| env = append(env, provider.RunningAgentTokenEnvironmentVariable(t.AgentId)+"="+t.Token) | ||
| } | ||
| } | ||
| for key, value := range provisionersdk.AgentScriptEnv() { | ||
| env = append(env, key+"="+value) | ||