Skip to content

convert postgres_config steps to go#164

Merged
stevenolen merged 2 commits intomainfrom
convert-step-postgres-config
Mar 10, 2026
Merged

convert postgres_config steps to go#164
stevenolen merged 2 commits intomainfrom
convert-step-postgres-config

Conversation

@stevenolen
Copy link
Collaborator

Description

Refactors the aws control room & workload and azure workload postgres_config steps from python to go. This has been tested with a control room and 2 workloads, producing no diffs.

Category of change

  • Bug fix (non-breaking change which fixes an issue)
  • Version upgrade (upgrading the version of a service or product)
  • New feature (non-breaking change which adds functionality)
  • Build: a code change that affects the build system or external dependencies
  • Performance: a code change that improves performance
  • Refactor: a code change that neither fixes a bug nor adds a feature
  • Documentation: documentation changes
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have reviewed my own diff and added inline comments on lines I want reviewers to focus on or that I am uncertain about

)
switch s.DstTarget.CloudProvider() {
case types.AWS:
return s.runAWSInlineGo(ctx, creds, envVars)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there's likely a little dry missing here aws vs. azure, but it's probably not so important

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, not important.


// --- Azure ---

// azurePostgresParams holds the pre-fetched data needed by the Azure deploy function.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unclear on the necessity of this, but it looks like a reasonable choice to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's meh/whatever to me. Creating an options / value object to limit a giant function signature. A little easier to grok for the humans, inconsequential to the agents. 🤷

return runPulumi(ctx, stack, s.Options)
}

// --- Shared helpers ---
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this shared helper might belong elsewhere, but it feels pretty unique to this step to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

YAGNI. If it's not needed elsewhere yet, fine to leave in here and let the next person refactor when it needs to be used elsewhere.

componentType = "ptd:AWSControlRoomPostgresConfig"
}

// Helper to create alias pointing to old Python component parent URN.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we may want to figure out how to refactor this later to be very generic/work for all steps, since it's the real crux of how to convert these steps between languages without producing diffs/deltas

Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above IMO: YAGNI, make it generic/reusable once there's another need for it.

ctx.Export("grafana_db_name", grafanaDb.Name)
ctx.Export("grant_id", grant.ID())

// Extra databases (workload only, e.g. soleng for staging workloads)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

obviously, we shouldn't use this anymore. but i didn't want to have to clean up/migrate the existing databases prior to conversion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@stevenolen stevenolen requested review from Lytol and timtalbot March 5, 2026 20:04
@stevenolen stevenolen marked this pull request as ready for review March 5, 2026 20:05
@stevenolen stevenolen requested a review from a team as a code owner March 5, 2026 20:05
Lytol
Lytol previously approved these changes Mar 9, 2026
Copy link
Contributor

@Lytol Lytol left a comment

Choose a reason for hiding this comment

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

As you mentioned, there's probably some DRYing and refactoring that could make it cleaner for the next human... but definitely don't do any premature refactoring for theoretical future needs. And even the few ones that could be nice now, are probably actually irrelevant in an agentic world.

All that said, looks great to me!

Comment on lines -87 to -91
// the unicode word split algo also doesn't like "postgres_config", so just hack that in manually
titleCaseStackBaseName := helpers.TitleCase(stackBaseName)
if stackBaseName == "postgres_config" {
titleCaseStackBaseName = "PostgresConfig"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to drop that nonsense.

)
switch s.DstTarget.CloudProvider() {
case types.AWS:
return s.runAWSInlineGo(ctx, creds, envVars)
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, not important.


// --- Azure ---

// azurePostgresParams holds the pre-fetched data needed by the Azure deploy function.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's meh/whatever to me. Creating an options / value object to limit a giant function signature. A little easier to grok for the humans, inconsequential to the agents. 🤷

Comment on lines +144 to +161
// Fetch DB admin secret from Azure Key Vault
secretName := fmt.Sprintf("%s-grafana-postgres-admin-secret", s.DstTarget.Name())
secretValue, err := s.DstTarget.SecretStore().GetSecretValue(ctx, creds, secretName)
if err != nil {
return fmt.Errorf("failed to get postgres admin secret from Key Vault: %w", err)
}

var secretData map[string]string
if err := json.Unmarshal([]byte(secretValue), &secretData); err != nil {
return fmt.Errorf("failed to parse postgres admin secret JSON: %w", err)
}

dbHost := secretData["fqdn"]
dbUser := secretData["username"]
dbPassword := secretData["password"]
if dbHost == "" || dbUser == "" || dbPassword == "" {
return fmt.Errorf("grafana DB secret must contain 'fqdn', 'username' and 'password' fields")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably all benefit from some method extraction and encapsulation. But again, pretty nitpicky and probably inconsequential to the bots.

return runPulumi(ctx, stack, s.Options)
}

// --- Shared helpers ---
Copy link
Contributor

Choose a reason for hiding this comment

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

YAGNI. If it's not needed elsewhere yet, fine to leave in here and let the next person refactor when it needs to be used elsewhere.

componentType = "ptd:AWSControlRoomPostgresConfig"
}

// Helper to create alias pointing to old Python component parent URN.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above IMO: YAGNI, make it generic/reusable once there's another need for it.

@stevenolen
Copy link
Collaborator Author

finally got around to running this in an azure env, fix a small bug (that was introduced in a go lib long ago)

⏺ Looks great. The real resources are all recognized (no creates, no deletes):

  - Provider: version bump from 3.14.0 → 3.16.2 (harmless)
  - KeyVault Secret: provider update + secret value re-evaluated (expected)
  - 2 deletes: the Python AzureWorkloadPostgresConfig and GrafanaPostgresResources component wrappers — expected since Go doesn't create those

  The postgres resources (password, role, database, grant) are all unchanged — the aliases are working correctly. This matches the same pattern we saw with the AWS previews.

@Lytol quick re-approval given last commit?

@stevenolen stevenolen enabled auto-merge March 10, 2026 15:51
@stevenolen stevenolen added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 6a0bc3c Mar 10, 2026
6 checks passed
@stevenolen stevenolen deleted the convert-step-postgres-config branch March 10, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants