-
Notifications
You must be signed in to change notification settings - Fork 15
chore: migrate deployment variable values to db #817
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,3 +65,57 @@ func ToVariableUpsertParams(e *oapi.DeploymentVariable) (db.UpsertDeploymentVari | |
| DefaultValue: defaultValue, | ||
| }, nil | ||
| } | ||
|
|
||
| func ValueToOapi(row db.DeploymentVariableValue) *oapi.DeploymentVariableValue { | ||
| var resourceSelector *oapi.Selector | ||
| if row.ResourceSelector.Valid && row.ResourceSelector.String != "" { | ||
| sel := &oapi.Selector{} | ||
| celJSON, _ := json.Marshal(oapi.CelSelector{Cel: row.ResourceSelector.String}) | ||
| _ = sel.UnmarshalJSON(celJSON) | ||
| resourceSelector = sel | ||
| } | ||
|
|
||
| value := oapi.Value{} | ||
| _ = value.UnmarshalJSON(row.Value) | ||
|
|
||
| return &oapi.DeploymentVariableValue{ | ||
| Id: row.ID.String(), | ||
| DeploymentVariableId: row.DeploymentVariableID.String(), | ||
| Value: value, | ||
| ResourceSelector: resourceSelector, | ||
| Priority: row.Priority, | ||
| } | ||
| } | ||
|
|
||
| func ToValueUpsertParams(e *oapi.DeploymentVariableValue) (db.UpsertDeploymentVariableValueParams, error) { | ||
| id, err := uuid.Parse(e.Id) | ||
| if err != nil { | ||
| return db.UpsertDeploymentVariableValueParams{}, fmt.Errorf("parse id: %w", err) | ||
| } | ||
|
|
||
| dvid, err := uuid.Parse(e.DeploymentVariableId) | ||
| if err != nil { | ||
| return db.UpsertDeploymentVariableValueParams{}, fmt.Errorf("parse deployment_variable_id: %w", err) | ||
| } | ||
|
|
||
| var resourceSelector pgtype.Text | ||
| if e.ResourceSelector != nil { | ||
| cel, err := e.ResourceSelector.AsCelSelector() | ||
| if err == nil && cel.Cel != "" { | ||
| resourceSelector = pgtype.Text{String: cel.Cel, Valid: true} | ||
| } | ||
| } | ||
|
Comment on lines
+101
to
+107
Contributor
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify selector union behavior and mapper error handling paths.
# 1) Inspect Selector union helpers in generated OAPI to confirm AsCelSelector failure modes.
echo "=== OAPI Selector union and AsCelSelector ==="
rg -n -C3 'type Selector|AsCelSelector\(|UnmarshalJSON\(' apps/workspace-engine/pkg/oapi/oapi.gen.go | head -100
# 2) Inspect current mapper handling around AsCelSelector in this file.
echo -e "\n=== Mapper AsCelSelector handling ==="
rg -n -C4 'ToValueUpsertParams|AsCelSelector|resourceSelector' apps/workspace-engine/pkg/workspace/store/repository/db/deploymentvariables/mapper.go
# 3) Check where deployment variable values are built/validated before persistence.
echo -e "\n=== Deployment variable validation and building ==="
rg -n -C3 'DeploymentVariableValue|ResourceSelector' apps/workspace-engine/pkg/workspace/store/repository/db/deploymentvariables/mapper.go | head -80Repository: ctrlplanedev/ctrlplane Length of output: 5765 🏁 Script executed: #!/bin/bash
# Check callers of ToValueUpsertParams to understand usage context
rg -n 'ToValueUpsertParams' apps/workspace-engine/pkg --type go -A 3 -B 1Repository: ctrlplanedev/ctrlplane Length of output: 1382 Handle On lines 103–107, Proposed fix var resourceSelector pgtype.Text
if e.ResourceSelector != nil {
cel, err := e.ResourceSelector.AsCelSelector()
- if err == nil && cel.Cel != "" {
- resourceSelector = pgtype.Text{String: cel.Cel, Valid: true}
- }
+ if err != nil {
+ return db.UpsertDeploymentVariableValueParams{}, fmt.Errorf("parse resource_selector: %w", err)
+ }
+ if cel.Cel != "" {
+ resourceSelector = pgtype.Text{String: cel.Cel, Valid: true}
+ }
}🤖 Prompt for AI Agents |
||
|
|
||
| valueBytes, err := e.Value.MarshalJSON() | ||
| if err != nil { | ||
| return db.UpsertDeploymentVariableValueParams{}, fmt.Errorf("marshal value: %w", err) | ||
| } | ||
|
|
||
| return db.UpsertDeploymentVariableValueParams{ | ||
| ID: id, | ||
| DeploymentVariableID: dvid, | ||
| Value: valueBytes, | ||
| ResourceSelector: resourceSelector, | ||
| Priority: e.Priority, | ||
| }, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t silently swallow repository errors in
Values.Returning an empty map on failure masks data-access issues and can lead to incorrect variable resolution behavior without any signal.
🔧 Suggested fix
func (d *DeploymentVariables) Values(variableId string) map[string]*oapi.DeploymentVariableValue { dvvs, err := d.store.DeploymentVariableValues.repo.GetByVariableID(variableId) if err != nil { + log.Error("Failed to list deployment variable values by variable ID", "variableId", variableId, "error", err) return make(map[string]*oapi.DeploymentVariableValue) }🤖 Prompt for AI Agents