- Notifications
You must be signed in to change notification settings - Fork907
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 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 fromall commits
d4d52e9
f6b6485
2b03908
266b1e0
10fe129
0c648fb
b90650d
671ef69
07fc321
93b0974
8100193
1ce5e7b
1e4c183
cfe2120
2cd42e3
0944436
File 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
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,7 +13,9 @@ import ( | ||
"github.com/hashicorp/hcl/v2" | ||
"github.com/hashicorp/hcl/v2/hclsyntax" | ||
"github.com/coder/coder/v2/apiversion" | ||
"github.com/coder/coder/v2/coderd/rbac/policy" | ||
"github.com/coder/coder/v2/coderd/util/ptr" | ||
"github.com/coder/coder/v2/provisioner/terraform/tfparse" | ||
"github.com/coder/coder/v2/provisionersdk" | ||
sdkproto "github.com/coder/coder/v2/provisionersdk/proto" | ||
@@ -51,9 +53,11 @@ type Builder struct { | ||
state stateTarget | ||
logLevel string | ||
deploymentValues *codersdk.DeploymentValues | ||
experiments codersdk.Experiments | ||
richParameterValues []codersdk.WorkspaceBuildParameter | ||
// dynamicParametersEnabled is non-nil if set externally | ||
dynamicParametersEnabled *bool | ||
initiator uuid.UUID | ||
reason database.BuildReason | ||
templateVersionPresetID uuid.UUID | ||
@@ -66,6 +70,7 @@ type Builder struct { | ||
template *database.Template | ||
templateVersion *database.TemplateVersion | ||
templateVersionJob *database.ProvisionerJob | ||
terraformValues *database.TemplateVersionTerraformValue | ||
templateVersionParameters *[]database.TemplateVersionParameter | ||
templateVersionVariables *[]database.TemplateVersionVariable | ||
templateVersionWorkspaceTags *[]database.TemplateVersionWorkspaceTag | ||
@@ -155,6 +160,14 @@ func (b Builder) DeploymentValues(dv *codersdk.DeploymentValues) Builder { | ||
return b | ||
} | ||
func (b Builder) Experiments(exp codersdk.Experiments) Builder { | ||
// nolint: revive | ||
cpy := make(codersdk.Experiments, len(exp)) | ||
copy(cpy, exp) | ||
b.experiments = cpy | ||
return b | ||
} | ||
func (b Builder) Initiator(u uuid.UUID) Builder { | ||
// nolint: revive | ||
b.initiator = u | ||
@@ -187,8 +200,9 @@ func (b Builder) MarkPrebuiltWorkspaceClaim() Builder { | ||
return b | ||
} | ||
func (b Builder) DynamicParameters(using bool) Builder { | ||
// nolint: revive | ||
b.dynamicParametersEnabled = ptr.Ref(using) | ||
return b | ||
} | ||
@@ -516,6 +530,22 @@ func (b *Builder) getTemplateVersionID() (uuid.UUID, error) { | ||
return bld.TemplateVersionID, nil | ||
} | ||
func (b *Builder) getTemplateTerraformValues() (*database.TemplateVersionTerraformValue, error) { | ||
if b.terraformValues != nil { | ||
return b.terraformValues, nil | ||
} | ||
v, err := b.getTemplateVersion() | ||
if err != nil { | ||
return nil, xerrors.Errorf("get template version so we can get terraform values: %w", err) | ||
} | ||
vals, err := b.store.GetTemplateVersionTerraformValues(b.ctx, v.ID) | ||
if err != nil { | ||
return nil, xerrors.Errorf("get template version terraform values %s: %w", v.JobID, err) | ||
} | ||
b.terraformValues = &vals | ||
return b.terraformValues, err | ||
} | ||
func (b *Builder) getLastBuild() (*database.WorkspaceBuild, error) { | ||
if b.lastBuild != nil { | ||
return b.lastBuild, nil | ||
@@ -593,9 +623,10 @@ func (b *Builder) getParameters() (names, values []string, err error) { | ||
return nil, nil, BuildError{http.StatusBadRequest, "Unable to build workspace with unsupported parameters", err} | ||
} | ||
// Dynamic parameters skip all parameter validation. | ||
// Deleting a workspace also should skip parameter validation. | ||
// Pass the user's input as is. | ||
if b.usingDynamicParameters() { | ||
// TODO: The previous behavior was only to pass param values | ||
// for parameters that exist. Since dynamic params can have | ||
// conditional parameter existence, the static frame of reference | ||
@@ -989,3 +1020,36 @@ func (b *Builder) checkRunningBuild() error { | ||
} | ||
return nil | ||
} | ||
func (b *Builder) usingDynamicParameters() bool { | ||
if !b.experiments.Enabled(codersdk.ExperimentDynamicParameters) { | ||
// Experiment required | ||
return false | ||
} | ||
vals, err := b.getTemplateTerraformValues() | ||
if err != nil { | ||
return false | ||
} | ||
if !ProvisionerVersionSupportsDynamicParameters(vals.ProvisionerdVersion) { | ||
return false | ||
} | ||
if b.dynamicParametersEnabled != nil { | ||
return *b.dynamicParametersEnabled | ||
} | ||
tpl, err := b.getTemplate() | ||
if err != nil { | ||
return false // Let another part of the code get this error | ||
} | ||
return !tpl.UseClassicParameterFlow | ||
} | ||
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 | ||
} | ||
Comment on lines +1050 to +1055 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: this feels like something that might want to be in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.