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

Skip to content

feat: allow new immutable parameters for existing workspaces #18579

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 2 commits into from
Jun 25, 2025

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jun 25, 2025

Closes #18578

This was a somewhat conscience choice to prevent new immutable parameters. In an ideal world, immutable parameters can only be set at creation time. The example to illustrate this is:

  1. A template exists that provisions workspaces to us-east1
  2. Workspace East-1 is created.
  3. Template is updated to include a regions parameter with the default us-west1.
  4. Workspace is updated, and now moved to us-west1. Volumes do not transfer, and this workspace is either broken, or wiped.

If we disallow new immutable parameters, then the fix would be to let regions be mutable. Push an update, update the the workspace, then make it immutable.

Since the workaround has no more protection than the original problem, it's probably best to just allow new immutable parameters. If at some point in the future we allow some first class flow to handling this case, we can change back this enforcement.

Notes

  • Added a mock for the renderer so I can test this with less setup.

Comment on lines +172 to +180
originalValue, ok := originalValues[parameter.Name]
// Immutable parameters should not be changed after the first build.
// They can match the original value though!
if parameter.Value.AsString() != originalValues[parameter.Name].Value {
// If the value matches the original value, that is fine.
//
// If the original value is not set, that means this is a new parameter. New
// immutable parameters are allowed. This is an opinionated choice to prevent
// workspaces failing to update or delete. Ideally we would block this, as
// immutable parameters should only be able to be set at creation time.
if ok && parameter.Value.AsString() != originalValue.Value {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the change. The rest is testing

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Would it be a lot of trouble to add a test to cover the scenario mentioned in the issue?

@Emyrk
Copy link
Member Author

Emyrk commented Jun 25, 2025

Would it be a lot of trouble to add a test to cover the scenario mentioned in the issue?

You mean a more e2e test? Like from coderd, template versions, etc?

The test I did write is pretty locally scoped to the parameter validation logic.

@dannykopping
Copy link
Contributor

Doesn't have to be e2e necessarily; coderd/workspaces_test.go would probably suffice.

  1. Create template version
  2. Create workspace
  3. Update version with immutable param
  4. Don't update workspace
  5. Try delete workspace
  6. Succeeds

@Emyrk Emyrk requested a review from dannykopping June 25, 2025 15:31
@Emyrk
Copy link
Member Author

Emyrk commented Jun 25, 2025

Doesn't have to be e2e necessarily; coderd/workspaces_test.go would probably suffice.

  1. Create template version
  2. Create workspace
  3. Update version with immutable param
  4. Don't update workspace
  5. Try delete workspace
  6. Succeeds

Added! aa2a809

Test ran on main failed with: (as expected and matches the issue)

    dynamicparameters_test.go:341: 
        	Error Trace:	/home/steven/go/src/github.com/coder/coder/enterprise/coderd/dynamicparameters_test.go:341
        	Error:      	Received unexpected error:
        	            	POST http://localhost:44413/api/v2/workspaces/6ea8dbda-9e21-4e9a-a388-189119dbdbf9/builds: unexpected status code 400: Unable to validate parameters
        	            		immutable: Immutable parameter changed; Parameter "immutable" is not mutable, so it can't be updated after creating a workspace.

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM!

@Emyrk Emyrk enabled auto-merge (squash) June 25, 2025 15:38
@Emyrk Emyrk merged commit e396b06 into main Jun 25, 2025
34 checks passed
@Emyrk Emyrk deleted the stevenmasley/immutable_param branch June 25, 2025 15:41
@github-actions github-actions bot locked and limited conversation to collaborators Jun 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: workspace deletion fails when template has new immutable parameters
2 participants