-
Notifications
You must be signed in to change notification settings - Fork 903
chore: keep previous workspace build parameters for dynamic params #18059
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
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
68fb748
chore: keep previous workspace build parameters for dynamic params
Emyrk bb234fd
test: include unit test to assert parameters
Emyrk 7d84b36
fmt
Emyrk 9299c14
overwrite parameter values
Emyrk 9215b23
add comment
Emyrk ea7c20f
linting
Emyrk 28d1416
better assertion in test
Emyrk c4ef39f
Merge remote-tracking branch 'origin/main' into stevenmasley/previous…
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
chore: keep previous workspace build parameters for dynamic params
- Loading branch information
commit 68fb74860f9f5747a81c5301f781f0bd147be38f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -623,6 +623,11 @@ func (b *Builder) getParameters() (names, values []string, err error) { | |
return nil, nil, BuildError{http.StatusBadRequest, "Unable to build workspace with unsupported parameters", err} | ||
} | ||
|
||
lastBuildParameterValues := db2sdk.WorkspaceBuildParameters(lastBuildParameters) | ||
resolver := codersdk.ParameterResolver{ | ||
Rich: lastBuildParameterValues, | ||
} | ||
|
||
// Dynamic parameters skip all parameter validation. | ||
// Deleting a workspace also should skip parameter validation. | ||
// Pass the user's input as is. | ||
|
@@ -632,19 +637,33 @@ func (b *Builder) getParameters() (names, values []string, err error) { | |
// conditional parameter existence, the static frame of reference | ||
// is not sufficient. So assume the user is correct, or pull in the | ||
// dynamic param code to find the actual parameters. | ||
latestValues := make(map[string]string) | ||
for _, latest := range b.richParameterValues { | ||
latestValues[latest.Name] = latest.Value | ||
} | ||
|
||
// Merge the inputs with values from the previous build. | ||
for _, last := range lastBuildParameterValues { | ||
// TODO: Ideally we use the resolver here and look at parameter | ||
// fields such as 'ephemeral'. This requires loading the terraform | ||
// files. For now, just send the previous inputs as is. | ||
if _, exists := latestValues[last.Name]; exists { | ||
continue | ||
} | ||
names = append(names, last.Name) | ||
values = append(values, last.Value) | ||
} | ||
|
||
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. I am skipping validation right now for dynamic params experimental. I have an issue to address this again later. |
||
for _, value := range b.richParameterValues { | ||
names = append(names, value.Name) | ||
values = append(values, value.Value) | ||
} | ||
|
||
b.parameterNames = &names | ||
b.parameterValues = &values | ||
return names, values, nil | ||
} | ||
|
||
resolver := codersdk.ParameterResolver{ | ||
Rich: db2sdk.WorkspaceBuildParameters(lastBuildParameters), | ||
} | ||
|
||
for _, templateVersionParameter := range templateVersionParameters { | ||
tvp, err := db2sdk.TemplateVersionParameter(templateVersionParameter) | ||
if err != nil { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.