Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jlegrone
Copy link
Collaborator

@jlegrone jlegrone commented Aug 26, 2025

Summary

This PR updates the environment variables injected by the worker controller to match the standard names expected by Temporal SDKs, improving compatibility and reducing configuration complexity for users.

Fixes #128

Key Changes

Environment Variable Updates:

  • TEMPORAL_HOST_PORTTEMPORAL_ADDRESS
  • TEMPORAL_TLS_KEY_PATHTEMPORAL_TLS_CLIENT_KEY_PATH
  • TEMPORAL_TLS_CERT_PATHTEMPORAL_TLS_CLIENT_CERT_PATH
  • WORKER_BUILD_IDTEMPORAL_WORKER_BUILD_ID
  • Added TEMPORAL_TLS=true when mTLS is enabled

Example code changes:

  • Updated demo code to use go.temporal.io/sdk/contrib/envconfig for configuration parsing

Test Plan

  • Updated existing tests to use new environment variable names
  • Added unit test for environment variable compatibility with go.temporal.io/sdk/contrib/envconfig

Migration Notes

This is a BREAKING CHANGE which updates the environment variables that the controller injects into worker deployments. Existing workers will need to read in the new environment variable names when they are next updated by the controller.

This change updates the environment variables injected by the worker controller
to match the standard names expected by Temporal SDKs:

- TEMPORAL_HOST_PORT → TEMPORAL_ADDRESS
- TEMPORAL_TLS_KEY_PATH → TEMPORAL_TLS_CLIENT_KEY_PATH
- TEMPORAL_TLS_CERT_PATH → TEMPORAL_TLS_CLIENT_CERT_PATH
- Added TEMPORAL_TLS=true when mTLS is enabled

Also updates all tests, documentation, and demo code to use the new
environment variable names.

Fixes #128
@jlegrone jlegrone requested a review from a team as a code owner August 26, 2025 18:59
Prefix the build ID environment variable with TEMPORAL_ to match
the naming convention of other Temporal SDK environment variables.
- Add unit test that verifies environment variables injected by the
  controller are compatible with go.temporal.io/sdk/contrib/envconfig
- Update demo client code to use envconfig.LoadDefaultClientOptions()
  instead of manually constructing client options
- Add go.temporal.io/sdk/contrib/envconfig dependency

This ensures that the environment variables we inject follow the
standard patterns expected by the Temporal SDK ecosystem.
- Update worker.go to use TEMPORAL_WORKER_BUILD_ID instead of WORKER_BUILD_ID
- Simplify env.go to only contain temporalTaskQueue and mustGetEnv function
- Remove unused environment variables that are now handled by envconfig:
  temporalHostPort, temporalNamespace, tlsKeyFilePath, tlsCertFilePath

The client configuration is now handled by envconfig.LoadDefaultClientOptions(),
so we only need the task queue name for worker creation.
- Rename TestNewDeploymentWithOwnerRef_EnvironmentVariables to
  TestNewDeploymentWithOwnerRef_EnvironmentVariablesAndVolumes to better
  reflect that it tests both env vars and volume mounts
- Add exhaustive coverage for all environment variables injected by
  the controller in TestNewDeploymentWithOwnerRef_EnvConfigSDKCompatibility
- Add verification that TLS is not configured for non-mTLS connections

Addresses:
- #130 (comment)
- #130 (comment)
The previous implementation incorrectly checked that environment variables
were set, but the review comment asked to verify that the parsed client
options from envconfig contain the expected values.

Now properly tests:
- HostPort is parsed from TEMPORAL_ADDRESS
- Namespace is parsed from TEMPORAL_NAMESPACE
- Other client option fields have expected default values
- Worker-specific env vars (TEMPORAL_DEPLOYMENT_NAME, TEMPORAL_WORKER_BUILD_ID)
  are available for worker versioning

Addresses: #130 (comment)
Changed test HostPort from localhost:7233 to test.temporal.example:9999
to ensure we're testing actual environment variable parsing rather than
potentially getting default values from the envconfig package.

This makes the test more reliable for detecting configuration issues.
Restructured TestNewDeploymentWithOwnerRef_EnvConfigSDKCompatibility
to include both TLS and non-TLS test cases:

- Non-TLS case: Fully tests envconfig parsing and client options
- TLS case: Verifies TLS environment variables are set correctly
  (skips actual client loading due to certificate validation complexity)

This provides comprehensive coverage of both connection types while
avoiding the complexity of creating valid test certificates.

Addresses: #130 (comment)
This dependency is required by internal/demo/util/client.go for SDK
configuration parsing. The CI was failing because this dependency was
not explicitly listed in go.mod.
@jlegrone jlegrone marked this pull request as draft August 26, 2025 20:35
The demo module has its own go.mod file and also needs the
go.temporal.io/sdk/contrib/envconfig dependency for CI builds
to succeed when controller-gen scans all code paths.
- Include actual values in error messages for better debugging
- Generate self-signed certificates for TLS envconfig testing
- Enable full TLS test coverage with valid certificate files

