Skip to content

chore: insert some more env vars#5402

Merged
Flo4604 merged 2 commits intomainfrom
03-20-chore_insert_some_interesting_env_vars
Mar 24, 2026
Merged

chore: insert some more env vars#5402
Flo4604 merged 2 commits intomainfrom
03-20-chore_insert_some_interesting_env_vars

Conversation

@Flo4604
Copy link
Copy Markdown
Member

@Flo4604 Flo4604 commented Mar 20, 2026

What does this PR do?

As a user it would be nice to have some more info at runtime.

So we are adding some more runtime environment variables to deployment workloads by extending the ApplyDeployment protobuf message with additional metadata fields. These fields include app slug, project slug, environment slug, region, and Git-related information (commit SHA, branch, repository, and commit message). The changes also add a UNKEY_REPLICA_ID environment variable that references the pod's metadata name.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Deploy a workload and verify that the new environment variables (UNKEY_APP_SLUG, UNKEY_PROJECT_SLUG, UNKEY_ENVIRONMENT_SLUG, UNKEY_REGION, UNKEY_GIT_COMMIT_SHA, UNKEY_GIT_BRANCH, UNKEY_GIT_REPO, UNKEY_GIT_COMMIT_MESSAGE, UNKEY_REPLICA_ID) are properly set in the running containers
  • Test with deployments that have Git information and verify the Git-related environment variables are populated correctly
  • Test with deployments that don't have Git information and verify the optional fields are handled gracefully
  • Verify that existing functionality remains unaffected

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Ran make fmt on /go directory
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment Mar 24, 2026 9:40am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

Extended DB queries, generated query structs, gRPC ApplyDeployment message, control-plane RPCs, and Krane apply logic to carry environment slug, region, and Git metadata (commit SHA, branch, commit message, and repository) through query results, RPC payloads, and container environment variables.

Changes

Cohort / File(s) Summary
Generated DB query structs
pkg/db/deployment_topology_by_id_and_region.sql_generated.go, pkg/db/deployment_topology_list_by_versions.sql_generated.go, pkg/db/querier_generated.go
Added fields for git_commit_sha, git_branch, git_commit_message, environment_slug, region_name, and git_repo to result-row types and expanded Scan/select mappings to populate them.
SQL query definitions
pkg/db/queries/deployment_topology_by_id_and_region.sql, pkg/db/queries/deployment_topology_list_by_versions.sql
SELECT lists extended to include d.git_commit_sha, d.git_branch, d.git_commit_message, e.slug AS environment_slug, r.name AS region_name (where applicable), and grc.repository_full_name AS git_repo; added INNER JOIN environments e and LEFT JOIN github_repo_connections grc.
gRPC proto
svc/ctrl/proto/ctrl/v1/cluster.proto
Added optional string fields to ctrl.v1.ApplyDeployment: environment_slug, region, git_commit_sha, git_branch, git_repo, and git_commit_message.
Control-plane RPCs
svc/ctrl/services/cluster/rpc_get_desired_deployment_state.go, svc/ctrl/services/cluster/rpc_watch_deployments.go
Populate new ApplyDeployment fields: set EnvironmentSlug and Region from DB values; conditionally set Git fields when corresponding DB Valid flags are true.
Krane apply / Pod env injection
svc/krane/internal/deployment/apply.go
Replaced prior workspace/project/env ID env vars with UNKEY_ENVIRONMENT_SLUG, UNKEY_REGION, added UNKEY_GIT_COMMIT_SHA, UNKEY_GIT_BRANCH, UNKEY_GIT_REPO, UNKEY_GIT_COMMIT_MESSAGE, and added UNKEY_INSTANCE_ID populated from Pod metadata.name.

Sequence Diagram(s)

/* Visualizes how deployment metadata flows from DB through control plane to Krane and into pod envs */

