**What changed** Dynamic parameter rendering now evaluates only the coder parameter blocks and what they reference. Other root-module resources are skipped. Parameter, preset, and tag values are unchanged; optimizing rendering on large templates. **How to revert** Set `CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION=true` (or `--dynamic-parameters-full-evaluation`) on `coder server` to restore full evaluation. The flag is hidden and needs no restart of workspaces. If you need it, please [open an issue](https://github.com/coder/coder/issues/new) with the template so we can fix the root cause. **Troubleshooting** Symptoms would be a parameter default, option list, preset value, or workspace tag that shows as unknown or empty after upgrading, when it was populated before. Confirm by setting the flag above; if the value comes back, report it. Templates written in `.tf.json` are not affected (they always use full evaluation). **Why** Rendering re-ran the entire template graph on every parameter change in the workspace form, which dominated latency on large templates. Resources a workspace would create cannot feed a parameter, so evaluating them is wasted work. The optimization lives in coder/preview#226 (coder/trivy#74); this PR adds the deployment-level escape hatch. --- - `CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION` / `--dynamic-parameters-full-evaluation` (hidden, default `false`) on `DeploymentValues`. - `dynamicparameters.PreviewOptions(dv)` maps it to `preview.OptionFullEvaluation()`; `dynamicparameters.WithPreviewOptions` threads it through the loader to `preview.Preview`. - Wired at the three render paths that hold deployment values: the template version tags extractor, the dynamic parameters websocket, and `wsbuilder` builds created from `coderd` (which call `.DeploymentValues(...)`). Not covered: the autobuild lifecycle executor and the enterprise prebuilds reconciler construct `wsbuilder` without deployment values, so builds started from those paths use preview's default regardless of the flag. Those only re-render for builds, not the keystroke websocket path the optimization targets. Prepared with Coder Agents assistance.
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package dynamicparameters_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/coderd/dynamicparameters"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
func TestProvisionerVersionSupportsDynamicParameters(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for v, dyn := range map[string]bool{
|
|
"": false,
|
|
"na": false,
|
|
"0.0": false,
|
|
"0.10": false,
|
|
"1.4": false,
|
|
"1.5": false,
|
|
"1.6": true,
|
|
"1.7": true,
|
|
"1.8": true,
|
|
"2.0": true,
|
|
"2.17": true,
|
|
"4.0": true,
|
|
} {
|
|
t.Run(v, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
does := dynamicparameters.ProvisionerVersionSupportsDynamicParameters(v)
|
|
require.Equal(t, dyn, does)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPreviewOptions(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("NilConfig", func(t *testing.T) {
|
|
t.Parallel()
|
|
require.Empty(t, dynamicparameters.PreviewOptions(nil))
|
|
})
|
|
|
|
t.Run("Default", func(t *testing.T) {
|
|
t.Parallel()
|
|
dv := &codersdk.DeploymentValues{}
|
|
require.Empty(t, dynamicparameters.PreviewOptions(dv))
|
|
})
|
|
|
|
t.Run("FullEvaluation", func(t *testing.T) {
|
|
t.Parallel()
|
|
dv := &codersdk.DeploymentValues{}
|
|
require.NoError(t, dv.DynamicParametersFullEvaluation.Set("true"))
|
|
require.Len(t, dynamicparameters.PreviewOptions(dv), 1)
|
|
})
|
|
}
|