@@ -92,7 +92,7 @@ func TestJobEndpointConnect_groupConnectHook(t *testing.T) {
92
92
tgExp .Services [0 ].Name = "backend"
93
93
tgExp .Services [1 ].Name = "admin"
94
94
95
- // Expect sidecar tasks to be properly canonicalized
95
+ // Expect sidecar tasks to be in canonical form.
96
96
tgExp .Tasks [0 ].Canonicalize (job , tgExp )
97
97
tgExp .Tasks [1 ].Canonicalize (job , tgExp )
98
98
tgExp .Networks [0 ].DynamicPorts = []structs.Port {{
@@ -146,6 +146,75 @@ func TestJobEndpointConnect_groupConnectHook_IngressGateway(t *testing.T) {
146
146
require .Exactly (t , expTG , job .TaskGroups [0 ])
147
147
}
148
148
149
+ func TestJobEndpointConnect_groupConnectHook_IngressGateway_CustomTask (t * testing.T ) {
150
+ t .Parallel ()
151
+
152
+ // Test that the connect gateway task is inserted if a gateway service exists
153
+ // and since this is a bridge network, will rewrite the default gateway proxy
154
+ // block with correct configuration.
155
+ job := mock .ConnectIngressGatewayJob ("bridge" , false )
156
+
157
+ job .Meta = map [string ]string {
158
+ "gateway_name" : "my-gateway" ,
159
+ }
160
+
161
+ job .TaskGroups [0 ].Services [0 ].Name = "${NOMAD_META_gateway_name}"
162
+ job .TaskGroups [0 ].Services [0 ].Connect .SidecarTask = & structs.SidecarTask {
163
+ Driver : "raw_exec" ,
164
+ User : "sidecars" ,
165
+ Config : map [string ]interface {}{
166
+ "command" : "/bin/sidecar" ,
167
+ "args" : []string {"a" , "b" },
168
+ },
169
+ Resources : & structs.Resources {
170
+ CPU : 400 ,
171
+ // Memory: inherit 128
172
+ },
173
+ KillSignal : "SIGHUP" ,
174
+ }
175
+
176
+ expTG := job .TaskGroups [0 ].Copy ()
177
+ expTG .Tasks = []* structs.Task {
178
+ // inject merged gateway task
179
+ {
180
+ Name : "connect-ingress-my-gateway" ,
181
+ Kind : structs .NewTaskKind (structs .ConnectIngressPrefix , "my-gateway" ),
182
+ Driver : "raw_exec" ,
183
+ User : "sidecars" ,
184
+ Config : map [string ]interface {}{
185
+ "command" : "/bin/sidecar" ,
186
+ "args" : []string {"a" , "b" },
187
+ },
188
+ Resources : & structs.Resources {
189
+ CPU : 400 ,
190
+ MemoryMB : 128 ,
191
+ },
192
+ LogConfig : & structs.LogConfig {
193
+ MaxFiles : 2 ,
194
+ MaxFileSizeMB : 2 ,
195
+ },
196
+ ShutdownDelay : 5 * time .Second ,
197
+ KillSignal : "SIGHUP" ,
198
+ Constraints : structs.Constraints {
199
+ connectGatewayVersionConstraint (),
200
+ },
201
+ },
202
+ }
203
+ expTG .Services [0 ].Name = "my-gateway"
204
+ expTG .Tasks [0 ].Canonicalize (job , expTG )
205
+ expTG .Networks [0 ].Canonicalize ()
206
+
207
+ // rewrite the service gateway proxy configuration
208
+ expTG .Services [0 ].Connect .Gateway .Proxy = gatewayProxyForBridge (expTG .Services [0 ].Connect .Gateway )
209
+
210
+ require .NoError (t , groupConnectHook (job , job .TaskGroups [0 ]))
211
+ require .Exactly (t , expTG , job .TaskGroups [0 ])
212
+
213
+ // Test that the hook is idempotent
214
+ require .NoError (t , groupConnectHook (job , job .TaskGroups [0 ]))
215
+ require .Exactly (t , expTG , job .TaskGroups [0 ])
216
+ }
217
+
149
218
// TestJobEndpoint_ConnectInterpolation asserts that when a Connect sidecar
150
219
// proxy task is being created for a group service with an interpolated name,
151
220
// the service name is interpolated *before the task is created.
@@ -330,7 +399,7 @@ func TestJobEndpointConnect_gatewayProxyIsDefault(t *testing.T) {
330
399
t .Run ("bind-addresses set" , func (t * testing.T ) {
331
400
result := gatewayProxyIsDefault (& structs.ConsulGatewayProxy {
332
401
EnvoyGatewayBindAddresses : map [string ]* structs.ConsulGatewayBindAddress {
333
- "listener1" : & structs. ConsulGatewayBindAddress {
402
+ "listener1" : {
334
403
Address : "1.1.1.1" ,
335
404
Port : 9000 ,
336
405
},
@@ -362,7 +431,7 @@ func TestJobEndpointConnect_gatewayBindAddresses(t *testing.T) {
362
431
}},
363
432
})
364
433
require .Equal (t , map [string ]* structs.ConsulGatewayBindAddress {
365
- "service1" : & structs. ConsulGatewayBindAddress {
434
+ "service1" : {
366
435
Address : "0.0.0.0" ,
367
436
Port : 3000 ,
368
437
},
@@ -388,15 +457,15 @@ func TestJobEndpointConnect_gatewayBindAddresses(t *testing.T) {
388
457
}},
389
458
})
390
459
require .Equal (t , map [string ]* structs.ConsulGatewayBindAddress {
391
- "service1" : & structs. ConsulGatewayBindAddress {
460
+ "service1" : {
392
461
Address : "0.0.0.0" ,
393
462
Port : 3000 ,
394
463
},
395
- "service2" : & structs. ConsulGatewayBindAddress {
464
+ "service2" : {
396
465
Address : "0.0.0.0" ,
397
466
Port : 3000 ,
398
467
},
399
- "service3" : & structs. ConsulGatewayBindAddress {
468
+ "service3" : {
400
469
Address : "0.0.0.0" ,
401
470
Port : 3001 ,
402
471
},
0 commit comments