Addresses:
- #130 (comment)
- #130 (comment)
- Remove expectedAddress and expectTLS fields from test cases
- Infer expected values directly from connection spec
- Simplifies test structure and reduces duplication

Addresses:
- #130 (comment)
- #130 (comment)
- Use pem.Encode() with os.Create() to write directly to files
- Replace pem.EncodeToMemory() + os.WriteFile() pattern
- Use t.TempDir() for proper test file cleanup
- Reduces memory allocation and improves performance
- Add proper file handle cleanup with defer statements

Addresses: #130 (comment)
- Add namespace string field to EnvConfigSDKCompatibility test cases
- Use different namespaces for TLS vs non-TLS test scenarios
- Replace hardcoded "test-namespace" references with tt.namespace
- Improves test clarity and prevents namespace collision

Addresses: #130 (comment)
- Remove assertions for certificate paths that were just set by t.Setenv()
- Keep only the meaningful assertion for TEMPORAL_TLS set by deployment
- Eliminates superfluous test code that doesn't add validation value

Addresses: #130 (comment)
@jlegrone jlegrone requested a review from Copilot August 26, 2025 22:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the environment variables injected by the worker controller to match the standard names expected by Temporal SDKs, improving compatibility and reducing configuration complexity.

  • Rename environment variables to SDK-standard names (e.g., TEMPORAL_HOST_PORTTEMPORAL_ADDRESS)
  • Add TEMPORAL_TLS=true environment variable when mTLS is enabled
  • Modernize demo code to use go.temporal.io/sdk/contrib/envconfig for configuration parsing

Reviewed Changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/k8s/deployments.go Updates environment variable names in deployment creation and adds TEMPORAL_TLS flag
internal/k8s/deployments_test.go Adds comprehensive tests for environment variable injection and SDK compatibility
internal/demo/util/client.go Modernizes client creation to use envconfig package instead of manual environment parsing
internal/demo/util/env.go Removes manual environment variable handling, keeping only task queue variable
internal/demo/util/worker.go Updates references to use new TEMPORAL_WORKER_BUILD_ID variable name
internal/testhelpers/workers.go Updates test helper to use new environment variable names
internal/planner/planner.go Updates deployment connection spec update logic for new variable names
internal/planner/planner_test.go Updates tests to verify new TEMPORAL_ADDRESS variable
README.md Updates documentation to reflect new environment variable names
go.mod Adds envconfig dependency for SDK compatibility testing
internal/demo/go.mod Adds envconfig dependency for demo modernization

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jlegrone jlegrone marked this pull request as ready for review August 26, 2025 22:40
@jlegrone jlegrone changed the title Update TEMPORAL_ injected env vars to match those expected by SDKs [Breaking change] Update TEMPORAL_ injected env vars to match those expected by SDKs Aug 26, 2025
- Reorganize imports to follow Go conventions (separate stdlib/external/internal)
- Consolidate TLS and non-TLS test logic into unified flow
- Add certificate path validation against expected volume mount paths
- Fix slice modification to properly override certificate paths with temp files
- Improve test structure by validating deployment env vars before overriding
- Remove redundant code duplication between TLS and non-TLS branches
Add missing os.Create() calls for certFile and keyFile variables
that were being referenced but not declared after the git rebase.

Fixes CI failure: https://github.com/temporalio/temporal-worker-controller/actions/runs/17252197679/job/48956754842
@carlydf
Copy link
Collaborator

carlydf commented Aug 26, 2025

you can run make fmt-imports to fix the imports linter

Replace defer statements with t.Cleanup for file closure to follow
Go testing best practices. t.Cleanup is preferred in test functions
as it ensures cleanup runs even if the test panics or exits early.
Copy link
Collaborator

@carlydf carlydf left a comment

Choose a reason for hiding this comment

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

thanks this is great! (approved pending my comment about SDK string vs object)

…tion

Replace string concatenation for the Version field with the proper
worker.WorkerDeploymentVersion struct that has separate DeploymentName
and BuildId fields. This follows the Temporal SDK's expected API.

Addresses: #130 (comment)
The go.work.sum file needed to be updated after adding the demo module
to the workspace to track checksums for the new dependency graph.

Fixes CI failure: https://github.com/temporalio/temporal-worker-controller/actions/runs/17252545293/job/48957836099?pr=130
@jlegrone jlegrone merged commit 071789e into main Aug 26, 2025
11 checks passed
@jlegrone jlegrone deleted the jlegrone/update-temporal-env-vars branch August 26, 2025 23:23
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.

Update TEMPORAL_ injected env vars to match those expected by SDKs

3 participants