You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(postgres): add create/update mutations and reuse live personal access - #535
Adds API-backed create/update for Postgres, following the Valkey pattern, and makes personal access idempotent.
Postgres create/update
createPostgres / updatePostgres mutations, authorized by new postgres:create and postgres:update permissions (members and owners). Developers get no direct write access to the CRDs.
Only major version 18 is accepted. Omitted cpu/memory/diskSize are left out so CRD defaults apply. Names must be DNS-1123 subdomains; quantities must be > 0.
POSTGRES_CREATED / POSTGRES_UPDATED activity log entries; updates log updatedFields (field, old and new value).
Personal access (PostgresAccess)
Deterministic name per (user, branch), so concurrent requests are serialized by the API server. A live access with the same level is reused, a different level is rejected, and an expired one is deleted and the caller asked to retry. This needs delete on postgresaccesses in RBAC.
PostgresAccess.connection returns null (no error) until the access is READY.
Tests
New postgres_crud suite; create_postgres_access covers reuse, conflicts and expired cleanup.
The write verbs are added only to the tenant ClusterRole. The on-prem ClusterRole still grants postgres only get, list, and watch (lines 302–308), while these mutations use the system-authenticated client with no environment-kind guard. Consequently, create/update requests against an on-prem environment will pass API authorization but fail with Kubernetes Forbidden; mirror create and update in the on-prem rule.
Omitted resource fields serialize as zero values instead of CRD defaults
internal/persistence/postgres/write.go:175
Omitting resource fields does not leave them to the CRD defaults. PostgresResources and its resource.Quantity fields are value structs, and DefaultUnstructuredConverter does not treat structs as empty for omitempty, so this emits cpu, memory, and diskSize as "0". The CRD therefore cannot apply its 100m/512Mi/10Gi defaults; toPostgres masks these zero values as null, so the integration assertion does not catch the malformed resource. Remove keys for omitted inputs before calling Create.
Reuse live legacy accesses before creating deterministic resources
internal/persistence/postgres/queries.go:504
Before this change, personal accesses used random postgres-access-<8 hex> names. A still-live access with that name will not conflict with the new deterministic name, so a repeat request after rollout creates another access for the same user and branch. Under the single-role constraint described above, the second access cannot become ready. Before creating the deterministic resource, look up accesses by spec.username and spec.postgresBranch; reuse a live match with the same access level and reject a different level. Return the existing object's name and expiry, and grant list on postgresaccesses in both RBAC branches. Cover a live legacy-named access in an integration test.
Re. Copilot's "Reuse live legacy accesses before creating deterministic resources": not planned. The personal access flow is unreleased, so the only random-named postgres-access-<8hex> objects are test objects from relay testing in nav-dev. Their TTL is at most 1 hour, so they have already expired. Looking them up would need list on postgresaccesses in both RBAC roles plus a separate reuse path, for something that goes away on its own.
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
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.
Adds API-backed create/update for Postgres, following the Valkey pattern, and makes personal access idempotent.
Postgres create/update
createPostgres/updatePostgresmutations, authorized by newpostgres:createandpostgres:updatepermissions (members and owners). Developers get no direct write access to the CRDs.POSTGRES_CREATED/POSTGRES_UPDATEDactivity log entries; updates logupdatedFields(field, old and new value).Personal access (PostgresAccess)
deleteonpostgresaccessesin RBAC.PostgresAccess.connectionreturns null (no error) until the access is READY.Tests
New
postgres_crudsuite;create_postgres_accesscovers reuse, conflicts and expired cleanup.