sequenceDiagram
    participant Client
    participant ControlPlane as "Control Plane\n(svc/ctrl)"
    participant DB as "Database"
    participant Krane as "Krane\n(svc/krane)"
    participant Pod

    Client->>ControlPlane: Request desired deployment state
    ControlPlane->>DB: Query deployment topology (includes env slug, region, git metadata)
    DB-->>ControlPlane: Row with environment_slug, region_name, git_commit_sha/branch/message, git_repo
    ControlPlane-->>Krane: Build ctrl.v1.ApplyDeployment (include env/region/git fields)
    Krane->>Pod: Create/Update PodSpec with env vars (UNKEY_ENVIRONMENT_SLUG, UNKEY_REGION, UNKEY_GIT_*)
    Pod-->>Krane: Pod metadata.name available -> UNKEY_INSTANCE_ID populated
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title 'chore: insert some more env vars' is vague and generic, using non-descriptive language that doesn't convey the specific or meaningful changes made. Make the title more specific and descriptive, such as 'chore: add deployment metadata environment variables' to clearly communicate what env vars are being added and why.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The PR description includes all required template sections: a clear explanation of what is being added (environment variables for runtime metadata), the type of change marked as 'Enhancement', comprehensive testing instructions, and a checklist with required items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 03-20-chore_insert_some_interesting_env_vars

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Member Author

Flo4604 commented Mar 20, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@svc/krane/internal/deployment/apply.go`:
- Around line 95-103: The env-var injection list in apply.go is missing
UNKEY_APP_SLUG and UNKEY_PROJECT_SLUG and incorrectly sets UNKEY_INSTANCE_ID
instead of UNKEY_REPLICA_ID; update the EnvVar slice where these are defined
(look for the block with Name: "UNKEY_ENVIRONMENT_SLUG", "UNKEY_REGION", etc.)
to add entries for UNKEY_APP_SLUG and UNKEY_PROJECT_SLUG with their values from
the request, and change the existing EnvVar with Name "UNKEY_INSTANCE_ID" to
Name "UNKEY_REPLICA_ID" while keeping the same ValueFrom FieldRef metadata.name
selector.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c67bf5f1-67f9-4bc7-904d-0c8b15bff4b5

📥 Commits

Reviewing files that changed from the base of the PR and between f15d596 and 38b649a.

⛔ Files ignored due to path filters (2)
  • gen/proto/ctrl/v1/cluster.pb.go is excluded by !**/*.pb.go, !**/gen/**
  • web/apps/dashboard/gen/proto/ctrl/v1/cluster_pb.ts is excluded by !**/gen/**
📒 Files selected for processing (9)
  • pkg/db/deployment_topology_by_id_and_region.sql_generated.go
  • pkg/db/deployment_topology_list_by_versions.sql_generated.go
  • pkg/db/querier_generated.go
  • pkg/db/queries/deployment_topology_by_id_and_region.sql
  • pkg/db/queries/deployment_topology_list_by_versions.sql
  • svc/ctrl/proto/ctrl/v1/cluster.proto
  • svc/ctrl/services/cluster/rpc_get_desired_deployment_state.go
  • svc/ctrl/services/cluster/rpc_watch_deployments.go
  • svc/krane/internal/deployment/apply.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • svc/ctrl/proto/ctrl/v1/cluster.proto
  • pkg/db/queries/deployment_topology_by_id_and_region.sql
  • pkg/db/queries/deployment_topology_list_by_versions.sql
  • svc/ctrl/services/cluster/rpc_get_desired_deployment_state.go
  • svc/ctrl/services/cluster/rpc_watch_deployments.go

Comment thread svc/krane/internal/deployment/apply.go
@Flo4604 Flo4604 force-pushed the 03-20-chore_insert_some_interesting_env_vars branch from 38b649a to 9b02f68 Compare March 24, 2026 09:38
@Flo4604 Flo4604 added this pull request to the merge queue Mar 24, 2026
@Flo4604 Flo4604 changed the title chore: insert some interesting env vars c Mar 24, 2026
@Flo4604 Flo4604 removed this pull request from the merge queue due to a manual request Mar 24, 2026
@Flo4604 Flo4604 added this pull request to the merge queue Mar 24, 2026
@Flo4604 Flo4604 changed the title c chore: insert some more env vars Mar 24, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 24, 2026
@Flo4604 Flo4604 added this pull request to the merge queue Mar 24, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 24, 2026
@Flo4604 Flo4604 added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit 7064daa Mar 24, 2026
14 checks passed
@Flo4604 Flo4604 deleted the 03-20-chore_insert_some_interesting_env_vars branch March 24, 2026 11:19
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.

3 participants