@@ -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+ }
0 commit comments