Skip to content

Commit 071789e

Browse files
jlegroneCopilot
andauthored
[Breaking change] Update TEMPORAL_ injected env vars to match those expected by SDKs (#130)
## 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_PORT` → `TEMPORAL_ADDRESS` - `TEMPORAL_TLS_KEY_PATH` → `TEMPORAL_TLS_CLIENT_KEY_PATH` - `TEMPORAL_TLS_CERT_PATH` → `TEMPORAL_TLS_CLIENT_CERT_PATH` - `WORKER_BUILD_ID` → `TEMPORAL_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 - [x] Updated existing tests to use new environment variable names - [x] 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. --------- Co-authored-by: Copilot <[email protected]>
1 parent 15aa23b commit 071789e

File tree

15 files changed

+733
-133
lines changed

15 files changed

+733
-133
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ significant references to Kubernetes Deployment resource, within this repository
5151
In order to be compatible with this controller, workers need to be configured using these standard environment
5252
variables:
5353

54-
- `TEMPORAL_HOST_PORT`: The host and port of the Temporal server, e.g. `default.foo.tmprl.cloud:7233`
54+
- `TEMPORAL_ADDRESS`: The host and port of the Temporal server, e.g. `default.foo.tmprl.cloud:7233`
5555
- `TEMPORAL_NAMESPACE`: The Temporal namespace to connect to, e.g. `default`
5656
- `TEMPORAL_DEPLOYMENT_NAME`: The name of the worker deployment. This must be unique to the worker deployment and should not
5757
change between versions.
58-
- `WORKER_BUILD_ID`: The build ID of the worker. This should change with each new worker rollout.
58+
- `TEMPORAL_WORKER_BUILD_ID`: The build ID of the worker. This should change with each new worker rollout.
5959

6060
Each of these will be automatically set by the controller, and must not be manually specified in the worker's pod template.
6161

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ require (
1515
github.com/stretchr/testify v1.10.0
1616
go.temporal.io/api v1.50.1
1717
go.temporal.io/sdk v1.35.0
18+
go.temporal.io/sdk/contrib/envconfig v0.1.0
19+
go.temporal.io/server v1.28.1
1820
k8s.io/api v0.33.2
1921
k8s.io/apimachinery v0.33.2
2022
k8s.io/client-go v0.33.2
@@ -32,6 +34,7 @@ require (
3234
cloud.google.com/go/storage v1.51.0 // indirect
3335
dario.cat/mergo v1.0.1 // indirect
3436
filippo.io/edwards25519 v1.1.0 // indirect
37+
github.com/BurntSushi/toml v1.4.0 // indirect
3538
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
3639
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0 // indirect
3740
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 // indirect
@@ -149,7 +152,6 @@ require (
149152
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
150153
go.opentelemetry.io/otel/trace v1.34.0 // indirect
151154
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
152-
go.temporal.io/server v1.28.1 // indirect
153155
go.temporal.io/version v0.3.0 // indirect
154156
go.uber.org/atomic v1.11.0 // indirect
155157
go.uber.org/dig v1.18.0 // indirect

go.sum

Lines changed: 48 additions & 2 deletions
Large diffs are not rendered by default.

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ toolchain go1.24.6
44

55
use (
66
.
7+
./internal/demo
78
./internal/tests
89
)

go.work.sum

Lines changed: 380 additions & 89 deletions
Large diffs are not rendered by default.

internal/demo/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ require (
88
go.temporal.io/api v1.44.1
99
go.temporal.io/sdk v1.33.0
1010
go.temporal.io/sdk/contrib/datadog v0.4.0
11+
go.temporal.io/sdk/contrib/envconfig v0.1.0
1112
go.temporal.io/sdk/contrib/tally v0.2.0
1213
)
1314

1415
require (
16+
github.com/BurntSushi/toml v1.4.0 // indirect
1517
github.com/DataDog/appsec-internal-go v1.9.0 // indirect
1618
github.com/DataDog/datadog-agent/pkg/obfuscate v0.58.0 // indirect
1719
github.com/DataDog/datadog-agent/pkg/proto v0.58.0 // indirect

internal/demo/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
33
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4+
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
5+
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
46
github.com/DataDog/appsec-internal-go v1.9.0 h1:cGOneFsg0JTRzWl5U2+og5dbtyW3N8XaYwc5nXe39Vw=
57
github.com/DataDog/appsec-internal-go v1.9.0/go.mod h1:wW0cRfWBo4C044jHGwYiyh5moQV2x0AhnwqMuiX7O/g=
68
github.com/DataDog/datadog-agent/pkg/obfuscate v0.58.0 h1:nOrRNCHyriM/EjptMrttFOQhRSmvfagESdpyknb5VPg=
@@ -356,6 +358,8 @@ go.temporal.io/sdk v1.33.0 h1:T91UzeRdlHTiMGgpygsItOH9+VSkg+M/mG85PqNjdog=
356358
go.temporal.io/sdk v1.33.0/go.mod h1:WwCmJZLy7zabz3ar5NRAQEygsdP8tgR9sDjISSHuWZw=
357359
go.temporal.io/sdk/contrib/datadog v0.4.0 h1:f5Z7zs9VDazvLRu6CmXC83KcdNMDclgvZPEm2DiyCgs=
358360
go.temporal.io/sdk/contrib/datadog v0.4.0/go.mod h1:iYSXJPlJA5b/9Jo4hmquD7IaAa3776fB4KThp6vHik4=
361+
go.temporal.io/sdk/contrib/envconfig v0.1.0 h1:s+G/Ujph+Xl2jzLiiIm2T1vuijDkUL4Kse49dgDVGBE=
362+
go.temporal.io/sdk/contrib/envconfig v0.1.0/go.mod h1:FQEO3C56h9C7M6sDgSanB8HnBTmopw9qgVx4F1S6pJk=
359363
go.temporal.io/sdk/contrib/tally v0.2.0 h1:XnTJIQcjOv+WuCJ1u8Ve2nq+s2H4i/fys34MnWDRrOo=
360364
go.temporal.io/sdk/contrib/tally v0.2.0/go.mod h1:1kpSuCms/tHeJQDPuuKkaBsMqfHnIIRnCtUYlPNXxuE=
361365
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=

internal/demo/util/client.go

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ package util
66

77
import (
88
"context"
9-
"crypto/tls"
109
"os"
1110

1211
"github.com/uber-go/tally/v4/prometheus"
1312
"go.temporal.io/api/workflowservice/v1"
1413
"go.temporal.io/sdk/client"
1514
"go.temporal.io/sdk/contrib/datadog/tracing"
15+
"go.temporal.io/sdk/contrib/envconfig"
1616
sdktally "go.temporal.io/sdk/contrib/tally"
1717
"go.temporal.io/sdk/interceptor"
1818
)
1919

2020
func NewClient(buildID string) (c client.Client, stopFunc func()) {
21-
return newClient(temporalHostPort, temporalNamespace, buildID, tlsKeyFilePath, tlsCertFilePath)
21+
return newClient(buildID)
2222
}
2323

24-
func newClient(hostPort, namespace, buildID, tlsKeyFile, tlsCertFile string) (c client.Client, stopFunc func()) {
24+
func newClient(buildID string) (c client.Client, stopFunc func()) {
2525
l, stopFunc := configureObservability(buildID)
2626

2727
promScope, err := newPrometheusScope(l, prometheus.Configuration{
@@ -33,29 +33,22 @@ func newClient(hostPort, namespace, buildID, tlsKeyFile, tlsCertFile string) (c
3333
panic(err)
3434
}
3535

36-
cert, err := tls.LoadX509KeyPair(tlsCertFile, tlsKeyFile)
36+
// Load client options from environment variables using envconfig
37+
opts, err := envconfig.LoadDefaultClientOptions()
3738
if err != nil {
3839
panic(err)
3940
}
4041

41-
opts := client.Options{
42-
Identity: os.Getenv("HOSTNAME"),
43-
HostPort: hostPort,
44-
Namespace: namespace,
45-
Logger: l,
46-
Interceptors: []interceptor.ClientInterceptor{
47-
tracing.NewTracingInterceptor(tracing.TracerOptions{
48-
DisableSignalTracing: false,
49-
DisableQueryTracing: false,
50-
}),
51-
},
52-
MetricsHandler: sdktally.NewMetricsHandler(promScope),
53-
ConnectionOptions: client.ConnectionOptions{
54-
TLS: &tls.Config{
55-
Certificates: []tls.Certificate{cert},
56-
},
57-
},
42+
// Override with our custom settings
43+
opts.Identity = os.Getenv("HOSTNAME")
44+
opts.Logger = l
45+
opts.Interceptors = []interceptor.ClientInterceptor{
46+
tracing.NewTracingInterceptor(tracing.TracerOptions{
47+
DisableSignalTracing: false,
48+
DisableQueryTracing: false,
49+
}),
5850
}
51+
opts.MetricsHandler = sdktally.NewMetricsHandler(promScope)
5952

6053
l.Debug("Client configured", "identity", opts.Identity, "hostPort", opts.HostPort, "namespace", opts.Namespace)
6154

@@ -69,7 +62,7 @@ func newClient(hostPort, namespace, buildID, tlsKeyFile, tlsCertFile string) (c
6962
}
7063

7164
if _, err := c.ListWorkflow(context.Background(), &workflowservice.ListWorkflowExecutionsRequest{
72-
Namespace: namespace,
65+
Namespace: opts.Namespace,
7366
}); err != nil {
7467
panic(err)
7568
}

internal/demo/util/env.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ import (
1010
)
1111

1212
var (
13-
temporalHostPort = mustGetEnv("TEMPORAL_HOST_PORT")
14-
temporalNamespace = mustGetEnv("TEMPORAL_NAMESPACE")
13+
// temporalTaskQueue is still needed for worker creation as it's not part of client config
1514
temporalTaskQueue = mustGetEnv("TEMPORAL_TASK_QUEUE")
16-
tlsKeyFilePath = mustGetEnv("TEMPORAL_TLS_KEY_PATH")
17-
tlsCertFilePath = mustGetEnv("TEMPORAL_TLS_CERT_PATH")
1815
)
1916

2017
func mustGetEnv(key string) string {

internal/demo/util/worker.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ func NewVersionedWorker(opts worker.Options) (w worker.Worker, stopFunc func())
3232
}()
3333

3434
opts.DeploymentOptions = worker.DeploymentOptions{
35-
UseVersioning: true,
36-
Version: mustGetEnv("TEMPORAL_DEPLOYMENT_NAME") + VersionIDSeparator + mustGetEnv("WORKER_BUILD_ID"),
35+
UseVersioning: true,
36+
Version: worker.WorkerDeploymentVersion{
37+
DeploymentName: mustGetEnv("TEMPORAL_DEPLOYMENT_NAME"),
38+
BuildId: mustGetEnv("TEMPORAL_WORKER_BUILD_ID"),
39+
},
3740
DefaultVersioningBehavior: workflow.VersioningBehaviorPinned,
3841
}
3942

40-
c, stopClient := NewClient(mustGetEnv("WORKER_BUILD_ID"))
43+
c, stopClient := NewClient(mustGetEnv("TEMPORAL_WORKER_BUILD_ID"))
4144

4245
w = worker.New(c, temporalTaskQueue, opts)
4346

0 commit comments

Comments
 (0)