Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: run a terraform plan before creating workspaces with the given template parameters#1732

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

Merged
deansheather merged 11 commits intomainfromtemplate-version-plan
Jun 1, 2022

Conversation

deansheather
Copy link
Member

@deansheatherdeansheather commentedMay 25, 2022
edited
Loading

Adds a new provisioner job typetemplate_version_plan which is for running a plan against a template version with custom parameters, but without having to make a workspace first. This will be used incoder create so we can verify that the workspace creation will start successfully and not fail quickly due to bad parameter values (leaving an inconsolable workspace state).

Subtasks

  • Addtemplate_version_plan provisioner job type to database
  • AddPOST /templateversions/:template_version_id/plan endpoint and codersdk methods
  • Add endpoints to monitor template version plan logs and cancel early (talking to Kyle in Slack about what to do here to avoid duplication)
  • Add tests for template plan endpoint
  • Add provisionerd protobuf types forTemplateVersionPlan
  • Dispatchtemplate_version_plan provisioner jobs =>TemplateVersionPlan protobuf jobs
  • Add provisionerd job handling forTemplateVersionPlan jobs
  • Add tests for provisionerd job handling
  • Add template version plan tocoder create before creating the workspace
    • Add the plan
    • Wait for the plan
    • Handle logs and cancellation
    • Check for parameter validation errors and reprompt for parameters
  • Add tests forcoder create plan
  • Add workspace name to the plan for name validation checks

Future:

  • Detect parameter validation errors and reprompt users instead of making them run the command again
  • Integrate the plan endpoint into the frontend

Screenshots

Successful validation:
Code_4UyXd6vUMP

Unsuccessful validation/plan:
Code_TPxhFaf7Vv

Fixes#831

@deansheatherdeansheather self-assigned thisMay 25, 2022
@deansheatherdeansheather marked this pull request as ready for reviewMay 27, 2022 19:50
@deansheatherdeansheather requested a review froma teamMay 27, 2022 19:50
@deansheatherdeansheather requested a review froma team as acode ownerMay 27, 2022 20:45
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

I haven't tested this out myself, but it looks solid to me.

Comment on lines 173 to 174
// We use the workspace RBAC check since we don't want to allow plans if the
// user can't create workspaces.
Copy link
Member

Choose a reason for hiding this comment

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

Technically correct - the best kind of correct.

deansheather reacted with laugh emoji
Comment on lines 1 to 9
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT
-- EXISTS".

-- Delete all jobs that use the new enum value.
DELETE FROM
provisioner_jobs
WHERE
provisioner_job_type = 'template_version_plan'
;
Copy link
Member

Choose a reason for hiding this comment

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

⚠️ reminder: rename me⚠️

Comment on lines 1 to 2
ALTER TYPE provisioner_job_type
ADD VALUE IF NOT EXISTS 'template_version_plan';
Copy link
Member

Choose a reason for hiding this comment

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

⚠️ reminder: rename me⚠️

Comment on lines +197 to +198
// TODO (Dean): reprompt for parameter values if we deem it to
// be a validation error
Copy link
Member

Choose a reason for hiding this comment

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

TODO: open an issue

kylecarbs and deansheather reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Opened two issues:

#1872 - for integrating with frontend
#1873 - for reprompting for values in CLI

johnstcn reacted with heart emoji
}
transition, err := convertWorkspaceTransition(workspaceBuild.Transition)
if err != nil {
return nil, failJob(fmt.Sprint("convert workspace transition: %w", err))
return nil, failJob(fmt.Sprintf("convert workspace transition: %s", err))
Copy link
Member

Choose a reason for hiding this comment

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

No wrapping? I guess this gets protobuffed in the end, right?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Can't wrap with Sprintf, and these just get condensed to strings sadly :(

kylecarbs reacted with thumbs up emoji
@deansheatherdeansheather changed the titlefeat: add new provisioner job type template_version_planfeat: run a terraform plan before creating workspaces with the given template parametersMay 27, 2022
@deansheatherdeansheather requested review froma team and removed request fora teamMay 28, 2022 10:21
Comment on lines 180 to 183
var req codersdk.CreateTemplateVersionPlanRequest
if !httpapi.Read(rw, r, &req) {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

As a user, I could spam this ~1000 times and take down a Coder deployment for the day. The same could be said for workspaces, but we have issues tracking quotas for those.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

OK so I'll just add details to those issues that whatever fix we do needs to apply to this endpoint too

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Could you link the issue? I can't seem to find it after searching "rate limit" and "quota"

Copy link
Member

Choose a reason for hiding this comment

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

Ahh my bad for being slow here.

Can we limit the parallelization here? This is a remarkably easy attack vector that we don't seem to have a solid plan to fix.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

That seems out of scope for this PR because we have the same issue with regular workspace builds and template imports which also needs to be fixed. It'd make sense to come up with a good solution that covers all of these job types

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

In that case, what's the mechanism we use to block multiple workspace builds so we can implement here

Copy link
Member

Choose a reason for hiding this comment

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

Multiple builds cannot occur for the same workspace in parallel because they are stateful.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Do we have any protection across multiple builds across multiple workspaces on the same user?

Copy link
Member

Choose a reason for hiding this comment

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

Nope, but it's less of a problem because that'd beextremely easy to detect malice via our current API. An admin could list workspaces to easily detect who's the malicious actor.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

That's fair, but I still think that a global solution should be applied to all jobs simultaneously. You said earlier there was a ticket about this, could you link it so I can add context to it? I will try to tackle it before community MVP

Comment on lines 257 to 261
var input templateVersionPlanJob
err = json.Unmarshal(job.Input, &input)
if err != nil {
return nil, failJob(fmt.Sprintf("unmarshal job input %q: %s", job.Input, err))
}
Copy link
Member

Choose a reason for hiding this comment

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

It scares me to add another job with such similar scope to the others, but I understand why.

It'd be helpful if you explained why we couldn't use theworkspace_build job to do similarly. I believe it'd just require not being attached to a literal workspace build, which seems like a reasonable change anyways.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We need to have a separate job for this because the job endpoints have different schemas and different endpoints to access the job details, not a unified/jobs endpoint. You've said in the past that you'd like to split these different job types apart more in the future (so they don't share DB tables for metadata etc.), so merging these two jobs together would be counterintuitive to that goal

Copy link
Member

Choose a reason for hiding this comment

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

The inputs are slightly different, but the outputs are the same, right?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Effectively, yes

Copy link
Member

Choose a reason for hiding this comment

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

It's probably worth opening a ticket considering merging those job types, or at least stating what the impl would look like to merge them. I'm always nervous about adding more job types.

return err
return xerrors.Errorf("begin workspace dry-run: %w", err)
}
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "Planning workspace...")
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I kept the language "Planning workspace" because I couldn't come up with something that made sense with the word "dry-run"....

"Dry-running workspace"

"Running workspace dry-run"

etc.

@deansheatherdeansheather merged commit6be8a37 intomainJun 1, 2022
@deansheatherdeansheather deleted the template-version-plan branchJune 1, 2022 14:44
kylecarbs pushed a commit that referenced this pull requestJun 10, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@zouncezouncezounce approved these changes

@kylecarbskylecarbsAwaiting requested review from kylecarbs

Assignees

@deansheatherdeansheather

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Workspaces can be created with invalid values, then cannot be deleted
4 participants
@deansheather@johnstcn@kylecarbs@zounce

[8]ページ先頭

©2009-2025 Movatter.jp