Skip to content

Commit 0a20e6e

Browse files
committed
Update TEMPORAL_ injected env vars to match those expected by SDKs
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
1 parent 15aa23b commit 0a20e6e

File tree

7 files changed

+112
-12
lines changed

7 files changed

+112
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ 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.

internal/demo/util/env.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
)
1111

1212
var (
13-
temporalHostPort = mustGetEnv("TEMPORAL_HOST_PORT")
13+
temporalHostPort = mustGetEnv("TEMPORAL_ADDRESS")
1414
temporalNamespace = mustGetEnv("TEMPORAL_NAMESPACE")
1515
temporalTaskQueue = mustGetEnv("TEMPORAL_TASK_QUEUE")
16-
tlsKeyFilePath = mustGetEnv("TEMPORAL_TLS_KEY_PATH")
17-
tlsCertFilePath = mustGetEnv("TEMPORAL_TLS_CERT_PATH")
16+
tlsKeyFilePath = mustGetEnv("TEMPORAL_TLS_CLIENT_KEY_PATH")
17+
tlsCertFilePath = mustGetEnv("TEMPORAL_TLS_CLIENT_CERT_PATH")
1818
)
1919

2020
func mustGetEnv(key string) string {

internal/k8s/deployments.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func NewDeploymentWithOwnerRef(
200200
for i, container := range podSpec.Containers {
201201
container.Env = append(container.Env,
202202
corev1.EnvVar{
203-
Name: "TEMPORAL_HOST_PORT",
203+
Name: "TEMPORAL_ADDRESS",
204204
Value: connection.HostPort,
205205
},
206206
corev1.EnvVar{
@@ -224,11 +224,15 @@ func NewDeploymentWithOwnerRef(
224224
for i, container := range podSpec.Containers {
225225
container.Env = append(container.Env,
226226
corev1.EnvVar{
227-
Name: "TEMPORAL_TLS_KEY_PATH",
227+
Name: "TEMPORAL_TLS",
228+
Value: "true",
229+
},
230+
corev1.EnvVar{
231+
Name: "TEMPORAL_TLS_CLIENT_KEY_PATH",
228232
Value: "/etc/temporal/tls/tls.key",
229233
},
230234
corev1.EnvVar{
231-
Name: "TEMPORAL_TLS_CERT_PATH",
235+
Name: "TEMPORAL_TLS_CLIENT_CERT_PATH",
232236
Value: "/etc/temporal/tls/tls.crt",
233237
},
234238
)

internal/k8s/deployments_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,99 @@ func TestComputeConnectionSpecHash(t *testing.T) {
557557
assert.NotEmpty(t, hash1, "Hash should still be generated even with empty mTLS secret")
558558
})
559559
}
560+
561+
func TestNewDeploymentWithOwnerRef_EnvironmentVariables(t *testing.T) {
562+
tests := map[string]struct {
563+
connection temporaliov1alpha1.TemporalConnectionSpec
564+
expectedEnvVars map[string]string
565+
unexpectedEnvVars []string
566+
}{
567+
"without mTLS": {
568+
connection: temporaliov1alpha1.TemporalConnectionSpec{
569+
HostPort: "localhost:7233",
570+
},
571+
expectedEnvVars: map[string]string{
572+
"TEMPORAL_ADDRESS": "localhost:7233",
573+
"TEMPORAL_NAMESPACE": "test-namespace",
574+
"TEMPORAL_DEPLOYMENT_NAME": "test-deployment",
575+
"WORKER_BUILD_ID": "test-build-id",
576+
},
577+
unexpectedEnvVars: []string{"TEMPORAL_TLS", "TEMPORAL_TLS_CLIENT_KEY_PATH", "TEMPORAL_TLS_CLIENT_CERT_PATH"},
578+
},
579+
"with mTLS": {
580+
connection: temporaliov1alpha1.TemporalConnectionSpec{
581+
HostPort: "mtls.localhost:7233",
582+
MutualTLSSecret: "my-tls-secret",
583+
},
584+
expectedEnvVars: map[string]string{
585+
"TEMPORAL_ADDRESS": "mtls.localhost:7233",
586+
"TEMPORAL_NAMESPACE": "test-namespace",
587+
"TEMPORAL_DEPLOYMENT_NAME": "test-deployment",
588+
"WORKER_BUILD_ID": "test-build-id",
589+
"TEMPORAL_TLS": "true",
590+
"TEMPORAL_TLS_CLIENT_KEY_PATH": "/etc/temporal/tls/tls.key",
591+
"TEMPORAL_TLS_CLIENT_CERT_PATH": "/etc/temporal/tls/tls.crt",
592+
},
593+
unexpectedEnvVars: []string{},
594+
},
595+
}
596+
597+
for name, tt := range tests {
598+
t.Run(name, func(t *testing.T) {
599+
spec := &temporaliov1alpha1.TemporalWorkerDeploymentSpec{
600+
Template: corev1.PodTemplateSpec{
601+
Spec: corev1.PodSpec{
602+
Containers: []corev1.Container{
603+
{
604+
Name: "worker",
605+
Image: "temporal/worker:latest",
606+
},
607+
},
608+
},
609+
},
610+
WorkerOptions: temporaliov1alpha1.WorkerOptions{
611+
TemporalNamespace: "test-namespace",
612+
},
613+
}
614+
615+
deployment := k8s.NewDeploymentWithOwnerRef(
616+
&metav1.TypeMeta{},
617+
&metav1.ObjectMeta{Name: "test", Namespace: "default"},
618+
spec,
619+
"test-deployment",
620+
"test-build-id",
621+
tt.connection,
622+
)
623+
624+
// Verify expected environment variables are present
625+
container := deployment.Spec.Template.Spec.Containers[0]
626+
envMap := make(map[string]string)
627+
for _, env := range container.Env {
628+
envMap[env.Name] = env.Value
629+
}
630+
631+
for expectedKey, expectedValue := range tt.expectedEnvVars {
632+
actualValue, exists := envMap[expectedKey]
633+
assert.True(t, exists, "Environment variable %s should be present", expectedKey)
634+
assert.Equal(t, expectedValue, actualValue, "Environment variable %s should have correct value", expectedKey)
635+
}
636+
637+
// Verify unexpected environment variables are not present
638+
for _, unexpectedKey := range tt.unexpectedEnvVars {
639+
_, exists := envMap[unexpectedKey]
640+
assert.False(t, exists, "Environment variable %s should not be present", unexpectedKey)
641+
}
642+
643+
// For mTLS case, verify volume mounts and volumes are configured
644+
if tt.connection.MutualTLSSecret != "" {
645+
assert.Len(t, container.VolumeMounts, 1)
646+
assert.Equal(t, "temporal-tls", container.VolumeMounts[0].Name)
647+
assert.Equal(t, "/etc/temporal/tls", container.VolumeMounts[0].MountPath)
648+
649+
assert.Len(t, deployment.Spec.Template.Spec.Volumes, 1)
650+
assert.Equal(t, "temporal-tls", deployment.Spec.Template.Spec.Volumes[0].Name)
651+
assert.Equal(t, tt.connection.MutualTLSSecret, deployment.Spec.Template.Spec.Volumes[0].VolumeSource.Secret.SecretName)
652+
}
653+
})
654+
}
655+
}

internal/planner/planner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func updateDeploymentWithConnection(deployment *appsv1.Deployment, connection te
133133
// Update any environment variables that reference the connection
134134
for i, container := range deployment.Spec.Template.Spec.Containers {
135135
for j, env := range container.Env {
136-
if env.Name == "TEMPORAL_HOST_PORT" {
136+
if env.Name == "TEMPORAL_ADDRESS" {
137137
deployment.Spec.Template.Spec.Containers[i].Env[j].Value = connection.HostPort
138138
}
139139
}

internal/planner/planner_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,14 +2015,14 @@ func TestCheckAndUpdateDeploymentConnectionSpec(t *testing.T) {
20152015
found := false
20162016
for _, container := range result.Spec.Template.Spec.Containers {
20172017
for _, env := range container.Env {
2018-
if env.Name == "TEMPORAL_HOST_PORT" {
2019-
assert.Equal(t, tt.expectHostPortEnv, env.Value, "TEMPORAL_HOST_PORT should be updated")
2018+
if env.Name == "TEMPORAL_ADDRESS" {
2019+
assert.Equal(t, tt.expectHostPortEnv, env.Value, "TEMPORAL_ADDRESS should be updated")
20202020
found = true
20212021
break
20222022
}
20232023
}
20242024
}
2025-
assert.True(t, found, "Should find TEMPORAL_HOST_PORT environment variable")
2025+
assert.True(t, found, "Should find TEMPORAL_ADDRESS environment variable")
20262026
})
20272027
}
20282028
}

internal/testhelpers/workers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func newVersionedWorker(ctx context.Context, podTemplateSpec corev1.PodTemplateS
4141
if err != nil {
4242
return nil, nil, err
4343
}
44-
temporalHostPort, err := getEnv(podTemplateSpec, "TEMPORAL_HOST_PORT")
44+
temporalHostPort, err := getEnv(podTemplateSpec, "TEMPORAL_ADDRESS")
4545
if err != nil {
4646
return nil, nil, err
4747
}

0 commit comments

Comments
 (0)