Skip to content

chore: disable parameter validatation for dynamic params for all transitions #17926

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 16 commits into from
May 20, 2025

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented May 19, 2025

What this does

Dynamic params currently has relaxed parameter validation in coder/coder. This is because conditional parameters cannot be validated with the static parameters in the database.

We might want to tighten this up later based on the coder provider version in the terraform. As version >=2.4.0 all have the strict validation built into the provider. And the UI form relies on the preview engine for validation.

Unit test

A unit test of validation drift is present. Without this dynamic params option in wsbuilder, workspace transactions fail to validate, and will never succeed.

This puts the workspace in a locked position where you cannot change its state.

The error is:

unexpected status code 400: Unable to validate parameter "param"
Error: can't validate build parameter "param": value 5 is less than the minimum 10

This would also break updates, auto-starts, auto-stop, deletes, etc.

Future work

Before we exit experimental, we should revisit if parameter validation is critical in coder/coder (for provider versions >2.4.0).

Validation in coder/coder is for raising errors early, rather than waiting for the terraform logs. For any action without the ability to change params, this does not really provide much help, as there is no way to resolve the issue.

We can always hook up dynamic params to more endpoints, the cost is just a bit of memory loading in all the files.

#17942

Note

This currently only applies to deployments that enable the experiment. Historical versions enforce the previous validation always.

Templates can additionally be opt-in or opt-out of dynamic params. Meaning a deployment with the experiment could have some templates testing the new params, and some on the old.

Validation drift prevents builds from being submitted, such
as deleting
@Emyrk Emyrk changed the title chore: unit test to showcase param validation drift chore: param validation drift permanently locks workspace state May 19, 2025
@Emyrk Emyrk marked this pull request as draft May 19, 2025 22:30
@Emyrk Emyrk changed the title chore: param validation drift permanently locks workspace state chore: dynamic params validation on all workspace build transitions May 20, 2025
@Emyrk Emyrk changed the title chore: dynamic params validation on all workspace build transitions chore: disable parameter validatation for dynamic params on all workspace build transitions May 20, 2025
@Emyrk Emyrk changed the title chore: disable parameter validatation for dynamic params on all workspace build transitions chore: disable parameter validatation for dynamic params for all transitions May 20, 2025
Comment on lines 387 to 392
// Only defer to dynamic parameters if the experiment is enabled.
if api.Experiments.Enabled(codersdk.ExperimentDynamicParameters) &&
createBuild.EnableDynamicParameters != nil {
// Explicit opt-in
builder = builder.DynamicParameters(*createBuild.EnableDynamicParameters)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I provide the explicit opt in as a way to force through transitions such as DELETE if there an issue. It would be unfortunate to have to change a template wide setting to fix a single workspace if we get into a strange state.

Copy link
Member

Choose a reason for hiding this comment

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

Can we drop a WARN or something if the build requests dynamic parameters but the experiment is not enabled?

@Emyrk Emyrk requested a review from johnstcn May 20, 2025 03:49
@Emyrk Emyrk marked this pull request as ready for review May 20, 2025 03:49
Comment on lines 387 to 392
// Only defer to dynamic parameters if the experiment is enabled.
if api.Experiments.Enabled(codersdk.ExperimentDynamicParameters) &&
createBuild.EnableDynamicParameters != nil {
// Explicit opt-in
builder = builder.DynamicParameters(*createBuild.EnableDynamicParameters)
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we drop a WARN or something if the build requests dynamic parameters but the experiment is not enabled?

Comment on lines +1048 to +1053
func ProvisionerVersionSupportsDynamicParameters(version string) bool {
major, minor, err := apiversion.Parse(version)
// If the api version is not valid or less than 1.6, we need to use the static parameters
useStaticParams := err != nil || major < 1 || (major == 1 && minor < 6)
return !useStaticParams
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: this feels like something that might want to be in provisionersdk

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. Really tough to know where to place it. I'm going to keep it with wsbuilder right now, since it only affects workspace builds.

I think I'll create a new package for dynamic params more generally as more code is added to support the feature, and I can move it there.

@Emyrk Emyrk requested a review from johnstcn May 20, 2025 13:37
@Emyrk Emyrk merged commit e76d58f into main May 20, 2025
36 checks passed
@Emyrk Emyrk deleted the stevenmasley/deleting_workspace_params branch May 20, 2025 15:09
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 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.

2 participants